Пример #1
0
        /// <summary>
        /// Method to get all orders from a specific store
        /// </summary>
        /// <param name="l">The location object to get orders from</param>
        public IEnumerable <BusinessLibrary.Order> GetOrdersByLocation(BusinessLibrary.StoreLocation l)
        {
            List <BusinessLibrary.Order> ordersList = new List <BusinessLibrary.Order>();

            IQueryable <Entity.Entities.Order> orders = _dbContext.Orders.Where(x => x.StoreId == l.StoreLocationId);

            foreach (var o in orders)
            {
                Customer c = GetCustomerById(o.UserId);
                BusinessLibrary.Order order = new BusinessLibrary.Order(o.Id, c, o.OrderTime, GetStoreById(o.StoreId + 1), o.OrderTotal);
                ordersList.Add(order);
            }

            return(ordersList);
        }
Пример #2
0
        /// <summary>
        /// Method to get all the store locations
        /// </summary>
        public IEnumerable <BusinessLibrary.StoreLocation> GetStoreLocations()
        {
            int id = 0;
            List <BusinessLibrary.StoreLocation> locationList = new List <BusinessLibrary.StoreLocation>();

            IQueryable <Entity.Entities.StoreLocation> locations = _dbContext.StoreLocations;

            foreach (var l in locations)
            {
                BusinessLibrary.StoreLocation sl = new BusinessLibrary.StoreLocation(id, l.Name);
                locationList.Add(sl);
                id++;
            }

            return(locationList);
        }
Пример #3
0
        /// <summary>
        /// Method to get a store object by its id
        /// </summary>
        /// <param name="storeId">The id of the store to get the object from db</param>
        public BusinessLibrary.StoreLocation GetStoreById(int storeId)
        {
            BusinessLibrary.StoreLocation store = null;

            IQueryable <Entity.Entities.StoreLocation> locations = _dbContext3.StoreLocations;

            foreach (var l in locations)
            {
                if (l.Id == storeId)
                {
                    store = new BusinessLibrary.StoreLocation(storeId, l.Name);
                }
            }

            return(store);
        }
Пример #4
0
        /// <summary>
        /// Method to get a stores product inventory
        /// </summary>
        /// <param name="l">The stores location object</param>
        public IEnumerable <BusinessLibrary.Product> GetStoreInventory(BusinessLibrary.StoreLocation l)
        {
            //return list to hold all the products
            List <BusinessLibrary.Product> products = new List <BusinessLibrary.Product>();

            //get products from invetory of selected location
            IQueryable <Entity.Entities.StoreInventory> inventory = _dbContext.StoreInventories.Include(x => x.Product)
                                                                    .Where(x => x.LocationId == l.StoreLocationId + 1);

            //add each product to list
            foreach (var item in inventory)
            {
                BusinessLibrary.Product p = new BusinessLibrary.Product(item.ProductId, item.Product.Name, (double)item.Product.Price, item.ProductQty);
                products.Add(p);
            }

            return(products);
        }
Пример #5
0
        /// <summary>
        /// Method to update the stores inventory tables products qtys
        /// </summary>
        /// <param name="l">The storelocation object</param>
        /// <param name="prodList">a list of all the products being purchases</param>
        public void UpdateProductInventory(BusinessLibrary.StoreLocation l, List <BusinessLibrary.Product> prodList)
        {
            //get the product
            IQueryable <Entity.Entities.StoreInventory> inv = _dbContext.StoreInventories.Where(x => x.LocationId == l.StoreLocationId + 1);

            //update db
            foreach (var i in inv)
            {
                foreach (var p in prodList)
                {
                    if (i.ProductId == p.ProductId)
                    {
                        i.ProductQty -= p.ProductQty;
                    }
                }
            }

            //save changes
            _dbContext.SaveChanges();
        }