private User AddUser(User user, int userTypeId)
        {
            if (_userService.UserExists(user.Email))
            {
                throw new ApplicationException("User already registered");
            }

            user.UserType = _userRepository.GetUserType(userTypeId);

            user.Id = _userRepository.Add(Mapper.Map <User, UserDto>(user));
            _permissionRepository.AddUserPermissions(user.Id, user.UserType);

            return(user);
        }
Exemple #2
0
        public void Update(long userId, string name = null, string email = null, string password = null,
                           RegistrationStatus?registrationStatus = null, UserType userType = null, string phoneNumber = null)
        {
            var userDto = _userRepository.Get(userId);

            if (userDto == null)
            {
                throw new ObjectNotFoundException();
            }

            userDto.Name               = name ?? userDto.Name;
            userDto.Email              = email ?? userDto.Email;
            userDto.Password           = password ?? userDto.Password;
            userDto.RegistrationStatus = registrationStatus ?? userDto.RegistrationStatus;
            userDto.UserType           = userType ?? userDto.UserType;
            userDto.PhoneNumber        = phoneNumber ?? userDto.PhoneNumber;

            _userRepository.Update(userDto);

            if (userDto.UserType == null && userType != null)
            {
                _permissionRepository.AddUserPermissions(userId, userType);
            }
        }