Exemplo 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);
            }
        }
Exemplo n.º 3
0
        internal static (List <Order>, List <List <OrderProducts> >, List <List <Product> >) GetOrdersInfoFromLocation(Location CurrentLocation)
        {
            List <Order> OrdersFromLocation   = new List <Order>();
            List <List <OrderProducts> > OPs  = new List <List <OrderProducts> >();
            List <List <Product> >       PIOs = new List <List <Product> >();

            using (var DB = new P0Context())
            {
                OrderDAO.LoadOrdersList(DB);
                OrdersFromLocation = DB.OrdersList.Where(o => o.LocationID == CurrentLocation.LocationID).ToList();
                OrderProductsDAO.LoadOrderProductsList(DB);
                foreach (Order order in OrdersFromLocation)
                {
                    List <OrderProducts> OrderProducts = DB.OrderProductsList.Where(o => o.OrderID == order.OrderID).ToList();
                    OPs.Add(OrderProducts);
                }
                ProductDAO.LoadProductsList(DB);
                foreach (List <OrderProducts> ops in OPs)
                {
                    List <Product> ProductsInOrder = new List <Product>();
                    foreach (OrderProducts op in ops)
                    {
                        Product p = DB.ProductsList.First(p => p.ProductID == op.ProductID);
                        ProductsInOrder.Add(p);
                    }
                    PIOs.Add(ProductsInOrder);
                }
            }
            return(OrdersFromLocation, OPs, PIOs);
        }
        internal static List <Order> GetPastOrdersFromCustomer(Customer customer, P1Context _context)
        {
            List <Order> OrdersByCustomer = new List <Order>();

            var DB = _context;

            OrderDAO.LoadOrdersList(DB);
            OrderProductsDAO.LoadOrderProductsList(DB);
            ProductDAO.LoadProductsList(DB);
            LocationDAO.LoadLocationsList(DB);
            BillingDAO.LoadBillingList(DB);
            CustomerDAO.LoadCustomersList(DB);
            ShippingDAO.LoadShippingInfomrationList(DB);

            OrdersByCustomer = DB.OrdersList.Where(o => o.CustomerID == customer.CustomerID).ToList();

            for (int i = 0; i < OrdersByCustomer.Count; i++)
            {
                Order o = OrdersByCustomer[i];

                List <ProductInStock> prodsOrdered = new List <ProductInStock>();

                List <OrderProducts> prodIDsAndQuantityInOrder = DB.OrderProductsList.Where(op => op.OrderID == OrdersByCustomer[i].OrderID).ToList();
                foreach (OrderProducts OP in prodIDsAndQuantityInOrder)
                {
                    ProductInStock prodOrdered = new ProductInStock();
                    Product        p           = DB.ProductsList.First(p => p.ProductID == OP.ProductID);
                    prodOrdered.Name        = p.Name;
                    prodOrdered.Price       = p.Price;
                    prodOrdered.Description = p.Description;
                    prodOrdered.Quantity    = OP.Quantity;
                    prodsOrdered.Add(prodOrdered);
                }

                o.ShoppingCart = prodsOrdered;

                o.Billing = DB.BillingInformationList.First(b => b.BillingID == OrdersByCustomer[i].BillingID);

                o.Shipping = DB.ShippingInformation.First(s => s.ShippingID == OrdersByCustomer[i].ShippingID);

                o.Location = DB.LocationList.First(l => l.LocationID == OrdersByCustomer[i].LocationID);

                o.Customer = DB.CustomersList.First(c => c.CustomerID == OrdersByCustomer[i].CustomerID);

                OrdersByCustomer[i] = o;
            }
            return(OrdersByCustomer);
        }