Esempio n. 1
0
        public UserGroup ReadProperties(int id)
        {
            var group = UserGroupRepository.GetPropertiesById(id);

            if (group == null)
            {
                throw new ApplicationException(string.Format(UserGroupStrings.GroupNotFound, id));
            }

            return(group);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        /// <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);
                }
            }
        }