public ActionResult Create(PartnerViewModel viewModel) { if (!ModelState.IsValid) { return View(viewModel); } Partner partner = Mapper.Map<Partner>(viewModel); ServiceResult result = _partnerService.AddPartner(partner); if (!result.IsValid) { result.Errors.ToList().ForEach(x => ModelState.AddModelError(x.Key.ToString(), x.Value)); return View(); } TempData["message"] = "Partner has been added"; return RedirectToAction("Index"); }
public ActionResult Edit(PartnerViewModel viewModel) { if (viewModel == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } if (!ModelState.IsValid) { return View(viewModel); } Partner partner = Mapper.Map<Partner>(viewModel); ServiceResult result = _partnerService.UpdatePartner(partner); if (!result.IsValid) { result.Errors.ToList().ForEach(x => ModelState.AddModelError(x.Key.ToString(), x.Value)); return View(); } TempData["message"] = "Partner has been edited"; return RedirectToAction("Index"); }