Пример #1
0
        public UserInfoDto UpdateUserMentorRole(int adminId, int userId, UserType userType)
        {
            User admin = _userRepository.Get(adminId);
            User user  = _userRepository.Get(userId);

            if (admin.UserType != UserType.Admin)
            {
                throw RecademyException.NotEnoughPermission(adminId, admin.UserType, UserType.Admin);
            }

            if (user.UserType == UserType.Admin)
            {
                throw new RecademyException($"Cannot change role, user with id {userId} has admin role");
            }

            if (userType == UserType.Admin)
            {
                throw new RecademyException("Cannot set admin role. Action is not supported");
            }

            return(_userRepository
                   .UpdateUserRole(user, userType)
                   .To(ConvertToDto));
        }