public ActionResult Create(ApplicationEditModel applicationEditModel) { var applicationToCreate = new Application(); Mapper.Map(applicationEditModel.Application, applicationToCreate); SetApplicationRoles(applicationToCreate, applicationEditModel.OrderedRoles, applicationEditModel.UnorderedRoles); applicationToCreate.TransferValidationMessagesTo(ModelState); if (ModelState.IsValid) { _applicationRepository.EnsurePersistent(applicationToCreate); Message = "Application Created Successfully"; return(Json(new { success = true })); } else { var viewModel = ApplicationViewModel.Create(Repository); viewModel.Application = applicationEditModel.Application; return(View(viewModel)); } }
public ActionResult Edit(int id, ApplicationEditModel applicationEditModel) { var applicationToEdit = _applicationRepository.GetNullableById(id); if (applicationToEdit == null) { return(RedirectToAction("Index")); } Mapper.Map(applicationEditModel.Application, applicationToEdit); SetApplicationRoles(applicationToEdit, applicationEditModel.OrderedRoles, applicationEditModel.UnorderedRoles); applicationToEdit.TransferValidationMessagesTo(ModelState); if (ModelState.IsValid) { _applicationRepository.EnsurePersistent(applicationToEdit); Message = "Application Edited Successfully"; return(Json(new { success = true })); } else { var viewModel = ApplicationViewModel.Create(Repository); viewModel.Application = applicationEditModel.Application; return(View(viewModel)); } }