Ejemplo n.º 1
0
        public User Createuser(string userName, string fullName, string password, string email, int[] roles)
        {
            var existingUser = _userRepository.GetSingleByUserName(userName);

            if (null != existingUser)
            {
                throw (new Exception("User already exists"));
            }

            var passwordSalt = _encryptionService.CreateSalt();
            // add user
            var user = new User()
            {
                DateCreated    = DateTime.Now,
                Email          = email,
                FullName       = fullName,
                HashedPassword = _encryptionService.EncryptPassword(password, passwordSalt),
                IsLocked       = false,
                PasswordSalt   = passwordSalt,
                UserName       = userName
            };

            _unitOfWork.Commit();

            foreach (var roleId in roles)
            {
                AddRoleToUser(user, roleId);
            }
            _unitOfWork.Commit();

            return(user);
        }