public ActionResult EditPublisher(PublishersEditPublisherVM model) { LibraryManagementSystemContext context = new LibraryManagementSystemContext(); PublishersRepository publishersRepository = new PublishersRepository(context); Publisher publisher = null; if (!ModelState.IsValid) { return(View(model)); } else { if (model.ID > 0) { publisher = publishersRepository.GetByID(model.ID); } else { publisher = new Publisher(); } publisher.ID = model.ID; publisher.Name = model.Name; publisher.Address = model.Address; publishersRepository.Save(publisher); } return(RedirectToAction("Index", "Publishers")); }
public ActionResult EditPublisher(int id) { LibraryManagementSystemContext context = new LibraryManagementSystemContext(); PublishersRepository publishersRepository = new PublishersRepository(context); PublishersEditPublisherVM model = new PublishersEditPublisherVM(); Publisher publisher = publishersRepository.GetByID(id); if (id > 0) { if (publisher == null) { return(RedirectToAction("Index", "Publishers")); } model.ID = publisher.ID; model.Name = publisher.Name; model.Address = publisher.Address; } return(View(model)); }