public List<Book> GetBooksList() { using (var bookContext = new BookContext()) { return bookContext.Books.ToList(); } }
public void AddBook(string name) { using (var bookContext = new BookContext()) { Book book = new Book { BookName = name }; bookContext.Books.Add(book); bookContext.SaveChanges(); } }
public Book GetBookById(string id) { try { int bookId = Convert.ToInt32(id); using (var bookContext = new BookContext()) { return bookContext.Books.SingleOrDefault(book => book.Id == bookId); } } catch { throw new FaultException("Something went wrong"); } }
public void DeleteBook(string id) { try { int bookId = Convert.ToInt32(id); using (var bookContext = new BookContext()) { Book book = bookContext.Books.SingleOrDefault(b => b.Id == bookId); bookContext.Books.Remove(book); bookContext.SaveChanges(); } } catch { throw new FaultException("Something went wrong"); } }