public async Task <BookListModel> AddBookToList(string bookId, int bookListId) { BookListModel bookList = await GetRaw(bookListId, true); if (bookList == null) { return(null); } BookModel book = await _book.Add(await _book.Get(bookId)); if (book == null) { return(null); } if (bookList.Books.Select(b => b.Id).Contains(book.Id)) { return(bookList); } BookListModel currentBookList = await _book.UserBookList(book.Id); if (currentBookList != null) { List <Book_BookListModel> book_bookList_list = currentBookList.Book_BookLists.Where(b => b.Book.Id == book.Id).ToList(); _context.Remove(book_bookList_list.First()); } bookList.Book_BookLists.Add(new Book_BookListModel() { Book = book, BookList = bookList }); _context.Update(bookList); await _context.SaveChangesAsync(); return(bookList); }
public async Task <bool> Delete(int id) { AuthorModel item = await Get(id); if (item == null) { return(true); } try { _context.Remove(item); await _context.SaveChangesAsync(); return(true); } catch (DbUpdateConcurrencyException) { item = await Get(id); return(item == null); } }