public ActionResult Create(HostedOrganisationViewModel viewModel) { if (!ModelState.IsValid) { return View(viewModel); } HostedOrganisation hostedOrganisation = Mapper.Map<HostedOrganisation>(viewModel); ServiceResult result = _hostedOrganisationService.AddHostedOrganisation(hostedOrganisation); if (!result.IsValid) { result.Errors.ToList().ForEach(x => ModelState.AddModelError(x.Key.ToString(), x.Value)); return View(); } TempData["message"] = "Hosted Organisation has been added"; return RedirectToAction("Index"); }
public ActionResult Edit(HostedOrganisationViewModel viewModel) { if (viewModel == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } if (!ModelState.IsValid) { return View(viewModel); } HostedOrganisation hostedOrganisation = _hostedOrganisationService.GetHostedOrganisation(viewModel.ID); hostedOrganisation.DomainNames.ToList().ForEach(x => { hostedOrganisation.DomainNames.Remove(x); _hostedOrganisationService.RemoveDomainNames(x); }); hostedOrganisation.PhoneNumbers.ToList().ForEach(x => { hostedOrganisation.PhoneNumbers.Remove(x); _hostedOrganisationService.RemoveTelephone(x);}); Mapper.Map(viewModel, hostedOrganisation); ServiceResult result = _hostedOrganisationService.UpdateHostedOrganisation(hostedOrganisation); if (!result.IsValid) { result.Errors.ToList().ForEach(x => ModelState.AddModelError(x.Key.ToString(), x.Value)); return View(); } TempData["message"] = "Hosted Organisation has been edited"; return RedirectToAction("Index"); }