示例#1
0
        public async Task <List <Order> > GetListAllOrdersForStore(int storeID)
        {
            try
            {
                List <BusinessLogic.Objects.Order> BLListOrders = new List <Order>();

                foreach (Entities.Orders CTXOrder in _context.Orders.AsNoTracking().Where(o => o.StoreNumber == storeID).ToHashSet())
                {
                    BLListOrders.Add(ParseHandler.ContextOrderToLogicOrder(CTXOrder));
                }
                foreach (BusinessLogic.Objects.Order BLOrd in BLListOrders)
                {
                    BLOrd.StoreLocation = await GetStoreInformation(BLOrd.StoreLocation.storeNumber);
                }
                foreach (Order BLOrdToFill in BLListOrders)
                {
                    BLOrdToFill.CustomerProductList = await GetOrderProductListByID(BLOrdToFill.orderID);

                    BLOrdToFill.Customer = await GetCustomerByID(BLOrdToFill.Customer.customerID);
                }
                return(BLListOrders);
            }
            catch
            {
                throw new Exception("Failed to retrieve order information for store number: " + storeID);
            }
        }
示例#2
0
        public async Task AddPlacedOrderToCustomerAsync(int customerID, BusinessLogic.Objects.Order BLOrd)
        {
            try
            {
                _context.Orders.Add(ParseHandler.LogicOrderToContextOrder(BLOrd));
                _context.SaveChanges();
                Order BLNewOrder = ParseHandler.ContextOrderToLogicOrder(_context.Orders.OrderByDescending(s => s.OrderId).First(o => o.CustomerId == customerID));
                int   newOrderID = BLNewOrder.orderID;
                //BLNewOrder.storeLocation = await GetStoreInformation(BLNewOrder.storeLocation.storeNumber);

                foreach (BusinessLogic.Objects.Product BLProd in BLOrd.CustomerProductList)
                {
                    _context.OrderProduct.Add(ParseHandler.LogicProductToContextOrderProduct(newOrderID, BLProd));
                }
                //In the future, put the update inventory function before the savechanges for inventory validation purposes
                _context.SaveChanges();
                //await UpdateInventoryFromPlacedOrder(BLNewOrder);
            }
            catch
            {
                throw new Exception("Unable to commit the order to the database");
            }
        }