コード例 #1
0
 public ActionResult Edit(int id, SideXC.WebUI.Models.Inventory.Inventory inventory, IFormCollection collection)
 {
     if (id != inventory.Id)
     {
         return(NotFound());
     }
     if (ModelState.IsValid)
     {
         var model          = _context.Inventories.Include(m => m.Material).Include(l => l.Location).ThenInclude(h => h.Hallway).ThenInclude(w => w.Warehouse).FirstOrDefault(i => i.Id == id);
         var QtyToMove      = double.Parse(collection["txtCantidadMover"].ToString());
         var Newlocation    = _context.Locations.Include(h => h.Hallway).ThenInclude(w => w.Warehouse).FirstOrDefault(u => u.Id == int.Parse(collection["ddLocations"].ToString()));
         var material       = _context.Materials.FirstOrDefault(u => u.Id == int.Parse(collection["hddMaterialId"].ToString()));
         var modelInventory = _context.Inventories.FirstOrDefault(i => i.Location.Id == Newlocation.Id && i.Material.Id == material.Id);
         inventory = model;
         inventory.QuantityAvailable -= QtyToMove;
         inventory.Modified           = DateTime.Now;
         inventory.ModifiedBy         = UserLogged;
         if (modelInventory != null)
         {
             modelInventory.QuantityAvailable += QtyToMove;
             modelInventory.Modified           = DateTime.Now;
             modelInventory.ModifiedBy         = UserLogged;
             _context.Update(modelInventory);
         }
         else
         {
             modelInventory                   = new Models.Inventory.Inventory();
             modelInventory.Location          = Newlocation;
             modelInventory.Material          = material;
             modelInventory.QuantityAvailable = QtyToMove;
             modelInventory.Created           = DateTime.Now;
             modelInventory.CreatedBy         = UserLogged;
             modelInventory.Modified          = DateTime.Now;
             modelInventory.ModifiedBy        = UserLogged;
             _context.Add(modelInventory);
         }
         _context.Update(inventory);
         _context.SaveChanges();
         var transactionType = _context.TransactionTypes.FirstOrDefault(t => t.Code == "ML");
         AddTransactionLog(inventory.Material, inventory.Location, QtyToMove, transactionType);
         return(RedirectToAction(nameof(Index)));
     }
     return(View(inventory));
 }
コード例 #2
0
        public async Task <IActionResult> Create(SideXC.WebUI.Models.Inventory.Inventory inventory, IFormCollection collection)
        {
            if (ModelState.IsValid)
            {
                var location        = _context.Locations.FirstOrDefault(u => u.Id == int.Parse(collection["ddLocations"].ToString()));
                var material        = _context.Materials.FirstOrDefault(u => u.Id == int.Parse(collection["hddMaterialId"].ToString()));
                var transactionType = _context.TransactionTypes.FirstOrDefault(u => u.Id == int.Parse(collection["ddTransactionTypes"].ToString()));
                var modelInventory  = _context.Inventories.FirstOrDefault(i => i.Location.Id == location.Id && i.Material.Id == material.Id);
                inventory.Location   = location;
                inventory.Material   = material;
                inventory.Created    = DateTime.Now;
                inventory.CreatedBy  = UserLogged;
                inventory.Modified   = DateTime.Now;
                inventory.ModifiedBy = UserLogged;
                if (modelInventory != null)
                {
                    if (transactionType.Sign == eSign.Plus)
                    {
                        modelInventory.QuantityAvailable += inventory.QuantityAvailable;
                    }
                    else
                    {
                        modelInventory.QuantityAvailable -= inventory.QuantityAvailable;
                    }
                    _context.Update(modelInventory);
                }
                else
                {
                    _context.Add(inventory);
                }
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(inventory));
        }