public IActionResult Upsert(BulkyBook.Models.CoverType cover) { if (ModelState.IsValid) { if (cover.Id == 0) { _coverTypeRepository.Add(cover); } else { _coverTypeRepository.Update(cover); } _coverTypeRepository.Commit(); return(RedirectToAction(nameof(Index))); // action name } return(View(cover)); }
public IActionResult Upsert(int?id) { BulkyBook.Models.CoverType cover = new BulkyBook.Models.CoverType(); //SOME ERROR with Single class initialization. if (id == null) { // Create return(View(cover)); } // Update cover = _coverTypeRepository.GetById(id.GetValueOrDefault()); if (cover == null) { // Incorrect ID return(NotFound()); } return(View(cover)); }