Exemplo n.º 1
0
        public void AddNewUser(UserRequest userRequest)
        {
            //Check if User already registered with same User-Id

            var user = _dataAccess.GetLoggedInUser(userRequest.UserId);

            if (user != null)
            {
                throw new DuplicateNameException("Customer already registered with this email-id");
            }


            var salt     = Guid.NewGuid();
            var userRole = _dataAccess.GetUserRole(userRequest.UserRole);

            var passCrypto   = new PasswordCryptography();
            var passwordHash = passCrypto.GetPasswordHash(salt, userRequest.Password);



            var newUser = new user()
            {
                UserId       = userRequest.UserId,
                UserRoleID   = userRole.UserRoleID,
                AddeddOn     = DateTime.Now,
                IsActive     = true,
                Salt         = salt.ToString(),
                PasswordHash = passwordHash,
                FirstName    = userRequest.FirstName,
                LastName     = userRequest.LastName,
                CustomerId   = userRequest.CustomerId,
                userrole     = userRole
            };

            _dataAccess.AddNewUser(newUser);
        }