ここ

2017-09-18 8 views
0

が私のクラスである子オブジェクトNULL MVCのAPIを受け取ることができません:私は、それはOrderDetailsNULLを示す以下のコードでは、いくつかのデータを受信して​​いたときにここ

public class OrderMaster 
    { 
     public string DisplayorderId { get; set; } 
     public string ExtOrderId { get; set; } 
     public string ExtInfo { get; set; } 
     public int OrderStatusId { get; set; } 
     public bool IsDeliveryPickup { get; set; } 
     public string BranchCode { get; set; } 
     public DateTime DeliveryPickupDate { get; set; } 
     public decimal Price { get; set; } 
     public decimal ServiceCharge { get; set; } 
     public decimal ServiceChargePerc { get; set; } 
     public decimal CGST { get; set; } 
     public decimal SGST { get; set; } 
     public decimal IGST { get; set; } 
     public decimal DeliveryCharge { get; set; } 
     public decimal Discount { get; set; } 
     public decimal GiftWrapPrice { get; set; } 
     public string OfferCouponcode { get; set; } 
     public decimal OfferCouponDiscount { get; set; } 
     public string GiftCouponCode { get; set; } 
     public decimal GiftCouponPrice { get; set; } 
     public int WalletPrice { get; set; } 
     public string ShippingFullname { get; set; } 
     public string ShippingEmail { get; set; } 
     public string ShippingContactNo { get; set; } 
     public string ShippingAddress { get; set; } 
     public string ShippingCity { get; set; } 
     public string ShippingPincode { get; set; } 
     public string ShippingState { get; set; } 
     public string UserComment { get; set; } 
     public string CancelRemarks { get; set; } 
     public DateTime CancelDate { get; set; } 
     public DateTime OrderShippingDate { get; set; } 
     public DateTime OrderCompleteDate { get; set; } 
     public string CourierName { get; set; } 
     public string TrackingNo { get; set; } 
     public string PaymentGateway { get; set; } 
     public string PaymentType { get; set; } 
     public int PaymentStatus { get; set; } 
     public DateTime Createddate { get; set; } 
     public int TrnType { get; set; } 
     public int TrnCtrlNo { get; set; } 
     public List<GetOrderDtls> OrderDetails { get; set; } 
       } 

    public class GetOrderDtls 
    { 
     public int TrnCtrlNo { get; set; } 
     public int TrnType { get; set; } 
     public string ExtOrderId { get; set; }   
     public string Barcode { get; set; } 
     public string Product { get; set; } 
     public string Category { get; set; } 
     public string Brand { get; set; } 
     public int OrderQuantity { get; set; } 
     public decimal Price { get; set; } 
     public decimal CGST { get; set; } 
     public decimal SGST { get; set; } 
     public decimal IGST { get; set; } 
     public string OfferCode { get; set; } 
     public decimal OfferDiscount { get; set; } 
     public string IsGiftPack { get; set; }  
     public decimal ReturnQuantity { get; set; } 
     public decimal ReturnPrice { get; set; } 
     public string ReturnReason { get; set; } 
     public decimal DocEntDisc { get; set; } 
     public decimal DiscRate { get; set; } 
    } 

しかし:

FIRST API(POST)オブジェクトリスト:

 [System.Web.Http.HttpPost] 
     [ResponseType(typeof(OrderMaster))] 
     [System.Web.Http.Route("api/Order/OrderSave")] 
     public IHttpActionResult OrderIntegartion(List<OrderMaster> order) 
     { 
      /*var token = System.Web.HttpContext.Current.Request.Headers["Token"]; 
      string webToken = WebConfigurationManager.AppSettings["token"]; 
      */ 
      //if (token == webToken) 
      //{ 

      string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(order); 
     } 

