public UserGroup ReadProperties(int id) { var group = UserGroupRepository.GetPropertiesById(id); if (group == null) { throw new ApplicationException(string.Format(UserGroupStrings.GroupNotFound, id)); } return(group); }
public MessageResult RemovePreAction(int id) { var group = UserGroupRepository.GetPropertiesById(id); if (group == null) { throw new ApplicationException(string.Format(UserGroupStrings.GroupNotFound, id)); } if (group.ChildGroups.Any()) { return(MessageResult.Confirm(UserGroupStrings.ConfirmHasChildren)); } return(null); }
public CopyResult Copy(int id) { var result = new CopyResult(); var group = UserGroupRepository.GetPropertiesById(id); if (group == null) { throw new ApplicationException(string.Format(UserGroupStrings.GroupNotFound, id)); } group.MutateName(); var newId = UserGroupRepository.CopyGroup(group, QPContext.CurrentUserId); if (newId == 0) { result.Message = MessageResult.Error(UserGroupStrings.GroupHasNotBeenCreated); } else { result.Id = newId; } return(result); }
/// <summary> /// Проверка на то, что нельзя удалять встроенных пользователей из встроенной группы /// </summary> /// <param name="errors"></param> private void BuiltInUsersRemovingValidation(RulesException <UserGroup> errors) { if (BuiltIn) { var group = UserGroupRepository.GetPropertiesById(Id); if (group == null) { throw new ApplicationException(string.Format(UserGroupStrings.GroupNotFound, Id)); } var dbBuiltInUserIDs = group.Users.Where(u => u.BuiltIn).Select(u => u.Id); var builtInUserIDs = Users.Where(u => u.BuiltIn).Select(u => u.Id); var undindedBuiltInUserIDs = dbBuiltInUserIDs.Except(builtInUserIDs); if (undindedBuiltInUserIDs.Any()) { var logins = group.Users .Where(u => undindedBuiltInUserIDs.Contains(u.Id)) .Select(u => u.LogOn); var message = string.Format(UserGroupStrings.BuiltInUsersCouldntBeRemoved, string.Join(",", logins)); errors.ErrorForModel(message); } } }