public async Task <int> AddItem(InventoryDTO inventoryDTO) { Inventory inventory = inventoryDTO.ToInventory(); inventory.DateAdded = DateTime.Now; await _dbContext.Inventories.AddAsync(inventory); await _dbContext.SaveChangesAsync(); return(inventory.ItemId); }
public async Task UpdateItem(InventoryDTO inventoryDTO) { Inventory inventory = _dbContext.Inventories.Find(inventoryDTO.ItemId); if (inventory is null) { throw new Exception($"Couldn't find the record with id {inventoryDTO.ItemId}"); } Inventory updatedinventory = inventoryDTO.ToInventory(); updatedinventory.DateUpdated = DateTime.Now; _dbContext.Inventories.Update(updatedinventory); await _dbContext.SaveChangesAsync(); }