public static void DeleteAuthor(int authorId) { using (var ctx = new BooksEntities()) { Author authorToDelete = ctx.Authors.Find(authorId); if (authorToDelete != null) { ctx.Authors.Remove(authorToDelete); ctx.SaveChanges(); } } }
public static void UpdateAuthorName(int authorId, string newFirstName, string newLastName) { //Author authorToUpdate = GetAuthorById(authorId); using (var ctx = new BooksEntities()) { Author authorToUpdate = ctx.Authors.Find(authorId); authorToUpdate.FirstName = newFirstName; authorToUpdate.LastName = newLastName; ctx.SaveChanges(); } }
public static int AddNewAuthor(string newAuthorFirstName, string newAuthorLastName) { using (var ctx = new BooksEntities()) { Author newAuthor = new Author(); newAuthor.FirstName = newAuthorFirstName; newAuthor.LastName = newAuthorLastName; ctx.Authors.Add(newAuthor); ctx.SaveChanges(); return newAuthor.AuthorID; } }