예제 #1
0
 public void UpdateLocationInventory(Models.Location location, Models.Product product, int delta)
 {
     Entities.Inventory i = ctx.Inventories.Where(i => i.LocationId == location.LocationID && i.ProductId == product.ProductID).ToList().FirstOrDefault();
     if (i == null)
     {
         i = new Entities.Inventory();
         if (location.LocationID != null)
         {
             i.LocationId = (int)location.LocationID;
         }
         if (product.ProductID != null)
         {
             i.ProductId = (int)product.ProductID;
         }
         i.Quantity = 0;
         ctx.Inventories.Add(i);
     }
     i.Quantity += delta;
     if (i.Quantity < 0)
     {
         throw new Exception("Tried to set inventory quantity to " + i.Quantity);
     }
     else if (i.Quantity == 0)
     {
         ctx.Inventories.Remove(i);
     }
     using var log = new LoggerConfiguration()
                     .WriteTo.File("log.txt", rollingInterval: RollingInterval.Day, shared: true)
                     .CreateLogger();
     log.Information("TRANSACTION: Updated inventory");
     ctx.SaveChanges();
 }
예제 #2
0
 public Model.Inventory ParseInventory(Entities.Inventory inventory)
 {
     return(new Model.Inventory
     {
         InventoryID = inventory.InventoryId,
         ProductID = inventory.ProductId,
         ProductQuantity = inventory.ProductQuantity.Value,
         InventoryLocation = inventory.LocationId,
         InventoryName = inventory.InventoryName
     });
 }
        public void UpdateInventory(Inventory inventoryForUpdate)
        {
            //find details for old inventory
            Entity.Inventory oldInventory = _context.Inventories.Find(inventoryForUpdate.InventoryID);
            oldInventory.ProductQuantity = inventoryForUpdate.ProductQuantity;

            _context.Inventories.Update(oldInventory);

            //_context.Entry(oldInventory).CurrentValues.SetValues(_mapper.ParseInventory(inventoryForUpdate).ProductQuantity);

            _context.SaveChanges();

            _context.ChangeTracker.Clear();
        }