【发布时间】:2019-04-27 13:02:28
【问题描述】:
使用邮递员时,我的 Post 命令未命中。 post命令用于更改交货的订单状态
namespace DeliveryGo.Controllers
{
public class DeliveryController : ApiController
{
public IHttpActionResult Get()
{
string retJson;
string constring = ConfigurationManager.AppSettings["DeliveryGocs"].ToString();
string sql = "SELECT * FROM Deliverys AS A LEFT OUTER JOIN DeliveryLines AS B ON A.id = B.DeliveryId;";
using (var connection = new SqlConnection(constring))
{
var orderDictionary = new Dictionary<int, DeliverysItems>();
var list = connection.Query<DeliverysItems, DeliverItemLines, DeliverysItems>(
sql,
(order, orderDetail) =>
{
DeliverysItems orderEntry;
if (!orderDictionary.TryGetValue(order.id, out orderEntry))
{
orderEntry = order;
orderEntry.DeliveryLines = new List<DeliverItemLines>();
orderDictionary.Add(orderEntry.id, orderEntry);
}
orderEntry.DeliveryLines.Add(orderDetail);
return orderEntry;
})
.Distinct()
.ToList();
retJson = JsonConvert.SerializeObject(list);
if (list.Count > 0)
{
var response = this.Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StringContent(retJson, Encoding.UTF8, "application/json");
return ResponseMessage(response);
}else
{
var response = this.Request.CreateResponse(HttpStatusCode.NoContent);
response.Content = new StringContent(retJson, Encoding.UTF8, "application/json");
return ResponseMessage(response);
}
}
}
// POST api/values
public void Post([FromBody]string value)
{
}
[HttpPost]
public void ChangeOrderStatus(int enumValue, string SopOrderNumber)
{
//lets get the order status here
int orderStatus = (int)enumValue;
string connectionString = Constants.DeliveryGocs;
using (IDbConnection db = new SqlConnection(connectionString))
{
string sql = "UPDATE Deliverys SET OrderStatus = +"+enumValue+ " WHERE SopOrderNumber ='" +SopOrderNumber +"'";
db.Execute(sql);
}
}
}
}
如您所见,我在 postman 中使用表单参数中的值调用该方法,但是当我在该方法中调试断点时没有被命中,是不是我做错了什么。
我在这里发布我的网络路线,看看最有什么要求。
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
【问题讨论】:
-
希望有人停止对我投反对票,我提供了大量代码和证据!
标签: c# asp.net-web-api2