public async Task <IResult <AuthEntity> > AddAsync(AuthModel authModel) { var validation = new AuthModelValidator().Validate(authModel); if (validation.Failed) { return(Result <AuthEntity> .Fail(validation.Message)); } if (await _authRepository.AnyByLoginAsync(authModel.Login)) { return(Result <AuthEntity> .Fail(Texts.AuthError)); } var authEntity = AuthFactory.Create(authModel); var password = _hashService.Create(authEntity.Password, authEntity.Salt); authEntity.ChangePassword(password); await _authRepository.AddAsync(authEntity); return(Result <AuthEntity> .Success(authEntity)); }
public async Task <IResult <Auth> > AddAsync(AuthModel model) { var validation = await new AuthModelValidator().ValidateAsync(model); if (validation.Failed) { return(Result <Auth> .Fail(validation.Message)); } if (await _authRepository.AnyByLoginAsync(model.Login)) { return(Result <Auth> .Fail(Texts.LoginAlreadyExists)); } var auth = AuthFactory.Create(model); var password = _hashService.Create(auth.Password, auth.Salt); auth.ChangePassword(password); await _authRepository.AddAsync(auth); return(Result <Auth> .Success(auth)); }