private async Task <Result <AccountEntity> > AddAccountAsync(AccountModel account) { if (await _accountStorage.GetByEmailAsync(account.Email) != null) { return(new Result <AccountEntity>(ResultCode.EmailAlreadyExist)); } if (await _accountStorage.GetByLoginAsync(account.Login) != null) { return(new Result <AccountEntity>(ResultCode.LoginAlreadyExist)); } var accountEntity = _mapper.Map <AccountModel, AccountEntity>(account); await _accountStorage.AddAsync(accountEntity); return(new Result <AccountEntity>(accountEntity)); }
public async Task <Result <AccountModel> > LoginAsync(string login, string password) { var user = await _accountStorage.GetByLoginAsync(login); if (user == null) { return(new Result <AccountModel>(ResultCode.InvalidLogin)); } if (user.IsBlocked) { return(new Result <AccountModel>(ResultCode.UserBlocked)); } var passwordIsValid = PasswordHash.ValidatePassword(password, user.PasswordHash); return(!passwordIsValid ? new Result <AccountModel>(ResultCode.InvalidPassword) : new Result <AccountModel>(_mapper.Map <AccountEntity, AccountModel>(user))); }