Hello Team, Please i want stock quantity to reduce by sales quantity, kindly help
public bool AddOrder(OrderViewModel objOrderViewModel) { tblOrder objOrder = new tblOrder(); objOrder.CustomerId = objOrderViewModel.CustomerId; objOrder.FinalTotal = objOrderViewModel.FinalTotal; objOrder.OrderDate = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"); objOrder.OrderNumber = string.Format("{0:ddmmmyyyyhhmmss }", DateTime.Now); objOrder.PaymentTypeId = objOrderViewModel.PaymentTypeId; objRestaurantDBEntities.tblOrders.Add(objOrder); objRestaurantDBEntities.SaveChanges(); int OderId = objOrder.OderId;
foreach (var item in objOrderViewModel.ListofOrderDetailViewModel) { tblOrderDetail objOrderDetails = new tblOrderDetail(); objOrderDetails.OderId = OderId; objOrderDetails.Discount = item.Discount; objOrderDetails.ItemId = item.ItemId; objOrderDetails.Total = item.Total; objOrderDetails.UnitPrice = item.UnitPrice; objOrderDetails.Quantity = item.Quantity; objRestaurantDBEntities.tblOrderDetails.Add(objOrderDetails); objRestaurantDBEntities.SaveChanges();
tblQuantity objtblQuantity = new tblQuantity(); objtblQuantity.ItemId = item.ItemId; objtblQuantity.Quantity = objtblQuantity.Quantity - NewQuantity; objRestaurantDBEntities.tblQuantity.Add(objtblQuantity ); objRestaurantDBEntities.SaveChanges(); } return true; }