public ActionResult CreateEdit(ProfileGroupViewModel model) { if (ModelState.IsValid) { var group = Mapper.Map <ProfileGroup>(model); if (group.Id == Guid.Empty) { group.CreatedBy = User.Identity.Name; group.CreatedOn = DateTime.UtcNow; } group.UpdatedBy = User.Identity.Name; group.UpdatedOn = DateTime.UtcNow; try { _profileGroupRepository.Save(group); } catch (DuplicateNameException) { ModelState.AddModelError("NameMustBeUnique", Resources.Profile_Group_Error_Profile_Group_Could_Not_Be_Saved_The_Name_Is_Already_In_Use); return(View("CreateEdit", model)); } return(RedirectToAction("Index")); } return(View("CreateEdit", model)); }
public ActionResult CreateEdit(ProfileGroupViewModel model) { if (ModelState.IsValid) { var group = Mapper.Map <ProfileGroup>(model); if (group.Id == Guid.Empty) { group.CreatedBy = User.Identity.Name; group.CreatedOn = DateTime.UtcNow; } group.UpdatedBy = User.Identity.Name; group.UpdatedOn = DateTime.UtcNow; try { _profileGroupRepository.Save(group); } catch (DuplicateNameException ex) { ModelState.AddModelError("NameMustBeUnique", "Gruppen kunde inte sparas. Namnet används redan."); return(View("CreateEdit", model)); } return(RedirectToAction("Index")); } return(View("CreateEdit", model)); }
public ActionResult Create() { ViewBag.Title = Resources.New_ProfileGroup; var model = new ProfileGroupViewModel(); PopulateViewModel(model); return(View("CreateEdit", model)); }
private void PopulateViewModel(ProfileGroupViewModel model) { var profiles = _profileRepository.GetAllProfileInfos() ?? new List <ProfileInfo>(); var notSelectedViewModels = profiles.Where(p => !model.Profiles.Select(pr => pr.Id).Contains(p.Id)).OrderBy(p => p.Name).Select(p => new ProfileListItemViewModel() { Id = p.Id, Name = p.Name, Selected = false }); model.Profiles.AddRange(notSelectedViewModels); }
public ActionResult Edit(ProfileGroupViewModel model) { if (ModelState.IsValid) { var group = Mapper.Map <ProfileGroup>(model); group.UpdatedBy = User.Identity.Name; _profileGroupRepository.Save(group); return(RedirectToAction("Index")); } return(View("CreateEdit", model)); }