public async Task <IActionResult> Edit(int id, [Bind("ProductID,StockLevel")] OwnerInventory ownerInventory) { if (id != ownerInventory.ProductID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(ownerInventory); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OwnerInventoryExists(ownerInventory.ProductID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ProductID"] = new SelectList(_context.Product, "ProductID", "Name", ownerInventory.ProductID); return(View(ownerInventory)); }
public async Task <IActionResult> Edit(int id, [Bind("ProductID,StockLevel")] OwnerInventory ownerInventory) { _context.Update(ownerInventory); await _context.SaveChangesAsync(); ViewData["ProductID"] = new SelectList(_context.Products, "ProductID", "ProductID", ownerInventory.ProductID); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> ProcessStockRequest(int id) { var query = _context.StockRequests.Include(s => s.Product).Include(s => s.Store); var stock = query.Where(s => s.StockRequestID == id).SingleOrDefault(); var request = _context.OwnerInventory.Include(x => x.Product).Select(x => x); request = request.Where(s => s.ProductID == stock.ProductID); var productID = stock.ProductID; var stocklevel = request.SingleOrDefault().StockLevel - stock.Quantity; var storeRequest = _context.StoreInventory.Include(s => s.Product).Include(s => s.Store);; var store = storeRequest.Where(s => s.StoreID == stock.StoreID).Where(p => p.ProductID == stock.ProductID).SingleOrDefault(); //Check StockLevel from Owner Inventory if (stock.Quantity <= request.SingleOrDefault().StockLevel) { var storeInventory = new StoreInventory { StoreID = stock.StoreID, ProductID = stock.ProductID, StockLevel = stock.Quantity }; //Update Store Inventory //Add New Item if (store == null) { _context.Add(storeInventory); } //Replenish Store Inventory StockLevel else if (store != null) { StoreInventory stores = new StoreInventory(); stores = _context.StoreInventory.Find(stock.StoreID, stock.ProductID); stores.StockLevel = (store.StockLevel + stock.Quantity); } _context.Remove(stock); //Upate Stock Request OwnerInventory owner = new OwnerInventory(); owner = _context.OwnerInventory.Find(productID); owner.StockLevel = stocklevel; //Update Owner Inventory await _context.SaveChangesAsync(); return(RedirectToAction(nameof(StockRequest))); } else { ViewData["ProductID"] = stock.StockRequestID; ViewData["ProductName"] = stock.Product.Name; ViewData["Quantity"] = stock.Quantity; ViewData["CurrentStock"] = request.SingleOrDefault().StockLevel; ViewData["Availability"] = "False"; ViewData["Aval"] = "Not enough stock"; } return(View()); }
public async Task <IActionResult> Create([Bind("ProductID,StockLevel")] OwnerInventory ownerInventory) { if (ModelState.IsValid) { _context.Add(ownerInventory); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ProductID"] = new SelectList(_context.Products, "ProductID", "ProductID", ownerInventory.ProductID); return(View(ownerInventory)); }
/// <summary> /// used to set stock owner inventory /// </summary> /// <param name="id"></param> /// <returns></returns> //[ValidateAntiForgeryToken] public IActionResult PutInventory(OwnerInventory ownerInventory) { try { if (!ModelState.IsValid) { throw new Exception("Invalid Input"); } _context.Update(ownerInventory); _context.SaveChanges(); return(RedirectToAction("Inventory", "Owner")); } catch (Exception e) { ViewBag.ErrorMsg = e.Message; return(View("~/Views/Common/Error.cshtml")); } }
public async Task <IActionResult> SetStockLevel(int id, [Bind("ProductID,Product,StockLevel")] OwnerInventory ownerInventory) { if (id != ownerInventory.ProductID) { return(NotFound()); } var have = _context.OwnerInventory.AsNoTracking().First(x => x.ProductID == id); //Cannot update the stock level to a lower figure (compare with current level) if (ownerInventory.StockLevel < have.StockLevel) { //ViewBag.Wrong = "Can not set to a LOWER stock level !"; //return View(ownerInventory); return(NotFound("Can not set to a LOWER stock level !")); } if (ModelState.IsValid) { try { _context.Update(ownerInventory); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(ownerInventory.ProductID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Inventory))); } return(View(ownerInventory)); }
public async Task <IActionResult> SetOwnerStock(int id, [Bind("ProductID,StockLevel")] OwnerInventory OwnerInventory) { if (id != OwnerInventory.ProductID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(OwnerInventory); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { } return(RedirectToAction(nameof(OwnerInventory))); } OwnerInventory.Product = await _context.Products.SingleOrDefaultAsync(m => m.ProductID == id); return(View(OwnerInventory)); }
public async Task <IActionResult> AddNoStockRequest(int productID, [Bind("ProductID,Product,StockLevel")] OwnerInventory ownerInventory) { if (productID != ownerInventory.ProductID) { return(NotFound()); } _storeID = GetStoreID(); StockRequest newRequest = new StockRequest(); newRequest.StoreID = _storeID; newRequest.ProductID = ownerInventory.ProductID; newRequest.Quantity = ownerInventory.StockLevel; if (ModelState.IsValid) { try { _context.Add(newRequest); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(ownerInventory.ProductID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Inventory))); } return(NotFound()); }