如何解决如何将数据发布到.net core restApi中的多个表?
你好,我正在尝试将数据发布到.netcore rest api中的多个表中,但是我不知道如何开始。 我有3个席位,游乐设施和报价都与之相关。因此,我首先需要在表中填写地址lat和lng,然后将2个地方填写为出发地(目的地)。该表与FromePlaceId(FK),ToPlaceID(FK)和Kms一起使用,由Google Maps api计算得出。然后报价包含rideID(Fk)和计算出的价格。我知道如何使用多个控制器发布数据,一个用于地点,游乐设施和报价。但我想在一条路线上做到这一点。例如。 “ / api / calculatedquote /”。预先感谢。
解决方法
您可以使用所有“表”创建一个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
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。