public void DeleteOrderDetail(int detailID) { ElectronicsShopDBEntities1 dbEntities = new ElectronicsShopDBEntities1(); //var sql = "DELETE FROM OrderDetails Where OrderDetailID = {0}"; OrderDetails detailsToRemove = dbEntities.OrderDetails.Where(o => o.OrderDetailID == detailID).FirstOrDefault(); dbEntities.OrderDetails.Remove(detailsToRemove); dbEntities.SaveChanges(); //this has to be saved because the price of the details is computed in the database decimal newPrice = GetNewPrice(detailsToRemove.OrderID); dbEntities.OrderHistory.Where(o => o.OrderID == detailsToRemove.OrderID).FirstOrDefault().TotalPrice = newPrice; dbEntities.SaveChanges(); }
public OrderDetails AddOrderDetail(OrderDetails details) { ElectronicsShopDBEntities1 dbEntities = new ElectronicsShopDBEntities1(); details.UnitPrice = GetProductPrice(details.ProductID); dbEntities.OrderDetails.Add(details); dbEntities.SaveChanges(); //this has to be saved because the price of the details is computed in the database decimal newPrice = GetNewPrice(details.OrderID); dbEntities.OrderHistory.Where(x => x.OrderID == details.OrderID).FirstOrDefault().TotalPrice = newPrice; dbEntities.SaveChanges(); return(details); }
public void DeleteOrder(int OrderID) { ElectronicsShopDBEntities1 dbEntities = new ElectronicsShopDBEntities1(); OrderHistory orderToRemove = dbEntities.OrderHistory.Where(x => x.OrderID == OrderID).FirstOrDefault(); dbEntities.OrderDetails.RemoveRange(orderToRemove.OrderDetails.ToList()); dbEntities.OrderHistory.Remove(orderToRemove); dbEntities.SaveChanges(); }
public void ModifyOrder(OrderHistory modifiedOrder) { ElectronicsShopDBEntities1 dbEntities = new ElectronicsShopDBEntities1(); OrderHistory orderToModify = dbEntities.OrderHistory.Where(o => o.OrderID == modifiedOrder.OrderID).FirstOrDefault(); orderToModify.EmployeeID = modifiedOrder.EmployeeID; orderToModify.DeliveryAddress = modifiedOrder.DeliveryAddress; orderToModify.ReceiptNumber = modifiedOrder.ReceiptNumber; orderToModify.Status = modifiedOrder.Status; orderToModify.OrderDate = modifiedOrder.OrderDate; dbEntities.SaveChanges(); }
public void AddOrder(Users currentUser, OrderHistory order, OrderDetails details) { ElectronicsShopDBEntities1 dbEntities = new ElectronicsShopDBEntities1(); order.OrderDate = DateTime.Now; order.ReceiptNumber = GetRandomString(13); order.CustomerID = currentUser.UserID; order.CurrencyCode = "USD"; details.OrderID = order.OrderID; details.UnitPrice = GetProductPrice(details.ProductID); order.OrderDetails.Add(details); dbEntities.OrderHistory.Add(order); dbEntities.OrderDetails.Add(details); dbEntities.SaveChanges(); // Add total price after automatically calculating it in DB decimal newPrice = GetNewPrice(order.OrderID); order.TotalPrice = newPrice; //still tracked dbEntities.SaveChanges(); }