Example #1
0
        public void AddInventory(string productName, int locationId, int quantity)
        {
            // get the location iventories with all the product details
            var dbLocation = _context.Locations
                             .Include(l => l.Inventories).ThenInclude(i => i.Product)
                             .FirstOrDefault(l => l.Id == locationId).Inventories.FirstOrDefault(i => i.Product.Name == productName);

            if (dbLocation == null)
            {
                // means the store doesn't have this item in its inventory
                var location = _context.Locations.First(l => l.Id == locationId);
                var product  = _context.Products.First(p => p.Name == productName);
                location.Inventories.Add(new Inventory()
                {
                    ProductId  = product.Id,
                    LocationId = locationId,
                    Quantity   = 0
                });
                _context.Update(location);
                _context.SaveChanges();
                dbLocation = _context.Locations
                             .Include(l => l.Inventories).ThenInclude(i => i.Product)
                             .FirstOrDefault(l => l.Id == locationId).Inventories.FirstOrDefault(i => i.Product.Name == productName);
            }
            dbLocation.Quantity += quantity;
            _context.Update(dbLocation);
            _context.SaveChanges();
        }
Example #2
0
        public void UpdateProduct(Library.Product product)
        {
            // get existing product
            var dbProduct = _context.Products.First(p => p.Name == product.Name);

            // update the entries except the name and id
            dbProduct.Description = product.Description;
            dbProduct.Price       = product.Price;
            dbProduct.OrderLimit  = product.OrderLimit;

            _context.Update(dbProduct);
            _context.SaveChanges();
        }
        public void UpdateProductInventory(BusinessLogic.ProductInventory productInventory)
        {
            Entities.ProductInventory pi = Mapper.MapProductInventory(productInventory);

            _context.Update(pi);
        }