Esempio n. 1
0
        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 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 RemoveLocationProducts(LocationProducts lp, P1Context DB)
 {
     DB.LocationProducts.Remove(lp);
     DB.SaveChanges();
 }
 internal static void UpdateLocationProducts(LocationProducts lp, P1Context DB)
 {
     DB.LocationProducts.Update(lp);
     DB.SaveChanges();
 }
 internal static void AddLocationProducts(LocationProducts lp, P1Context DB)
 {
     DB.LocationProducts.Add(lp);
     DB.SaveChanges();
     Thread.Sleep(500);
 }