データは以下のように、ここから来る: 第2のAPI(GET):以下のように

 [HttpGet] 
     [ResponseType(typeof(List<Order>))] 
     [System.Web.Http.Route("api/Order/GetOrders")] 
     public async Task<IHttpActionResult> GetOrderData() 
     { 
      //List<Order> OrderList = new List<Order>(); 

      //List<Orderdetail> OrderDList = new List<Orderdetail>(); 

      //var list = db.GetSalesOrderHdr().ToList(); 

      var list = db.GetSalesOrderHdr().ToList(); 
      var data = new List<Order>(); 

      foreach (var listdata in list) 
      { 
       var getorder = new Order() ; 

       //Order getorder = new Order() { Orderdetails = OrderDList }; 

       getorder.DisplayorderId = listdata.OrderId; 
       getorder.ExtOrderId = listdata.DocNo; 
       getorder.ExtInfo = ""; 
       getorder.OrderStatusId = listdata.Status; 
       getorder.BranchCode = listdata.VACompCode; 
       getorder.DeliveryPickupDate = listdata.DeliveryExptdDateTime; 
       getorder.Price = listdata.BTotDocValue; 
       getorder.ServiceCharge = 0; 
       getorder.ServiceChargePerc = 0; 
       getorder.CGST = Convert.ToDecimal(listdata.BTaxComp1); 
       getorder.SGST = Convert.ToDecimal(listdata.BTaxComp2); 
       getorder.IGST = Convert.ToDecimal(listdata.BTaxComp3); 
       getorder.DeliveryCharge = 0; 
       getorder.Discount = listdata.BTotDocDisc; 
       getorder.GiftWrapPrice = 0; 
       getorder.OfferCouponcode = ""; 
       getorder.OfferCouponDiscount = 0; 
       getorder.GiftCouponCode = ""; 
       getorder.GiftCouponPrice = 0; 
       getorder.WalletPrice = 0; 
       getorder.ShippingFullname = listdata.ShipToCustomerName; 
       getorder.ShippingEmail = listdata.ShipToEmail; 
       getorder.ShippingContactNo = listdata.PartyId; 
       getorder.ShippingAddress = listdata.ShipToFullAddr; 
       getorder.ShippingCity = listdata.ShipToCity; 
       getorder.ShippingPincode = ""; 
       getorder.ShippingState = listdata.ShipToState; 
       getorder.UserComment = listdata.BDocRemarks; 
       getorder.CancelRemarks = listdata.RDocRemarks; 
       getorder.CancelDate = listdata.RDocDt; 
       getorder.OrderShippingDate = listdata.DeliveredDateTime; 
       getorder.OrderCompleteDate = Convert.ToDateTime(listdata.DocDt); 
       getorder.CourierName = ""; 
       getorder.TrackingNo = ""; 
       getorder.PaymentGateway = listdata.BPayModeTypeDesc; 
       getorder.PaymentType = listdata.BPayModeCode; 
       getorder.PaymentStatus = 0; 
       getorder.Createddate = Convert.ToDateTime(listdata.DocDt);     
       getorder.TrnType = listdata.TrnType; 
       getorder.TrnCtrlNo = listdata.TrnCtrlNo; 

       getorder.OrderDetails = db.GetSalesOrderHdrDtls(listdata.TrnType, listdata.TrnCtrlNo).ToList(); 

       data.Add(getorder); 
      } 

      var Message = ""; 

      using (HttpClient client = new HttpClient()) 
      { 
       string stringData = JsonConvert.SerializeObject(data); 

       string UrlApi = ConfigurationManager.AppSettings["UrlApi"]; 
       client.BaseAddress = new Uri(UrlApi); 
       MediaTypeWithQualityHeaderValue contentType = new MediaTypeWithQualityHeaderValue("application/json"); 
       client.DefaultRequestHeaders.Accept.Add(contentType); 
       var contentData = new StringContent(stringData, System.Text.Encoding.UTF8, "application/json"); 


       //HttpResponseMessage response = client.PostAsJsonAsync<List<Order>>("/api/Order/OrderSave", data).Result; 

       HttpResponseMessage response = client.PostAsync("/api/Order/OrderSave", contentData).Result; 

       Message = response.Content.ReadAsStringAsync().Result; 

       //Message = contentData.ToString(); 
      } 

      return Ok(data); 
     } 

クラス:上記の

