public ActionResult Edit(int id, ReviewerModel reviewerModel) { if (ModelState.IsValid) { Reviewer reviewer; if (id == default(int)) { reviewer = ModelFactoryInstance.Parse(new Reviewer(), reviewerModel); reviewer.State = ObjectState.Added; _reviewerRepo.Insert(reviewer); } else { reviewer = _reviewerRepo.FindById(id); reviewer = ModelFactoryInstance.Parse(reviewer, reviewerModel); reviewer.State = ObjectState.Modified; _reviewerRepo.Update(reviewer); } _unitOfWork.Save(); return RedirectToAction("Index"); } return View(reviewerModel); }
public ActionResult Edit(int? id) { ReviewerModel reviewerModel = null; if (id != null) { var reviewer = _reviewerRepo.FindById(id); if (reviewer != null) { reviewerModel = ModelFactoryInstance.Create(reviewer); } } if (reviewerModel == null) { reviewerModel = new ReviewerModel(); } return View(reviewerModel); }
public Reviewer Parse(Reviewer reviewer, ReviewerModel reviewerModel) { reviewer.Name = reviewerModel.Name; reviewer.SiteUrl = reviewerModel.SiteUrl; return reviewer; }