title: Post JSON Array in Asp.Net Web API
body: <p>Hi every one I am new to <code>ASP.Net Web API</code> and I want to Post <code>JSON</code> array data any get there response.</p>
  
  <p>My JSON POST Array format is</p>
  
  <pre><code>{
      "User_Id":"admi12n@1234","Key_Code":"3F-47-AB-84-9F-EB-D6-6B-9C-62-CC-85-98-4D-28-6B",
      "ProductDetails": [
          {"Product_Id":"ELT-7035","Price":"999","Quantity":"5"},
          {"Product_Id":"ELT-1254","Price":"1024","Quantity":"3"}
      ]
  }
  </code></pre>
  
  <p>And I want response as follows</p>
  
  <pre><code>{
      "User_Id":"admi12n@1234","Key_Code":"3F-47-AB-84-9F-EB-D6-6B-9C-62-CC-85-98-4D-28-6B",
      "OrderID":"Ord-021","Name":"Sabyasachi"
      "ProductDetails": [
          {"Product_Id":"ELT-7035","Price":"999","Quantity":"5"},
          {"Product_Id":"ELT-1254","Price":"1024","Quantity":"3"}
      ]
  }
  </code></pre>
  
  <p>I generate <code>OrderID</code> as Random and <code>Name</code> from posted <code>User_Id</code>. Here I want to post multiple product in one order.</p>
  
  <p>My Order class is as follows</p>
  
  <pre><code>public class Order
      {
          [Key]
          public long ID { get; set; }
          public string Order_Id { get; set; }
          public string Product_Id { get; set; }
          public long Quantity { get; set; }
          public long Amount { get; set; }
          public string User_Id { get; set; }
          public string Key_Code { get; set; }
          public DateTime Order_Date { get; set; }
          public DateTime Modified_Date { get; set; }
      }
  </code></pre>
  
  <p>And my Product class as follows</p>
  
  <pre><code>public class Product
      {
          [Key]
          public int Id { get; set; }
          public string Product_Code { get; set; }
          public string Product_Name { get; set; }
          public string Product_Category { get; set; }
          public string Product_Description { get; set; }
          public string Quantity { get; set; }
          public string Price { get; set; }
          public string Image { get; set; }
          public DateTime Created_Date { get; set; }
          public DateTime Modified_Date { get; set; }
      }
  </code></pre>
  
  <p>I am not able to ind the best way to post the order</p>
  
  <pre><code>public Order Add(Order odrerDetails) //This will not give array of data for products
  {
      using (var context = new EcommerceDBContext())
      {            
          odrerDetails.Order_Id = Helper.Random(7); //Generate random orderID from my class
          odrerDetails.Created_Date = DateTime.Now;
          odrerDetails.Modified_Date = DateTime.Now;
          //How to Save other details
          context.objOrderListing.Add(odrerDetails);
          context.SaveChanges();
          return odrerDetails;
      }
  }
  </code></pre>
  
  <p>In API controllers my code is as follows</p>
  
  <pre><code>public HttpResponseMessage PostOrder([FromBody] Order_Listing orderData)
  {
      orderData = repository.Add(orderData);
      var response = Request.CreateResponse&lt;Order_Listing&gt;(HttpStatusCode.Created, orderData);
      string uri = Url.Link("DefaultApi", new { customerID = orderData.ID });
      response.Headers.Location = new Uri(uri);
      return response;
  }
  </code></pre>
  
  <p>Please help me how to achieve this.</p>