public void AddBook(string name) { using (SampleDbEntities entities = new SampleDbEntities()) { Book book = new Book { BookName = name }; entities.Books.AddObject(book); entities.SaveChanges(); } }
public void DeleteBook(string id) { try { int bookId = Convert.ToInt32(id); using (SampleDbEntities entities = new SampleDbEntities()) { Book book = entities.Books.SingleOrDefault(b => b.ID == bookId); entities.Books.DeleteObject(book); entities.SaveChanges(); } } catch { throw new FaultException("Something went wrong"); } }
public void UpdateBook(string id, string name) { try { int bookId = Convert.ToInt32(id); using (SampleDbEntities entities = new SampleDbEntities()) { Book book = entities.Books.SingleOrDefault(b => b.ID == bookId); book.BookName = name; entities.SaveChanges(); } } catch { throw new FaultException("Something went wrong"); } }