// this is a bool because return did it change the data context (save changes) public bool BookInventoryCreate(BookInventoryCreate model) { var content = new BookInventory() { BookInventoryID = model.BookInventoryID, UserID = _userID, BookID = model.BookID, HasRead = model.HasRead, Notes = model.Notes, TypeOfBook = model.TypeOfBook }; using (var ctx = new ApplicationDbContext()) { ctx.BookInventory.Add(content); return(ctx.SaveChanges() == 1); } }
/// <summary> /// Creates a new inventory item within the branch for a book. /// </summary> /// <param name="inventoryItem">The inventory item.</param> /// <exception cref="System.InvalidOperationException">$Book - {inventoryItem.Book.Name} - already a stock item at this branch</exception> public void AddBookInventory(BookInventory inventoryItem) { if (IsBookInInventory(inventoryItem.BookId)) throw new InvalidOperationException($"Book - {inventoryItem.BookId} - already a stock item at this branch"); if (TotalBooksInventory + inventoryItem.Total > MaxInventory) throw new OverflowException($"Adding this stock of books will take the amount of books above the maximum inventory available at branch - {Name} "); _bookInventory.Add(inventoryItem); }
public async Task <bool> CreateBookInventory(BookInventory model) => await _service.Add(model);
public async Task <int> Add(BookInventory newItem) { return (await connection.ExecuteAsync( "INSERT INTO [BookInventory] ([BookId], [Inventory]) VALUES (@BookId, @Inventory)", newItem)); }