示例#1
0
        public async Task <bool> AddUserAsync(User user)
        {
            var loginTest = await dbContext.Users.FirstOrDefaultAsync(t => t.Email == user.Email);

            if (loginTest != null)
            {
                return(false);
            }

            user.Salt     = hashService.CreatedSalt();
            user.Password = hashService.HashPassword(user.Password, user.Salt);

            await dbContext.Users.AddAsync(user);

            return(true);
        }
        public async Task <bool> AddUserAsync(User user)
        {
            var userEmail = await _userRepository.GetUserByEmail(user.Email);

            var userLogin = await _userRepository.GetUserByName(user.Login);

            if (userLogin != null || userEmail != null)
            {
                return(false);
            }

            user.Salt     = _hashService.CreatedSalt();
            user.Password = _hashService.HashPassword(user.Password, user.Salt);

            await _userRepository.AddUserAsync(user);

            return(await _userRepository.SaveChanges());
        }