public async Task Add(AccountToCreateDto accountToCreateDto) { var accountToCreate = new Account { CustomerId = accountToCreateDto.CustomerId.Value, Name = accountToCreateDto.Name }; var createdAccount = await accountDataAccess.Add(accountToCreate); if (accountToCreateDto.InitialCredit > 0) { var transactionRequest = new TransactionRequest { AccountId = createdAccount.Id, Amount = accountToCreateDto.InitialCredit }; await transactionClient.Post(transactionRequest); } }
public async Task <AccountModel> Create(AccountToCreateDto accountToCreate) { var account = new AccountModel { CustomerId = accountToCreate.CustomerId, Name = accountToCreate.Name, Created = DateTime.UtcNow, }; await this.dataContext.Accounts.AddAsync(account); var success = await this.dataContext.SaveChangesAsync() > 0; if (!success) { throw new Exception("Problem saving changes"); } return(account); }
public async Task Add() { var accountCoreMoq = new Mock <IAccountCore>(); var controller = new AccountController(accountCoreMoq.Object); var accountToCreateDto = new AccountToCreateDto() { CustomerId = Guid.NewGuid(), InitialCredit = 300.00m, Name = "Savings01" }; accountCoreMoq.Setup(x => x.Add(accountToCreateDto)).Returns(async() => await Task.CompletedTask ); var result = await controller.Add(accountToCreateDto); Assert.NotNull(result); Assert.That((result is OkResult)); }
public async Task <ActionResult> Add([FromBody] AccountToCreateDto accountToCreateDto) { await this.accountCore.Add(accountToCreateDto); return(Ok()); }