internal static void PlaceOrder(List <ProductInStock> ShoppingCart, Billing BillingInfo, Shipping ShippingInfo, Customer CurrentCustomer, Location CurrentLocation, P1Context _context) { DateTime now = System.DateTime.Now; var DB = _context; Order Order = new Order { CustomerID = CurrentCustomer.CustomerID, LocationID = CurrentLocation.LocationID, BillingID = BillingInfo.BillingID, ShippingID = ShippingInfo.ShippingID, OrderTime = now.ToString() }; OrderDAO.AddOrders(Order, DB); LocationProductsDAO.LoadLocationProductsList(DB); foreach (ProductInStock p in ShoppingCart) { OrderProducts OP = new OrderProducts { OrderID = Order.OrderID, ProductID = p.ProductID, Quantity = p.Quantity }; OrderProductsDAO.AddOrderProducts(OP, DB); LocationProducts LP = DB.LocationProductsList.Single( x => (x.LocationID == CurrentLocation.LocationID && x.ProductID == p.ProductID)); LP.Inventory -= OP.Quantity; LocationProductsDAO.UpdateLocationProducts(LP, DB); } }
internal static void PlaceOrder(List <Product> ShoppingCart, Billing BillingInfo, Customer CurrentCustomer, Location CurrentLocation, List <int> Quantities) { DateTime now = System.DateTime.Now; using (var DB = new P0Context()) { Order Order = new Order { CustomerID = CurrentCustomer.CustomerID, LocationID = CurrentLocation.LocationID, OrderTime = now.ToString() }; OrderDAO.AddOrders(Order, DB); LocationProductsDAO.LoadLocationProductsList(DB); foreach (Product p in ShoppingCart) { int QuantityIndex = ShoppingCart.IndexOf(p); OrderProducts OP = new OrderProducts { OrderID = Order.OrderID, ProductID = p.ProductID, Quantity = Quantities[QuantityIndex] }; OrderProductsDAO.AddOrderProducts(OP, DB); LocationProducts LP = DB.LocationProductsList.Single( x => (x.LocationID == CurrentLocation.LocationID && x.ProductID == p.ProductID)); LP.Inventory -= OP.Quantity; LocationProductsDAO.UpdateLocationProducts(LP, DB); } } }
internal static void UpdateQuantity(Product p, int quanity, Location location, P1Context _context) { var DB = _context; LocationProductsDAO.LoadLocationProductsList(DB); foreach (LocationProducts lp in DB.LocationProductsList) { if (lp.LocationID == location.LocationID && lp.ProductID == p.ProductID) { lp.Inventory -= quanity; LocationProductsDAO.UpdateLocationProducts(lp, DB); break; } } }