public async void ModifyBook(BookModifyInputModel book) { var bookEntity = new Book { Id = book.BookId, Title = book.Title, Isbn = book.Isbn, PublishingYear = book.PublishingYear ?? default(int), Type = book.Type, Price = book.Price ?? default(double), PublisherId = book.Publisher ?? default(int) }; _bookRepo.ModBook(bookEntity); var details = new BookDetails { Id = _bookRepo.GetDetailsId(book.BookId), BookId = book.BookId, Description = book.Description, Font = book.Font, PageCount = book.PageCount ?? default(int), Length = book.Length ?? default(int) }; _bookRepo.ModBookDetails(details); var genreConnections = _bookRepo.GetBookGenreConnections(book.BookId); foreach (var g in genreConnections) { _bookRepo.RemoveBookGenreConnection(g); } foreach (var g in book.Genre) { var genreConnection = new BookGenreConnection { BookId = book.BookId, GenreId = g }; _bookRepo.AddBookGenreConnection(genreConnection); } var authorConnections = _bookRepo.GetBookAuthorConnections(book.BookId); foreach (var a in authorConnections) { _bookRepo.RemoveBookAuthorConnection(a); } foreach (var a in book.Author) { var authorConnection = new BookAuthorConnection { BookId = book.BookId, AuthorId = a }; _bookRepo.AddBookAuthorConnection(authorConnection); } if (book.NewCoverImage != null) { using (var memoryStream = new MemoryStream()) { await book.NewCoverImage.CopyToAsync(memoryStream); var img = new CoverImage { Id = _bookRepo.GetCoverImageId(book.BookId), BookId = book.BookId, Img = memoryStream.ToArray() }; _bookRepo.ModImage(img); } } }