See, in this case, first you need to add data to Tbl_Order table. Then you can add as many data to Tbl_OrderMenu table, by taking Order_ID from the first table. Hope you understood this.
Create a class which should include both the table. For example,
public class myCombinedClass
{
public int Order_ID {get;set;}
public int Employee_ID {get;set;}
public string TotalBill {get;set;}
public List<Tbl_OrderMenu> OrderMenu { get; set; }
}
In your API Controller method, you can write like this,
[HttpPost]
public HttpResponseMessage Post(myCombinedClass myData)
{
if(myData.id == 0)
{
// This is a new entry to Tbl_Order.
Tbl_Order orderObject = new Tbl_Order();
orderObject.Employee_ID = myData.Employee_ID;
orderObject.TotalBill = myData.TotalBill;
_ctx.Tbl_Order.Add(orderObject);
_ctx.SaveChanges();
}
else
{
//You just need to update the Tbl_Order. I mean, here you are adding
//data to Tbl_OrderMenu table with Order_ID.
var OrderMenuData = _ctx.Tbl_OrderMenu.where(m=>m.Order_ID ==
myData.id).FirstOrDefault();
OrderMenuData.Order_ID = myData.id;
OrderMenuData.MenuName = myData.OrderMenu.MenuName;
OrderMenuData.Quantity = myData.OrderMenu.Quantity;
_ctx.Entry(OrderMenuData).State=System.Data.Entity.EntityState.Modified;
_ctx.SaveChanges();
}
}
Note: See here, _ctx is the context class, that you need to add in this controller/method.
Ex: MyDBContext _ctx = new MyDBContext();
I have written an answer same like this here. Go through that. Check how I'm passing data to both the table in ajax method.