public async Task <IActionResult> Create(int barcodeinput, int courseinput, float qtyusedinput) { ViewData["Barcode"] = barcodeinput; ViewData["Course"] = courseinput; ViewData["Qty"] = qtyusedinput; if (_context.ChemInventory.Count(M => M.ChemInventoryId == barcodeinput) >= 1) { ChemLog chemLog = new ChemLog(); ChemInventory temp = _context.ChemInventory.FirstOrDefault(s => s.ChemInventoryId == barcodeinput); float tempValue = temp.QtyLeft; temp.QtyLeft = tempValue - qtyusedinput; _context.Entry <ChemInventory>(temp).State = EntityState.Modified; _context.SaveChanges(); //chemLog.DatetimeCreated = DateTime.Now; if (ModelState.IsValid) { chemLog.ChemInventoryId = barcodeinput; chemLog.CourseID = courseinput; chemLog.QtyUsed = qtyusedinput; _context.Add(chemLog); await _context.SaveChangesAsync(); sp_Logging("2-Change", "Create", "User created a Log entry where Barcode=" + barcodeinput, "Success"); return(RedirectToAction("Index")); } ViewData["CourseID"] = new SelectList(_context.Course, "CourseID", "NormalizedStr", chemLog.CourseID); return(View(chemLog)); } else { return(View("CheckBarcode")); } }
public async Task <IActionResult> Edit(int id, int barcodeinput, int courseinput, float qtyusedinput) { if (_context.ChemInventory.Count(M => M.ChemInventoryId == barcodeinput) >= 1) { ChemLog chemLog = await _context.ChemLog.FirstAsync(m => m.ChemLogId == id); ChemInventory temp = _context.ChemInventory.FirstOrDefault(s => s.ChemInventoryId == barcodeinput); float tempValue = temp.QtyLeft; float used = chemLog.QtyUsed; temp.QtyLeft = tempValue + used - qtyusedinput; _context.Entry <ChemInventory>(temp).State = EntityState.Modified; _context.SaveChanges(); chemLog.ChemInventoryId = barcodeinput; chemLog.CourseID = courseinput; chemLog.QtyUsed = qtyusedinput; if (id != chemLog.ChemLogId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(chemLog); await _context.SaveChangesAsync(); sp_Logging("2-Change", "Edit", "User edited a Log entry where ID= " + id.ToString(), "Success"); } catch (DbUpdateConcurrencyException) { if (!ChemLogExists(chemLog.ChemLogId)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } ViewData["Barcode"] = new SelectList(_context.ChemInventory, "ChemInventoryId", "ChemInventoryId", chemLog.ChemInventoryId); ViewData["CourseID"] = new SelectList(_context.Course, "CourseID", "NormalizedStr", chemLog.CourseID); return(View(chemLog)); } else { return(View("CheckBarcode")); } }