public void SaveAuthor(Author author) { if (author.Id == 0) { db.Author.Add(author); } else { Author dbEntry = db.Author.Find(author.Id); if (dbEntry != null) { dbEntry.Name = author.Name; } } db.SaveChanges(); }
public ActionResult EditAuthor(Author author) { if (ModelState.IsValid) { SaveAuthor(author); TempData["message"] = string.Format("{0} has been saved", author.Name); return RedirectToAction("Index"); } else { // there is something wrong with the data values return View(author); } }