public async Task <IActionResult> Create(int?formulainput, DateTime dateinput, int?storageinput, int?orderinput, string cat, string lot, float qtyinput, string unitstring, string deptstring, string manustring) { ViewData["Formula"] = formulainput; ViewData["ExpiryDate"] = dateinput; ViewData["StorageCode"] = storageinput; ViewData["Order"] = orderinput; ViewData["Qty"] = qtyinput; ViewData["Unit"] = unitstring; ViewData["Department"] = deptstring; ViewData["CAT"] = cat; ViewData["LOT"] = lot; ViewData["Manufacturer"] = manustring; ChemInventory2 chemInventory2 = null; if (ModelState.IsValid) { chemInventory2 = new ChemInventory2(); chemInventory2.ChemID = formulainput; chemInventory2.LocationID = storageinput; chemInventory2.ExpiryDate = dateinput; chemInventory2.OrderID = orderinput; chemInventory2.QtyLeft = qtyinput; chemInventory2.Units = unitstring; chemInventory2.Department = deptstring; chemInventory2.CAT = cat; chemInventory2.LOT = lot; chemInventory2.Manufacturer = manustring; var temp = _context.Locations.First(m => m.LocationID == storageinput); chemInventory2.NormalizedLocation = temp.StorageCode; _context.Add(chemInventory2); await _context.SaveChangesAsync(); chemInventory2.Barcode = chemInventory2.ChemInventoryMId; _context.Update(chemInventory2); await _context.SaveChangesAsync(); Sp_Logging("2-Change", "Create", "User created a chemical inventory item where ChemID=" + formulainput + ", OrderID=" + formulainput, "Success"); return(RedirectToAction("Index", new { barcodeFlag = true })); } ViewData["ChemID"] = new SelectList(_context.Chemical, "ChemID", "FormulaName", chemInventory2.ChemID); ViewData["LocationName"] = new SelectList(_context.Locations, "LocationID", "StorageCode", chemInventory2.LocationID); ViewData["OrderID"] = new SelectList(_context.Orders, "OrderID", "OrderID", chemInventory2.OrderID); return(View(chemInventory2)); }
public async Task <IActionResult> Edit(int id, int?formulainput, DateTime dateinput, int?storageinput, int?orderinput, string cat, string lot, float qtyinput, string unitstring, string deptstring, string manustring) { ChemInventory2 chemInventory2 = await _context.ChemInventory2.SingleOrDefaultAsync(p => p.ChemInventoryMId == id); if (id != chemInventory2.ChemInventoryMId) { return(NotFound()); } if (ModelState.IsValid) { if (qtyinput == 0) { ChemInventoryArc2 chemInventoryArc2 = null; try { chemInventoryArc2 = new ChemInventoryArc2(); chemInventoryArc2.ChemID = formulainput; chemInventoryArc2.LocationID = storageinput; chemInventoryArc2.ExpiryDate = dateinput; chemInventoryArc2.OrderID = orderinput; chemInventoryArc2.QtyLeft = qtyinput; chemInventoryArc2.Units = unitstring; chemInventoryArc2.Department = deptstring; chemInventoryArc2.CAT = cat; chemInventoryArc2.LOT = lot; chemInventoryArc2.Manufacturer = manustring; chemInventoryArc2.Barcode = chemInventory2.Barcode; var temp = _context.Locations.First(m => m.LocationID == storageinput); chemInventoryArc2.NormalizedLocation = temp.StorageCode; _context.Add(chemInventoryArc2); await _context.SaveChangesAsync(); await DeleteConfirmed(id); Sp_Logging("2-Archive", "Edit", "User archived a Chemical inventory item where ID= " + id.ToString(), "Success"); } catch (DbUpdateConcurrencyException) { if (!ChemInventory2Exists(chemInventoryArc2.ChemInventoryMIdArc)) { return(NotFound()); } else { throw; } } } else { try { chemInventory2.ChemID = formulainput; chemInventory2.LocationID = storageinput; chemInventory2.ExpiryDate = dateinput; chemInventory2.OrderID = orderinput; chemInventory2.QtyLeft = qtyinput; chemInventory2.Units = unitstring; chemInventory2.Department = deptstring; chemInventory2.CAT = cat; chemInventory2.LOT = lot; chemInventory2.Manufacturer = manustring; var temp = _context.Locations.First(m => m.LocationID == storageinput); chemInventory2.NormalizedLocation = temp.StorageCode; _context.Update(chemInventory2); await _context.SaveChangesAsync(); Sp_Logging("2-Change", "Edit", "User edited a Chemical inventory item where ID= " + id.ToString(), "Success"); } catch (DbUpdateConcurrencyException) { if (!ChemInventory2Exists(chemInventory2.ChemInventoryMId)) { return(NotFound()); } else { throw; } } } return(RedirectToAction("Index")); } ViewData["ChemID"] = new SelectList(_context.Chemical, "ChemID", "FormulaName", chemInventory2.ChemID); ViewData["LocationName"] = new SelectList(_context.Locations, "LocationID", "StorageCode", chemInventory2.LocationID); ViewData["OrderID"] = new SelectList(_context.Orders, "OrderID", "OrderID", chemInventory2.OrderID); return(View(chemInventory2)); }