public class Order 
    { 
     public string DisplayorderId { get; set; } 
     public string ExtOrderId { get; set; } 
     public string ExtInfo { get; set; } 
     public int OrderStatusId { get; set; } 
     public bool IsDeliveryPickup { get; set; } 
     public string BranchCode { get; set; } 
     public DateTime DeliveryPickupDate { get; set; } 
     public decimal Price { get; set; } 
     public decimal ServiceCharge { get; set; } 
     public decimal ServiceChargePerc { get; set; } 
     public decimal CGST { get; set; } 
     public decimal SGST { get; set; } 
     public decimal IGST { get; set; } 
     public decimal DeliveryCharge { get; set; } 
     public decimal Discount { get; set; } 
     public decimal GiftWrapPrice { get; set; } 
     public string OfferCouponcode { get; set; } 
     public decimal OfferCouponDiscount { get; set; } 
     public string GiftCouponCode { get; set; } 
     public decimal GiftCouponPrice { get; set; } 
     public int WalletPrice { get; set; } 
     public string ShippingFullname { get; set; } 
     public string ShippingEmail { get; set; } 
     public string ShippingContactNo { get; set; } 
     public string ShippingAddress { get; set; } 
     public string ShippingCity { get; set; } 
     public string ShippingPincode { get; set; } 
     public string ShippingState { get; set; } 
     public string UserComment { get; set; } 
     public string CancelRemarks { get; set; } 
     public DateTime CancelDate { get; set; } 
     public DateTime OrderShippingDate { get; set; } 
     public DateTime OrderCompleteDate { get; set; } 
     public string CourierName { get; set; } 
     public string TrackingNo { get; set; } 
     public string PaymentGateway { get; set; } 
     public string PaymentType { get; set; } 
     public int PaymentStatus { get; set; } 
     public DateTime Createddate { get; set; } 
     public int TrnType { get; set; } 
     public int TrnCtrlNo { get; set; } 

     public List<GetSalesOrderHdrDtls_Result> OrderDetails { get; set; } 
    } 

    public class Orderdetail 
    { 
     public int TrnType { get; set; } 
     public int TrnCtrlNo { get; set; } 
     public string ExtOrderId { get; set; } 
     public string Barcode { get; set; } 
     public float OrderQuantity { get; set; } 
     public decimal Price { get; set; } 
     public decimal CGST { get; set; } 
     public decimal SGST { get; set; } 
     public decimal IGST { get; set; } 
     public string OfferCode { get; set; } 
     public decimal OfferDiscount { get; set; } 
     public bool IsGiftPack { get; set; } 
     public float ReturnQuantity { get; set; } 
     public int ReturnPrice { get; set; } 
     public string ReturnReason { get; set; } 
     public string Product { get; set; } 
     public string Category { get; set; } 
     public string Brand { get; set; } 
     public decimal DocEntDisc { get; set; } 
     public decimal DiscRate { get; set; } 

    } 

概要:

私はここで私は上記のように、いくつかのデータが、子オブジェクトを渡す最初のAPIを呼び出すmは最初のAPIでNULL値を表示していますが、私は2番目のAPIでフォーマットごとに正しいデータを渡しています。まず、API(POST)から

電流出力:まずAPI(POST)から

[ 
    { 
    "DisplayorderId": "0", 
    "ExtOrderId": "S17/1", 
    "ExtInfo": "", 
    "OrderStatusId": 4, 
    "IsDeliveryPickup": false, 
    "BranchCode": "SC", 
    "DeliveryPickupDate": "1900-01-01T00:00:00", 
    "Price": 899.0000, 
    "ServiceCharge": 0.0, 
    "ServiceChargePerc": 0.0, 
    "CGST": 0.0000, 
    "SGST": 21.9300, 
    "IGST": 0.0000, 
    "DeliveryCharge": 0.0, 
    "Discount": 0.0000, 
    "GiftWrapPrice": 0.0, 
    "OfferCouponcode": "", 
    "OfferCouponDiscount": 0.0, 
    "GiftCouponCode": "", 
    "GiftCouponPrice": 0.0, 
    "WalletPrice": 0, 
    "ShippingFullname": "", 
    "ShippingEmail": "", 
    "ShippingContactNo": "1", 
    "ShippingAddress": "", 
    "ShippingCity": "", 
    "ShippingPincode": "", 
    "ShippingState": "", 
    "UserComment": "", 
    "CancelRemarks": "", 
    "CancelDate": "2017-08-01T00:00:00", 
    "OrderShippingDate": "1900-01-01T00:00:00", 
    "OrderCompleteDate": "2017-08-01T00:00:00", 
    "CourierName": "", 
    "TrackingNo": "", 
    "PaymentGateway": "Cash", 
    "PaymentType": "Rs", 
    "PaymentStatus": 0, 
    "Createddate": "2017-08-01T00:00:00", 
    "TrnType": 2100, 
    "TrnCtrlNo": 1, 
    "OrderDetails": [ 

    ] 
    } 
] 

必要な出力:

