public ActionResult Create(ServicePlanViewModel viewModel) { if (!ModelState.IsValid) { return View(viewModel); } ServicePlan servicePlan = Mapper.Map<ServicePlan>(viewModel); ServiceResult result = _servicePlanService.AddServicePlan(servicePlan); if (!result.IsValid) { result.Errors.ToList().ForEach(x => ModelState.AddModelError(x.Key.ToString(), x.Value)); return View(); } TempData["message"] = "Service plan has been added"; return RedirectToAction("Index"); }
public ActionResult Edit(ServicePlanViewModel viewModel) { if (viewModel == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } if (!ModelState.IsValid) { return View(viewModel); } ServicePlan servicePlan = Mapper.Map<ServicePlan>(viewModel); ServiceResult result = _servicePlanService.UpdateServicePlan(servicePlan); if (!result.IsValid) { result.Errors.ToList().ForEach(x => ModelState.AddModelError(x.Key.ToString(), x.Value)); return View(); } TempData["message"] = "Service plan has been edited"; return RedirectToAction("Index"); }