public async Task <IActionResult> Edit(int id, [Bind("WildeRoverItemId,Name,Par,Have,Type,SubType")] WildeRoverItem wildeRoverItem) { if (id != wildeRoverItem.WildeRoverItemId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(wildeRoverItem); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WildeRoverItemExists(wildeRoverItem.WildeRoverItemId)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(wildeRoverItem)); }
public async Task <IActionResult> Create([Bind("WildeRoverItemId,Name,Par,Have,Type, SubType")] WildeRoverItem wildeRoverItem) { if (ModelState.IsValid) { _context.Add(wildeRoverItem); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(wildeRoverItem)); }
public async Task <IActionResult> Submit(int?id, InventorySummarySubmitViewModel isvm) { //Validate if (id == null) { return(NotFound()); } if (ModelState.IsValid) { try { //save itemCounts //Get InventorySummary var summary = await(from log in _context.InventoryLog.Include("InventoryAreaLogs.Inventory.Item") where log.InventorySummaryId == isvm.InventorySummaryId select log).SingleOrDefaultAsync(); //Create Dictionary of Items for O(n) tallying var items = await(from i in _context.WildeRoverItem select i).ToDictionaryAsync(t => t.WildeRoverItemId); //Reset item Have values foreach (var item in items) { item.Value.Have = 0; } //Save Inventory counts to Item Have foreach (var log in summary.InventoryAreaLogs) { foreach (var item in log.Inventory) { WildeRoverItem temp = items[item.WildeRoverItemId]; temp.Have += item.Count; _context.WildeRoverItem.Update(temp); //Update context } } //Change LastEdited var user = await _userManager.GetUserAsync(User); if (user == null) { throw new InvalidOperationException(); } summary.LastEdited = user.FullName; _context.InventoryLog.Update(summary); //====EMAIL PARTIES HERE=================================== //========================================================= //Update InventorySummary status summary.Submitted = true; _context.InventoryLog.Update(summary); await _context.SaveChangesAsync(); //Save context } catch (DbUpdateConcurrencyException) { throw; } return(RedirectToAction("Index")); } return(RedirectToAction("Index")); }