public void AddOrUpdateAuthor(Author author) { if (author.Id == default(int)) context.Authors.Add(author); else context.Entry(author).State = EntityState.Modified; }
public async Task<IActionResult> Edit(Author author) { if (ModelState.IsValid) { _context.Update(author); await _context.SaveChangesAsync(); return RedirectToAction("Index"); } return View(author); }
public IActionResult Create(Author author) { if (ModelState.IsValid) { _context.Author.Add(author); _context.SaveChanges(); return RedirectToAction("Index"); } return View(author); }
public IActionResult Create(Author author) { if (ModelState.IsValid) { db.AddOrUpdateAuthor(author); db.SaveChanges(); TempData["success"] = $"New author added with Id = {author.Id}"; return RedirectToAction("Index"); } return View(author); }
public IActionResult Edit(Author author) { if (ModelState.IsValid) { db.AddOrUpdateAuthor(author); db.SaveChanges(); TempData["success"] = $"Changes to author with Id = {author.Id} saved successfully"; return RedirectToAction("Index"); } return View(author); }