Exemple #1
0
 public IActionResult ImportProduct(Inventory inventory)
 {
     if (ModelState.IsValid)
     {
         var location     = _storeRepo.GetStoreById(inventory.StoreId);
         var productCheck = ProductExists(inventory.ProductName);
         if (productCheck != false)
         {
             var product        = _productRepo.GetProductByName(inventory.ProductName);
             var existInventory = location.Inventory.Any(i => i.ProductName == inventory.ProductName);
             if (existInventory)
             {
                 var invItem = location.Inventory.Find(i => i.ProductName == inventory.ProductName);
                 invItem.Stock += inventory.Stock;
                 _storeRepo.UpdateInventory(location.StoreId, product.ProductName, invItem.Stock);
                 return(RedirectToAction("Details", new { id = location.StoreId }));
             }
             else
             {
                 _storeRepo.CreateInventory(location, product, inventory.Stock);
                 return(RedirectToAction("Details", new { id = location.StoreId }));
             }
         }
     }
     else
     {
         throw new Exception("Controller Error!");
     }
     return(View());
 }
Exemple #2
0
 public IActionResult AddToInventory(Inventory inventoryItem)
 {
     if (ModelState.IsValid)
     {
         var location = _storeRepo.GetStoreById(inventoryItem.StoreId);
         var invItem  = location.Inventory.Find(i => i.ProductName == inventoryItem.ProductName);
         invItem.Stock += inventoryItem.Stock;
         _storeRepo.UpdateInventory(inventoryItem.StoreId, inventoryItem.ProductName, invItem.Stock);
         return(RedirectToAction("Details", new { id = inventoryItem.StoreId }));
     }
     return(View());
 }
        public List <Inventory> GetInventoryByStore(Store store)
        {
            using var context = new project0Context(_context);
            var dbInventory = context.Inventories
                              .Where(i => i.StoreId == store.StoreId)
                              .Include(i => i.Product)
                              .ToList();
            var result = new List <Inventory>();

            foreach (var item in dbInventory)
            {
                var newItem = new Inventory(item.StoreId, item.Product.ProductName, item.Stock)
                {
                    InventoryId = item.InventoryId
                };
                result.Add(newItem);
            }
            return(result);
        }
        public Inventory GetInventoryById(int?id)
        {
            using var context = new project0Context(_context);
            var dbInventory = context.Inventories
                              .Where(i => i.InventoryId == id)
                              .Include(i => i.Product)
                              .FirstOrDefault();

            if (dbInventory == null)
            {
                return(null);
            }
            else
            {
                var result = new Inventory()
                {
                    InventoryId = dbInventory.InventoryId,
                    StoreId     = dbInventory.StoreId,
                    ProductName = dbInventory.Product.ProductName,
                    Stock       = dbInventory.Stock
                };
                return(result);
            }
        }