public IActionResult PutInventoryItem(int id, InventoryItem inventoryItem) { if (id != inventoryItem.ItemId) { return(BadRequest()); } if (inventoryItem.ItemQuantity > 5) { return(BadRequest("Quantity is above limit")); } if (InventoryItemRepository.GetTotalQuantity() + inventoryItem.ItemQuantity > 200) { return(BadRequest($"Total items are above 200, your current limit to add is {200- InventoryItemRepository.GetTotalQuantity()}")); } _context.Entry(inventoryItem).State = EntityState.Modified; try { _context.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!InventoryItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void AddNewItem(InventoryItem item) { _context.Add(item); _context.SaveChanges(); }