public async Task <ActionResult> EditGroupAsync(GroupEditViewModel GroupViewModel) { if (ModelState.IsValid) { var administrators = GroupViewModel.GroupAdministrators; //_groupService.getg // Reset the select list GroupViewModel.AllGroups = _groupService.GetBaseSelectListGroups(_groupService.GetAll(LoggedOnReadOnlyUser?.Id) .Where(x => x.Id != GroupViewModel.Id) .ToList(), LoggedOnReadOnlyUser?.Id); var groupToEdit = _groupService.Get(GroupViewModel.Id); var group = GroupViewModel.ToGroup(groupToEdit); group.RowVersion = GroupViewModel.RowVersion; var groupResult = await _groupService.Edit(group, GroupViewModel.Files, GroupViewModel.ParentGroup, GroupViewModel.Section); if (!groupResult.Successful) { ModelState.AddModelError("", groupResult.ProcessLog.FirstOrDefault()); } else { // We use temp data because we are doing a redirect TempData[Constants.MessageViewBagName] = new GenericMessageViewModel { Message = "Group Edited", MessageType = GenericMessages.success }; // Set the view model GroupViewModel = groupResult.EntityToProcess.ToEditViewModel( _groupService.GetBaseSelectListGroups(_groupService.GetAll(LoggedOnReadOnlyUser?.Id) .Where(x => x.Id != GroupViewModel.Id) .ToList(), LoggedOnReadOnlyUser?.Id), _groupService.GetAllSections().ToSelectList()); if (administrators != null && administrators.Any()) { _groupService.AddGroupAdministrators(group.Slug, administrators.Where(x => x != Guid.Empty).ToList(), LoggedOnReadOnlyUser.Id); } else { _groupService.AddGroupAdministrators(group.Slug, new List <Guid>(), LoggedOnReadOnlyUser.Id); } return(RedirectToAction("Index")); } } GroupViewModel.Users = MembershipService.GetAll().ToSelectList(); return(View(GroupViewModel)); }
public async Task <ActionResult> CreateGroupAsync(GroupEditViewModel GroupViewModel) { if (ModelState.IsValid) { var Group = GroupViewModel.ToGroup(); Group.GroupOwner = MembershipService.GetUser(GroupViewModel.GroupOwner); var GroupResult = await _groupService.Create(Group, GroupViewModel.Files, GroupViewModel.ParentGroup, GroupViewModel.Section); if (!GroupResult.Successful) { ModelState.AddModelError("", GroupResult.ProcessLog.FirstOrDefault()); } else { if (GroupViewModel.GroupAdministrators != null && GroupViewModel.GroupAdministrators.Any()) { _groupService.AddGroupAdministrators(Group.Slug, GroupViewModel.GroupAdministrators.ToList(), LoggedOnReadOnlyUser.Id); } // We use temp data because we are doing a redirect TempData[Constants.MessageViewBagName] = new GenericMessageViewModel { Message = "Group Created", MessageType = GenericMessages.success }; return(RedirectToAction("Index")); } } else { ModelState.AddModelError("", "There was an error creating the Group"); } GroupViewModel.AllGroups = _groupService.GetBaseSelectListGroups(_groupService.GetAll(LoggedOnReadOnlyUser?.Id), LoggedOnReadOnlyUser?.Id); GroupViewModel.AllSections = _groupService.GetAllSections().ToSelectList(); GroupViewModel.Users = MembershipService.GetAll().ToSelectList(); return(View(GroupViewModel)); }