简体   繁体   English

如何将数据发布到.net core restApi 中的多个表?

[英]How to post data to multiple tables in .net core restApi?

Hello i'm trying to post data to multiple tables in .netcore rest api but I don't know how to get started.您好,我正在尝试将数据发布到 .netcore rest api 中的多个表,但我不知道如何开始。 I have 3 tables places, rides, and quotes they are all related.我有 3 个表的位置、游乐设施和报价,它们都是相关的。 So first I need to fill the table places with address lat and lng, 2 places to be filled one for departure one for destination.所以首先我需要用地址 lat 和 lng 填充表格位置,2 个位置填充一个用于出发地一个用于目的地。 The table rides with FromePlaceId(FK), ToPlaceID(FK) and Kms which is calculated by google maps api.该表带有 FromePlaceId(FK)、ToPlaceID(FK) 和 Kms,由谷歌地图 api 计算。 And then quotes which has rideID(Fk) and the calculated price.然后引用具有rideID(Fk) 和计算出的价格。 I know how to post data with multiple controllers one for places, for rides and quotes.我知道如何使用多个控制器发布数据,其中一个用于地点、乘车和报价。 But I wanted to do it on a single route.但我想在一条路线上做到这一点。 For eg.例如。 "/api/calculatedquote/". “/api/calculatedquote/”。 Thanks in advance.提前致谢。

You can create a class CalculatedquoteRequest with all your "Tables" and send it to your method "/api/calculatedquote/" as json.您可以使用所有“表”创建一个类CalculatedquoteRequest,并将其作为json发送到您的方法“/api/calculatedquote/”。 You don' t need to create one Controller for each "Table".您不需要为每个“表”创建一个控制器。 Example:例子:

Class Request:课程要求:

    public class CalculatedquoteRequest
{
    public Place Departure { get; set; }
    public Place Destination { get; set; }
    public Ride Ride { get; set; }
    public Quote Quotes { get; set; }
}

public class Place
{
    public string Lat { get; set; } 
    public string Lng { get; set; }
}
public class Ride
{
    //your properties of  Ride
}

public class Quote
{
    //your properties of  Quote
}

Your Controller:您的控制器:

    public class Calculatedquote : Controller
{
    [HttpPost]
    public async Task<ActionResult> Calculate([FromBody] CalculatedquoteRequest request)
    {
       //Here you put your code...
        
        return Ok(null);//You will return your response, not null
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将数据播种到 .NET Core 中的多个表? - How to seed data to multiple tables in .NET Core? 如何将数据插入.NET Core API中的多个相关表中? - How to insert data into multiple related tables in .NET Core API? RestAPI C# .net 核心将单个字符串传递给发布请求。 没有到达终点 - RestAPI C# .net core pass a single string to post request. not reaching endpoint 如何在 asp.net 核心 .NET6(Razor 页面)中的单个 cshtml 中显示来自多个表/模型的数据 - How to display data from multiple tables/models in a single cshtml in asp.net core .NET6 (Razor pages) 如何在 .NET 核心 3 中使用 LINQ 语法查询多个表 - How to query multiple tables using LINQ syntax in .NET core 3 将数据发布到控制器.net核心 - Post data to controller .net core 如何使用.NET Core中的Angular 4在同一提交中发布表单数据和文件 - How to post Form data and File in the same submit with Angular 4 in .NET Core 如何使用 post 将数据传递到另一个 .Net Core Web 应用程序 - How to pass data to another .Net Core web application using post .NET Core 2中多个表的IDENTITY_INSERT - IDENTITY_INSERT for multiple tables in .net core 2 .NET Core 6,多表一对多 - .NET Core 6, one to many table for multiple tables
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM