public void EditAuthor(int?authorId) { Author author = dbContext.Author .Where(c => c.AuthorID == authorId).FirstOrDefault(); if (author != null && TryUpdateModel <Author>(author)) { dbContext.Entry <Author>(author).State = EntityState.Modified; dbContext.SaveChanges(); } }
// Редактировать данные покупателя public void EditUser(int?userId) { UserInfo user = dbContext.UserInfo .Where(c => c.UserID == userId).FirstOrDefault(); if (user != null && TryUpdateModel <UserInfo>(user)) { // Обновить данные в БД с помощью Entity Framework dbContext.Entry <UserInfo>(user).State = EntityState.Modified; dbContext.SaveChanges(); } }
public void EditBook(int?bookId) { Book book = dbContext.Book .Where(c => c.BookID == bookId).FirstOrDefault(); BookAuthor bookAuthor = dbContext.BookAuthor .Where(c => c.BookID == bookId).FirstOrDefault(); Author author = dbContext.Author .Where(c => c.AuthorID == bookAuthor.AuthorID).FirstOrDefault(); if (book != null && TryUpdateModel <Book>(book)) { dbContext.Entry <Book>(book).State = EntityState.Modified; dbContext.SaveChanges(); } }