title: How to insert data into multiple tables using a POST request on Postman?
body: <p>I have 3 tables that need to be populated; OrderHistory, OrderHistoryItem and OrderHistoryLabel. These three tables are connected to each other through the following keys:</p>
  
  <pre><code>UserID - references AspNetUsers(Id)
  OrderID in OrderHistoryItem - references OrderHistory(OrderID)
  </code></pre>
  
  <p>This <a href="https://i.stack.imgur.com/mSv4O.png" rel="nofollow noreferrer">picture</a> will provide more information about the table but I included only what I deem important at this stage.</p>
  
  <p>The following code is written in visual studio and represents the method used to create the order by adding all needed values in their tables.</p>
  
  <pre><code>    [Route("v1/orderhistory")]
      [HttpPost()]
      public IActionResult CreateOrder([FromBody]OrderHistoryDto ohdata, [FromBody]OrderHistoryItemDto itemdata, [FromBody]HistoryLabelDto labeldata)
      {
          try
          {
              if (ohdata == null) throw new ArgumentException("No data specified");
              if (itemdata == null) throw new ArgumentException("No data specified");
              if (labeldata == null) throw new ArgumentException("No data specified");
              //string orderId = "40281804-FE51-4893-AEA8-944903C27771";
              var orderID = Guid.NewGuid();
  
              using (var con = _connFactory())
              {
                  con.Open();
                  con.Execute("INSERT INTO dbo.OrderHistoryItemLabel (LabelID, OrderProductID) VALUES (@labelID, @orderProductID)", new
                  {
                      labeldata.orderProductID,
                      labeldata.labelID
                  });
  
                  con.Execute(@"INSERT INTO dbo.OrderHistoryItem (ProductID, OrderID, ProductGroup, NormalPrice, Price, StandardUnit, PricePerStandardAmount, Quantity, Discount, IsDiscounted, TotalPrice) 
                              VALUES (@productID, @orderID, @productGroup, @normalPrice, @price, @standardUnit, @pricePerStandardAmount, @quantity, @discount, @isDiscounted, @totalPrice)", new
                  {
                      itemdata.productID,
                      itemdata.orderID,
                      itemdata.productGroup,
                      itemdata.normalPrice,
                      itemdata.price,
                      itemdata.standardUnit,
                      itemdata.pricePerStandardAmount,
                      itemdata.quantity,
                      itemdata.discount,
                      itemdata.isDiscounted,
                      itemdata.itemTotalPrice,
                      labeldata.orderProductID
                  });
                  con.Execute("INSERT INTO dbo.OrderHistory (UserID, TransferredAtUtc, OrderTotalPrice, StoreID) VALUES (@userID, @transferredAtUtc, @orderTotalPrice, @storeID)", new
                  {
                      ohdata.userID,
                      ohdata.transferredAtUtc,
                      ohdata.orderTotalPrice,
                      ohdata.storeID
                  });
              }
              return Ok(orderID);
          }
          catch (Exception exc)
          {
              return BadRequest();
          }
      }
  }
  </code></pre>
  
  <p>As a testing tool, I am using Postman, and the POST request written in JSON is the following:</p>
  
  <pre><code>{
      "TransferredAtUtc": "",
      "OrderTotalPrice": 344343.43,
      "StoreId": 1,
      "Items": [
          {
              "LabelID": [
                  1,
                  2,
                  3,
                  4,
                  5
              ],
              "ProductID": 1,
              "ProductGroup": "asd",
              "NormalPrice": 2,
              "Price": 2,
              "StandardUnit": "asd",
              "PricePerStandardAmount": 2,
              "Quantity": 1,
              "Discount": 0,
              "IsDiscounted": 0,
              "ItemTotalPrice": 2
          },
          {
              "LabelID": [
                  1,
                  2,
                  5
              ],
              "ProductID": 434,
              "ProductGroup": "asd",
              "NormalPrice": 2,
              "Price": 22,
              "StandardUnit": "asd",
              "PricePerStandardAmount": 2,
              "Quantity": 1,
              "Discount": 0,
              "IsDiscounted": 0,
              "ItemTotalPrice": 2
          }
      ]
  }
  </code></pre>
  
  <p>]</p>
  
  <p>I have little to no knowledge of how I am supposed to write the code in JSON so I am kindly asking for your advice, as every time I am sending a request, the <code>if()</code> clauses at the beginning of the method throw me out. The problem seems to be that the values are not being populated so my guess is that the JSON code that I wrote is not properly written. Any tips?</p>