[ 
    { 
    "DisplayorderId": "0", 
    "ExtOrderId": "S17/1", 
    "ExtInfo": "", 
    "OrderStatusId": 4, 
    "IsDeliveryPickup": false, 
    "BranchCode": "SC", 
    "DeliveryPickupDate": "1900-01-01T00:00:00", 
    "Price": 899.0000, 
    "ServiceCharge": 0.0, 
    "ServiceChargePerc": 0.0, 
    "CGST": 0.0000, 
    "SGST": 21.9300, 
    "IGST": 0.0000, 
    "DeliveryCharge": 0.0, 
    "Discount": 0.0000, 
    "GiftWrapPrice": 0.0, 
    "OfferCouponcode": "", 
    "OfferCouponDiscount": 0.0, 
    "GiftCouponCode": "", 
    "GiftCouponPrice": 0.0, 
    "WalletPrice": 0, 
    "ShippingFullname": "", 
    "ShippingEmail": "", 
    "ShippingContactNo": "1", 
    "ShippingAddress": "", 
    "ShippingCity": "", 
    "ShippingPincode": "", 
    "ShippingState": "", 
    "UserComment": "", 
    "CancelRemarks": "", 
    "CancelDate": "2017-08-01T00:00:00", 
    "OrderShippingDate": "1900-01-01T00:00:00", 
    "OrderCompleteDate": "2017-08-01T00:00:00", 
    "CourierName": "", 
    "TrackingNo": "", 
    "PaymentGateway": "Cash", 
    "PaymentType": "Rs", 
    "PaymentStatus": 0, 
    "Createddate": "2017-08-01T00:00:00", 
    "TrnType": 2100, 
    "TrnCtrlNo": 1, 
    "OrderDetails": [ 
     { 
     "TrnType": 2100, 
     "TrnCtrlNo": 1, 
     "ExtOrderId": "S17/1", 
     "Barcode": "150101787", 
     "Brand": "KRISS", 
     "Category": "MENS SHIRTS", 
     "Product": "KRS STR F/S SHIRTS S", 
     "OrderQuantity": 1.0, 
     "Price": 899.0000, 
     "CGST": 0.0000, 
     "SGST": 21.9300, 
     "IGST": 0.0000, 
     "OfferCode": "", 
     "OfferDiscount": 0.0000, 
     "IsGiftPack": "False", 
     "ReturnQuantity": 1.0, 
     "ReturnPrice": 899.0000, 
     "ReturnReason": "Damage", 
     "DocEntDisc": 0.0000, 
     "DiscRate": 0.0000 
     } 
    ] 
    } 
] 

ので、上記のコードを調べて提案してください訂正。

+0

ここで、 'stringData'をどこに設定していますか?あなたの2番目のAPIアクションのコードはありません –

+0

あなたは 'List 'と 'List 'を2種類の入力として入力します。musmatch – Niladri

+0

@Yogeshはこのコードで任意の値を返します 'getorder.OrderDetails = db.GetSalesOrderHdrDtls(listdata.TrnType、 listdata.TrnCtrlNo).ToList(); 'OrderDetails – Niladri

答えて

0

最初のPOSTはList<OrderMaster>タイプの引数を受け入れますが、List<Order>を渡しています。戻り値の型はIHttpActionResultであるため、POSTメソッドからHttpResponseMessageを返す必要があることに注意してください。現在、コードにreturn文はありません。

あなたは以下のコード

[System.Web.Http.HttpPost] 
    [ResponseType(typeof(Order))] 
    [System.Web.Http.Route("api/Order/OrderSave")] 
    public IHttpActionResult OrderIntegartion(List<Order> contentData) 
    { 
     /*var token = System.Web.HttpContext.Current.Request.Headers["Token"]; 
     string webToken = WebConfigurationManager.AppSettings["token"]; 
     */ 
     //if (token == webToken) 
     //{ 

     string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(contentData); 
     return Ok<string> (jsonString); 
    } 

で試すことができます。またOrderMasterクラスは、タイプのList<GetOrderDtls>

public List<GetOrderDtls> OrderDetails { get; set; } 

である。しかしOrderクラスクラスは以下の型であるプロパティOrderDetailsを持つプロパティOrderDetailsを持っています

public List<GetSalesOrderHdrDtls_Result> OrderDetails { get; set; } 

したがってレスポンスで空の配列としてOrderDetailsプロパティを取得しています。