public async Task <IActionResult> Post([FromBody] RegisterRequest request) { RegisterOutput output = await _registerUseCase.Execute(request.Personnummer, request.Name, request.InitialAmount); _presenter.Populate(output); return(_presenter.ViewModel); }
public async Task Execute(RegisterInput input) { if (input == null) { _outputHandler.Error("Input is null."); return; } var customer = _entityFactory.NewCustomer(input.SSN, input.Name); var account = _entityFactory.NewAccount(customer); ICredit credit = account.Deposit(_entityFactory, input.InitialAmount); if (credit == null) { _outputHandler.Error("An error happened when depositing the amount."); return; } customer.Register(account); await _customerRepository.Add(customer); await _accountRepository.Add(account, credit); await _unitOfWork.Save(); RegisterOutput output = new RegisterOutput(customer, account); _outputHandler.Standard(output); }
public void GivenValidData_Handle_WritesOkObjectResult() { var customer = new Infrastructure.InMemoryDataAccess.Customer( new CustomerId(Guid.NewGuid()), new SSN("198608178888"), new Name("Ivan Paulovich"), Array.Empty <AccountId>()); var account = new Infrastructure.InMemoryDataAccess.Account( new AccountId(Guid.NewGuid()), customer.Id, Array.Empty <Infrastructure.InMemoryDataAccess.Credit>(), Array.Empty <Infrastructure.InMemoryDataAccess.Debit>() ); var registerOutput = new RegisterOutput( new ExternalUserId("github/ivanpaulovich"), customer, account); var sut = new RegisterPresenter(); sut.Standard(registerOutput); var actual = Assert.IsType <CreatedAtRouteResult>(sut.ViewModel); Assert.Equal((int)HttpStatusCode.Created, actual.StatusCode); var actualValue = (RegisterResponse)actual.Value; Assert.Equal(customer.Id.ToGuid(), actualValue.CustomerId); }
public void GivenValidData_Handle_WritesOkObjectResult() { var customer = new Infrastructure.InMemoryGateway.Customer( new SSN("198608178888"), new Name("Ivan Paulovich") ); var account = new Infrastructure.InMemoryGateway.Account( customer ); var registerOutput = new RegisterOutput( customer, account ); var sut = new RegisterPresenter(); sut.Standard(registerOutput); var actual = Assert.IsType <CreatedAtRouteResult>(sut.ViewModel); Assert.Equal((int)HttpStatusCode.Created, actual.StatusCode); var actualValue = (RegisterResponse)actual.Value; Assert.Equal(customer.Id, actualValue.CustomerId); }
public void Standard(RegisterOutput output) { var transactions = new List <TransactionModel>(); foreach (var item in output.Account.Transactions) { var transaction = new TransactionModel( item.Amount, item.Description, item.TransactionDate); transactions.Add(transaction); } var account = new AccountDetailsModel( output.Account.AccountId, output.Account.CurrentBalance, transactions); var accounts = new List <AccountDetailsModel>(); accounts.Add(account); var registerResponse = new RegisterResponse( output.Customer.CustomerId, output.Customer.SSN, output.Customer.Name, accounts); this.ViewModel = new CreatedAtRouteResult( "GetCustomer", new { customerId = registerResponse.CustomerId, version = "1.0" }, registerResponse); }
private async Task <bool> VerifyCustomerAlreadyRegistered(IUser user) { if (!(user.CustomerId is { } customerId)) { return(false); } if (!await this._customerService .IsCustomerRegistered(customerId) .ConfigureAwait(false)) { return(false); } ICustomer existingCustomer = await this._customerRepository .GetBy(customerId) .ConfigureAwait(false); IList <IAccount> existingAccounts = await this._accountRepository .GetBy(customerId) .ConfigureAwait(false); var output = new RegisterOutput( user, existingCustomer, existingAccounts); this._registerOutputPort .HandleAlreadyRegisteredCustomer(output); return(true); }
public void Populate(RegisterOutput response) { if (response == null) { ViewModel = new NoContentResult(); return; } List <TransactionModel> transactions = new List <TransactionModel> (); foreach (var item in response.Account.Transactions) { var transaction = new TransactionModel( item.Amount, item.Description, item.TransactionDate); transactions.Add(transaction); } AccountDetailsModel account = new AccountDetailsModel(response.Account.AccountId, response.Account.CurrentBalance, transactions); List <AccountDetailsModel> accounts = new List <AccountDetailsModel> (); accounts.Add(account); CustomerModel model = new CustomerModel( response.Customer.CustomerId, response.Customer.Personnummer, response.Customer.Name, accounts ); ViewModel = new CreatedAtRouteResult("GetCustomer", new { customerId = model.CustomerId }, model); }
public void Populate(RegisterOutput response) { if (response == null) { ViewModel = new NoContentResult(); return; } ViewModel = new RedirectToActionResult("GetCustomer", "Customers", new { customerId = response.Customer.CustomerId }); }
/// <summary> /// When the customer already exists and we are returning from DB. /// </summary> /// <param name="output">Output.</param> public void HandleAlreadyRegisteredCustomer(RegisterOutput output) { var customerModel = new CustomerModel((Customer)output.Customer); var accountsModel = (from Account accountEntity in output.Accounts select new AccountModel(accountEntity)) .ToList(); var registerResponse = new RegisterResponse(customerModel, accountsModel); this.ViewModel = new OkObjectResult(registerResponse); }
private void BuildOutput( ExternalUserId externalUserId, ICustomer customer, IAccount account) { var output = new RegisterOutput( externalUserId, customer, account); this._outputPort.Standard(output); }
private void BuildOutput( IUser user, ICustomer customer, IList <IAccount> account) { var output = new RegisterOutput( user, customer, account); this._registerOutputPort .Standard(output); }
public async Task <ActionResult <RegisterOutput> > RegisterAsync([FromBody] RegisterApiModel model) { RegisterInput input = new RegisterInput(); input.Name = model.AccountID; input.Surname = model.AccountID; input.UserName = model.AccountID; input.Password = model.Password; input.TenantId = _AbpSession.TenantId; RegisterOutput output = await _AccountAppService.Register(input); return(output); }
public async Task <RegisterOutput> Register([FromBody] RegisterInput input) { var output = new RegisterOutput(); var createUserInput = _mapper.Map <CreateUserInput>(input); var user = await _userService.Create(createUserInput); if (user != null) { output.Token = GetAuthToken(user, DateTime.UtcNow.AddDays(30)); } return(output); }
/// <summary> /// </summary> /// <param name="output"></param> public void Standard(RegisterOutput output) { var customerModel = new CustomerModel((Customer)output.Customer); var accountsModel = (from Account accountEntity in output.Accounts select new AccountModel(accountEntity)) .ToList(); var registerResponse = new RegisterResponse(customerModel, accountsModel); this.ViewModel = new CreatedAtRouteResult( "GetCustomer", new { customerId = registerResponse.Customer.CustomerId, version = "1.0" }, registerResponse); }
private async Task <RegisterOutput> TryInsertUser(RegisterInput input) { var output = new RegisterOutput(); var userToAdd = _mapper.Map <ApplicationUser>(input); PasswordManager.CreatePasswordSaltAndHash(input.Password, out var passwordSalt, out var passwordHash); userToAdd.PasswordSalt = passwordSalt; userToAdd.PasswordHash = passwordHash; var userSaved = await UserRepository.AddAsync(userToAdd); await _userContext.SaveChangesAsync(); output.Result = RegisterOutputResult.Success; output.UserId = userSaved.Entity.Id; return(output); }
public async Task <IActionResult> Register(RegisterRequest request) { if (!ModelState.IsValid) { return(View()); } RegisterOutput output = await _registerUseCase.Execute( request.Personnummer, request.Name, request.InitialAmount); _presenter.Populate(output); return(_presenter.ViewModel); }
/// <summary> /// Executes the Use Case. /// </summary> /// <param name="input">Input Message.</param> /// <returns>Task.</returns> public async Task Execute(RegisterInput input) { if (input is null) { this._outputPort.WriteError(Messages.InputIsNull); return; } if (this._userService.GetCustomerId() is CustomerId customerId) { if (await this._customerService.IsCustomerRegistered(customerId) .ConfigureAwait(false)) { var existingCustomer = await this._customerRepository.GetBy(customerId) .ConfigureAwait(false); var existingAccount = await this._accountRepository.GetAccount(existingCustomer.Accounts.GetAccountIds().First()) .ConfigureAwait(false); var output = new RegisterOutput( this._userService.GetExternalUserId(), existingCustomer, existingAccount); this._outputPort.CustomerAlreadyRegistered(output); return; } } var customer = await this._customerService.CreateCustomer(input.SSN, this._userService.GetUserName()) .ConfigureAwait(false); var account = await this._accountService.OpenCheckingAccount(customer.Id, input.InitialAmount) .ConfigureAwait(false); var user = await this._securityService .CreateUserCredentials(customer.Id, this._userService.GetExternalUserId()) .ConfigureAwait(false); customer.Register(account.Id); await this._unitOfWork.Save() .ConfigureAwait(false); this.BuildOutput(this._userService.GetExternalUserId(), customer, account); }
public async Task Register_ValidValues_ShouldReturnACustomerWithAnAccount() { //ARRANGE string name = "Customer Name Test"; string pin = "0101010000"; double amount = 10; _customerWriteOnlyRepository.Setup(m => m.Add(It.IsAny <Customer>())).Returns(Task.CompletedTask); _accountWriteOnlyRepository.Setup(m => m.Add(It.IsAny <Account>(), It.IsAny <Credit>())).Returns(Task.CompletedTask); //ACT RegisterOutput outPut = await registerUseCase.Execute(pin, name, amount); //ASSERT _customerWriteOnlyRepository.Verify(v => v.Add(It.IsAny <Customer>()), Times.Once()); _accountWriteOnlyRepository.Verify(v => v.Add(It.IsAny <Account>(), It.IsAny <Credit>()), Times.Once()); Assert.Equal(outPut.Customer.Name, name); Assert.Equal(outPut.Account.CurrentBalance, amount); }
public async Task Execute(RegisterInput input) { var customer = _entityFactory.NewCustomer(input.SSN, input.Name); var account = _entityFactory.NewAccount(customer); var credit = account.Deposit(_entityFactory, input.InitialAmount); customer.Register(account); await _customerRepository.Add(customer); await _accountRepository.Add(account, credit); await _unitOfWork.Save(); var output = new RegisterOutput(customer, account); _outputHandler.Standard(output); }
public async void Register_Valid_User_Account(decimal amount) { string personnummer = "8608178888"; string name = "Ivan Paulovich"; var mockCustomerWriteOnlyRepository = new Mock <ICustomerWriteOnlyRepository>(); var mockAccountWriteOnlyRepository = new Mock <IAccountWriteOnlyRepository>(); RegisterUseCase sut = new RegisterUseCase( mockCustomerWriteOnlyRepository.Object, mockAccountWriteOnlyRepository.Object ); RegisterOutput output = await sut.Execute( personnummer, name, amount); Assert.Equal(amount, output.Account.CurrentBalance); }
public async Task Execute(RegisterInput input) { if (input == null) { _outputHandler.Error("Input is null."); return; } var customer = _entityFactory.NewCustomer(input.SSN, input.Name); var account = _entityFactory.NewAccount(customer); ICredit credit = account.Deposit(_entityFactory, input.InitialAmount); if (credit == null) { _outputHandler.Error("An error happened when depositing the amount."); return; } customer.Register(account); // Call to an external Web Api await _customerRepository.Add(customer); await _accountRepository.Add(account, credit); // Publish the event to the enterprice service bus await _serviceBus.PublishEventAsync(new RegistrationCompleted() { CustomerId = customer.Id, AccountId = account.Id, CreditId = credit.Id }); await _unitOfWork.Save(); RegisterOutput output = new RegisterOutput(customer, account); _outputHandler.Standard(output); }
public async Task <RegisterOutput> FirstTimeLoginAsync(RegisterEmployeeInput input) { User user; try { user = await _userManager.FindByEmployeeNumberAsync(input.EmployeeNumber); } catch (InvalidOperationException) { string userNotFoundErrorMessage = $"Usuario {input.EmployeeNumber} no encontrado"; Logger.Error(userNotFoundErrorMessage); return(new RegisterOutput { CanLogin = false, HasErrors = true, Errors = new List <string> { userNotFoundErrorMessage } }); } IdentityResult changePasswordIdentityResult = await _userManager.ChangePasswordAsync(user, input.Password); IdentityResult setEmailIdentityResult = await _userManager.SetEmailAsync(user, input.Email); RegisterOutput output = new RegisterOutput(); if (!changePasswordIdentityResult.Succeeded || !setEmailIdentityResult.Succeeded) { output.HasErrors = true; output.CanLogin = false; output.Errors = changePasswordIdentityResult.Errors.Select(error => error.Description) .Concat(setEmailIdentityResult.Errors.Select(error => error.Description)).ToList(); } else { user.IsEmailConfirmed = true; } return(output); }
/// <summary> /// </summary> /// <param name="output"></param> public void HandleAlreadyRegisteredCustomer(RegisterOutput output) => this.AlreadyRegistered.Add(output);
public void Populate(RegisterOutput response) { throw new System.Exception("Populate Register PResnter"); }
public void Standard(RegisterOutput output) { this.Registers.Add(output); }
private void BuildOutput(string token, IAccount account, ApplicationUser applicationUser) { var output = new RegisterOutput(token, account, applicationUser); outputPort.Output(output); }
public Presenter(RegisterOutput output) { AssociatedTodos = output.UserOutput.AssociatedTodos.GetReadOnly(); Name = (string)output.UserOutput.Name; }
public void BuildOutput(ICustomer customer, IAccount account) { var output = new RegisterOutput(customer, account); _outputPort.Standard(output); }
public void Output(RegisterOutput output) { var res = new RegisterResponse(output.Token, output.Account.Id.ToGuid()); ViewModel = new OkObjectResult(res); }
public async Task <RegisterOutput> VerificationUserResetPasswprd(ResetPasswordDto input) { var result = new RegisterOutput(); try { if (!input.NewPassword.Equals(input.ConfirmPassword)) { result.CanLogin = false; result.RegisterMessage = "New password and confirm password not match."; return(result); } long userId = 0; try { userId = Convert.ToInt32(await _encryptionDecryptionService.DecryptString(input.UserKey)); } catch (Exception ex) { result.CanLogin = false; result.RegisterMessage = "Invalid request."; return(result); } var user = await _userManager.GetUserByIdAsync(userId); if (user == null) { // Don't reveal that the user does not exist result.CanLogin = false; result.RegisterMessage = "Invalid request."; return(result); } var applicationUser = await _applicationUserReposatory.GetAll().FirstOrDefaultAsync(x => x.UserId == user.Id); if (applicationUser == null) { // Don't reveal that the user does not exist result.CanLogin = false; result.RegisterMessage = "Invalid request."; return(result); } //add logic to check password history table and manage user password history CheckErrors(await _userManager.ResetPasswordAsync(user, input.Token.Replace(' ', '+'), input.NewPassword)); //update application and user state applicationUser.IsActive = true; applicationUser.IsPasswordCreated = true; await _applicationUserReposatory.UpdateAsync(applicationUser); //add user role that can access the general user content //TDDO await CurrentUnitOfWork.SaveChangesAsync(); var isEmailConfirmationRequiredForLogin = await SettingManager.GetSettingValueAsync <bool>(AbpZeroSettingNames.UserManagement.IsEmailConfirmationRequiredForLogin); result.CanLogin = user.IsActive && (user.IsEmailConfirmed || !isEmailConfirmationRequiredForLogin); result.RegisterMessage = "Your password successfully changed. Now you can login with your new credentials."; return(result); } catch (Exception ex) { result.CanLogin = false; result.RegisterMessage = ex.Message; return(result); } }