您好,我正在尝试在.netcore rest api中向多个表发布数据,但我不知道如何开始。我有3个表的地方,游乐设施和报价,他们都是相关的。因此,首先我需要在表格位置填入地址lat和lng,两个位置需要填充,一个是出发位置,一个是目的地位置。该表包含FromePlaceId(FK)、ToPlaceID(FK)和Kms (由谷歌地图api计算得出)。然后报价,其中有rideID(Fk)和计算出的价格。我知道如何在多个控制器上发布数据,一个用于位置,一个用于乘车和报价。但我只想在一条路线上做。例如。"/api/calculatedquote/“。提前谢谢。
发布于 2020-08-28 23:04:46
您可以创建一个包含所有“表”的类CalculatedquoteRequest,并将其作为json发送到您的方法"/api/calculatedquote/“。你不需要为每个“表”创建一个控制器。示例:
类请求:
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
}您的控制器:
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
}
}https://stackoverflow.com/questions/63636076
复制相似问题