public bool Update(int id, BookEntity entry) { var book = MapBook(entry); using (var db = new LibraryDataModel()) { db.Books.Attach(book); db.Entry(entry).State = EntityState.Modified; return(db.SaveChanges() > 0); } }
public bool Update(int id, AuthorEntity entry) { var author = MapAuthor(entry); using (var db = new LibraryDataModel()) { db.Author.Attach(author); db.Entry(entry).State = EntityState.Modified; return(db.SaveChanges() > 0); } }
public bool Insert(BookEntity entry) { var book = MapBook(entry); using (var db = new LibraryDataModel()) { db.Books.Add(book); var success = db.SaveChanges() > 0; if (success) { entry.Id = book.Id; } return(success); } }
public bool Delete(int id) { using (var db = new LibraryDataModel()) { var book = db.Books.Find(id); if (book == null) { return(false); } var authorBook = (from ab in db.AuthorBook where ab.BookId == id select ab).ToList(); authorBook.ForEach(ab => db.AuthorBook.Remove(ab)); db.Books.Remove(book); return(db.SaveChanges() > 0); } }
public bool Insert(AuthorEntity entry) { var author = MapAuthor(entry); using (var db = new LibraryDataModel()) { db.Author.Add(author); var success = db.SaveChanges() > 0; if (success) { entry.Id = author.Id; } return(success); } }