public int AddAuthor(Author author) { int addedAuthorId; using (var context = new LibraryEntities()) { context.Authors.Add(author); context.SaveChanges(); addedAuthorId = author.Id; } return addedAuthorId; }
public int AddBook(Book book) { int addedBookId; using (var context = new LibraryEntities()) { context.Books.Add(book); context.SaveChanges(); addedBookId = book.Id; } return addedBookId; }
public int AddCategory(Category cat) { int addedAuthorId; using (var context = new LibraryEntities()) { context.Categorys.Add(cat); context.SaveChanges(); addedAuthorId = cat.Id; } return addedAuthorId; }
public bool DeleteBookById(int id) { bool result = false; using (var context = new LibraryEntities()) { var bookToDelte = context.Books.FirstOrDefault(x => x.Id == id); if (bookToDelte != null) { context.Books.Remove(bookToDelte); context.SaveChanges(); result = true; } } return result; }
public void UpdateBookAuthor(int bookId, int authorId) { using (var context = new LibraryEntities()) { context.Books.FirstOrDefault(x => x.Id == bookId).AuthorId = authorId; context.SaveChanges(); } }
public void UpdateBookTitle(int bookId, string title) { using (var context = new LibraryEntities()) { context.Books.FirstOrDefault(x => x.Id == bookId).Title = title; context.SaveChanges(); } }
public void UpdateBookPrice(int bookId, int price) { using (var context = new LibraryEntities()) { context.Books.FirstOrDefault(x => x.Id == bookId).Price = price; context.SaveChanges(); } }
public void UpdateBookDescr(int bookId, string descr) { using (var context = new LibraryEntities()) { context.Books.FirstOrDefault(x => x.Id == bookId).Descriptn = descr; context.SaveChanges(); } }