订单状态发布方法未调用Web API 2

时间:2019-04-27 13:02:28

标签: c# asp.net-web-api2

使用邮递员时,我的Post命令没有被点击。后comamnd用于更改交货的订单状态

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);



            }
        }

    }
}

如您所见,我正在使用表单参数中的值在邮递员中调用该方法,但是当我调试该方法内部的断点时,未击中我是在做错什么。

enter image description here

我在这里发布我的网络路线,以了解大多数要求。

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 }
        );
    }
}

1 个答案:

答案 0 :(得分:0)

您收到204,这是成功的,当您没有从POST方法返回任何响应时。这对我来说是打击。但是您说它没有找到方法,如果您想找到一个断点,可能是由于运行时和现有二进制文件之间的汇编问题。但总的来说,这对我来说似乎是打击:)