public async Task <IActionResult> ArchiveConfirmed(int id)
        {
            var chemInventory = await _context.ChemInventory.SingleOrDefaultAsync(m => m.ChemInventoryId == id);

            ChemInventoryArc chemInventoryArc = new ChemInventoryArc();

            if (chemInventoryArc != null)
            {
                chemInventoryArc.ChemInventoryIdArc = chemInventory.ChemInventoryId;
                chemInventoryArc.ChemID             = chemInventory.ChemID;
                chemInventoryArc.LocationID         = chemInventory.LocationID;
                chemInventoryArc.ExpiryDate         = chemInventory.ExpiryDate;
                chemInventoryArc.OrderID            = chemInventory.OrderID;
                chemInventoryArc.QtyLeft            = chemInventory.QtyLeft;
                chemInventoryArc.Units      = chemInventory.Units;
                chemInventoryArc.Department = chemInventory.Department;
                chemInventoryArc.CAT        = chemInventory.CAT;
                chemInventoryArc.LOT        = chemInventory.LOT;
                _context.ChemInventoryArc.Add(chemInventoryArc);
                await _context.SaveChangesAsync();
            }
            _context.ChemInventory.Remove(chemInventory);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create(int?formulainput, DateTime dateinput, int?storageinput, int?orderinput, string cat, string lot, float qtyinput, string unitstring, string deptstring)
        {
            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;

            ChemInventoryArc chemInventoryArc = null;

            if (ModelState.IsValid)
            {
                chemInventoryArc            = new ChemInventoryArc();
                chemInventoryArc.ChemID     = formulainput;
                chemInventoryArc.LocationID = storageinput;
                chemInventoryArc.ExpiryDate = dateinput;
                chemInventoryArc.OrderID    = orderinput;
                chemInventoryArc.QtyLeft    = qtyinput;
                chemInventoryArc.Units      = unitstring;
                chemInventoryArc.Department = deptstring;
                chemInventoryArc.CAT        = cat;
                chemInventoryArc.LOT        = lot;
                var temp = _context.Locations.First(m => m.LocationID == storageinput);
                chemInventoryArc.NormalizedLocation = temp.StorageCode;

                _context.Add(chemInventoryArc);
                await _context.SaveChangesAsync();

                //               Sp_Logging("2-Change", "Create", "User created a chemical archive item where ChemID=" + formulainput + ", OrderID=" + formulainput, "Success");
                return(RedirectToAction("Index", new { barcodeFlag = true }));
            }
            ViewData["ChemID"]       = new SelectList(_context.Chemical, "ChemID", "FormulaName", chemInventoryArc.ChemID);
            ViewData["LocationName"] = new SelectList(_context.Locations, "LocationID", "StorageCode", chemInventoryArc.LocationID);
            ViewData["OrderID"]      = new SelectList(_context.Orders, "OrderID", "OrderID", chemInventoryArc.OrderID);
            return(View(chemInventoryArc));
        }
Ejemplo n.º 3
0
        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)
        {
            ChemInventoryArc chemInventoryArc = await _context.ChemInventoryArc.SingleOrDefaultAsync(p => p.ChemInventoryIdArc == id);

            if (id != chemInventoryArc.ChemInventoryIdArc)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                if (qtyinput > 0)
                {
                    ChemInventory chemInventory = null;
                    try
                    {
                        chemInventory            = new ChemInventory();
                        chemInventory.ChemID     = formulainput;
                        chemInventory.LocationID = storageinput;
                        chemInventory.ExpiryDate = dateinput;
                        chemInventory.OrderID    = orderinput;
                        chemInventory.QtyLeft    = qtyinput;
                        chemInventory.Units      = unitstring;
                        chemInventory.Department = deptstring;
                        chemInventory.CAT        = cat;
                        chemInventory.LOT        = lot;
                        var temp = _context.Locations.First(m => m.LocationID == storageinput);
                        chemInventory.NormalizedLocation = temp.StorageCode;
                        _context.Add(chemInventory);
                        await _context.SaveChangesAsync();

                        await DeleteConfirmed(id);
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!ChemInventoryArcExists(chemInventory.ChemInventoryId))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
                else
                {
                    try
                    {
                        chemInventoryArc.ChemID     = formulainput;
                        chemInventoryArc.LocationID = storageinput;
                        chemInventoryArc.ExpiryDate = dateinput;
                        chemInventoryArc.OrderID    = orderinput;
                        chemInventoryArc.QtyLeft    = qtyinput;
                        chemInventoryArc.Units      = unitstring;
                        chemInventoryArc.Department = deptstring;
                        chemInventoryArc.CAT        = cat;
                        chemInventoryArc.LOT        = lot;
                        var temp = _context.Locations.First(m => m.LocationID == storageinput);
                        chemInventoryArc.NormalizedLocation = temp.StorageCode;
                        _context.Update(chemInventoryArc);
                        await _context.SaveChangesAsync();

                        //Sp_Logging("2-Change", "Edit", "User editted a Chemical archive item where ID=" + id.ToString(), "Success");
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!ChemInventoryArcExists(chemInventoryArc.ChemInventoryIdArc))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
                return(RedirectToAction("Index"));
            }
            ViewData["ChemID"]       = new SelectList(_context.Chemical, "ChemID", "FormulaName", chemInventoryArc.ChemID);
            ViewData["LocationName"] = new SelectList(_context.Locations, "LocationID", "StorageCode", chemInventoryArc.LocationID);
            ViewData["OrderID"]      = new SelectList(_context.Orders, "OrderID", "OrderID", chemInventoryArc.OrderID);
            return(View(chemInventoryArc));
        }
        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)
        {
            ChemInventory chemInventory = await _context.ChemInventory.SingleOrDefaultAsync(p => p.ChemInventoryId == id);

            if (id != chemInventory.ChemInventoryId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                // if the amount of the chemical is changed to zero units,
                //   this places it in the archives table, and deletes it from
                //   the inventory table.
                //   possibly also sends you to the archives table. not sure yet.
                if (qtyinput == 0)
                {
                    ChemInventoryArc chemInventoryArc = null;

                    try
                    {
                        chemInventoryArc            = new ChemInventoryArc();
                        chemInventoryArc.ChemID     = formulainput;
                        chemInventoryArc.LocationID = storageinput;
                        chemInventoryArc.ExpiryDate = dateinput;
                        chemInventoryArc.OrderID    = orderinput;
                        chemInventoryArc.QtyLeft    = qtyinput;
                        chemInventoryArc.Units      = unitstring;
                        chemInventoryArc.Department = deptstring;
                        chemInventoryArc.CAT        = cat;
                        chemInventoryArc.LOT        = lot;
                        var temp = _context.Locations.First(m => m.LocationID == storageinput);
                        chemInventoryArc.NormalizedLocation = temp.StorageCode;
                        _context.Add(chemInventoryArc);
                        await _context.SaveChangesAsync();

                        // This section would change the barcode/PK of the item, inside the archive table,
                        // to match what it was in the inventory table if that was possible.
                        // The only option I see is to replace the table with one where the barcode is an
                        // additional column, or attribute, in the table, and change it using the line
                        // directly below this comment, but placed up above with the other attributes.
                        // ** there may be a method of altering a table's attributes **
                        // Doing this change would requre code changes throughout the files affiliated with chemicals

                        /*                       chemInventoryArc.ChemInventoryIdArc = chemInventory.ChemInventoryId;
                         *                     temp = _context.Locations.First(m => m.LocationID == storageinput);
                         *                     chemInventoryArc.NormalizedLocation = temp.StorageCode;
                         *                     _context.Update(chemInventoryArc);
                         *                     await _context.SaveChangesAsync();
                         */
                        //Sp_Logging("4-Archive", "Edit", "User archived a Chemical inventory item where ID= " + id.ToString(), "Success");

                        await DeleteConfirmed(id);
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!ChemInventoryExists(chemInventoryArc.ChemInventoryIdArc))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }

                    /// maybe call DeleteConfirmed(id) to delete the chemical from the inventory
                }
                else
                {
                    try
                    {
                        chemInventory.ChemID     = formulainput;
                        chemInventory.LocationID = storageinput;
                        chemInventory.ExpiryDate = dateinput;
                        chemInventory.OrderID    = orderinput;
                        chemInventory.QtyLeft    = qtyinput;
                        chemInventory.Units      = unitstring;
                        chemInventory.Department = deptstring;
                        chemInventory.CAT        = cat;
                        chemInventory.LOT        = lot;
                        var temp = _context.Locations.First(m => m.LocationID == storageinput);
                        chemInventory.NormalizedLocation = temp.StorageCode;
                        _context.Update(chemInventory);
                        await _context.SaveChangesAsync();

                        Sp_Logging("2-Change", "Edit", "User edited a Chemical inventory item where ID= " + id.ToString(), "Success");
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!ChemInventoryExists(chemInventory.ChemInventoryId))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
                return(RedirectToAction("Index"));
            }
            ViewData["ChemID"]       = new SelectList(_context.Chemical, "ChemID", "FormulaName", chemInventory.ChemID);
            ViewData["LocationName"] = new SelectList(_context.Locations, "LocationID", "StorageCode", chemInventory.LocationID);
            ViewData["OrderID"]      = new SelectList(_context.Orders, "OrderID", "OrderID", chemInventory.OrderID);
            return(View(chemInventory));
        }