public IHttpActionResult Create([FromBody] CreateBankAccountRequest request) { var customer = _repositorywrapper.Customers.GetCustomerById(request.CustomerId); if (customer == null) { return(BadRequest("Theres no Customer with that Id")); } var accountType = _repositorywrapper.BankAccount.GetAccountTypeByName(request.AccountType); var newAccount = _repositorywrapper.BankAccount.CreateBankAccount(new BankAccount { Balance = 0, AccountNumber = _repositorywrapper.BankAccount.CreateAccountNumber(), ClearingNumber = _repositorywrapper.BankAccountService.ReturnClearingNumber(), CustomerId = customer.Id, IBANNumber = _repositorywrapper.BankAccount.CreateIBANNumber(), AccountTypeId = accountType.Id }); var response = CreatedBankAccountResponse.CreatedResponse(customer, newAccount); return(Json(response)); }
public async Task <IActionResult> Post(CreateBankAccountRequest request) { if (request == null) { return(BadRequest()); } await _bankAccountService.CreateNewBankAccount(request); return(Ok()); }
private BankAccount CreateBankAccount(CreateBankAccountRequest request) { var newBankAccount = new BankAccount() { AccountNo = Guid.NewGuid().ToString(), IBAN = request.IBAN, CustomerId = request.CustomerId, BranchId = request.BranchId, Balance = request.Balance, AllowedBalanceToUse = request.Balance, CurrencyId = request.CurrencyId, Type = request.Type, CreatedBy = _httpContextAccessor.HttpContext.User.Identity.Name }; return(newBankAccount); }
/// <summary> /// Add or Edit bank account /// </summary> /// <param name="accountId"></param> /// <param name="request"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <Response> AddOrEditBankAccountAsync(int accountId, CreateBankAccountRequest request, CancellationToken cancellationToken = default) { var responseModel = new Response(); if (accountId > 0) { var bankaccount = await _bankAccountRepo.FindByIdAsync(accountId); if (bankaccount != null) { bankaccount.IBAN = request.IBAN; bankaccount.CurrencyId = request.CurrencyId; bankaccount.Balance = request.Balance; bankaccount.Type = request.Type; bankaccount.LastModifiedBy = _httpContextAccessor.HttpContext.User.Identity.Name; bankaccount.LastModifiedOn = DateTime.UtcNow; await _bankAccountRepo.UpdateAsync(bankaccount); } else { responseModel.AddError(ExceptionCreator.CreateNotFoundError("bankAccount", $"bank account Not found")); return(responseModel); } } else { try { var newBankAccount = CreateBankAccount(request); await _bankAccountRepo.AddAsync(newBankAccount); } catch (Exception ex) { responseModel.AddError(ExceptionCreator.CreateInternalServerError(ex.ToString())); } } return(responseModel); }
public async Task <IActionResult> Post([FromBody] CreateBankAccountRequest request) => (await _mediator.Send(new CreateBankAccountCommand(request.Owner, _contextAccessor.CorrelationId))) .PipeTo(accountId => Created("api/Queries/Info", accountId));
public async Task CreateNewBankAccount(CreateBankAccountRequest request) { var command = new CreateNewBankAccountCommand(request.BankId, request.AccountNumber, request.CustomerName, request.InitialBalance); await _bus.SendCommand(command); }
public async Task <IActionResult> AddOrEditBankAccount([FromRoute] int accountId, [FromBody] CreateBankAccountRequest request, CancellationToken cancellationToken = default) { try { var apiResponse = await _bankAccountService.AddOrEditBankAccountAsync(accountId, request, cancellationToken); if (apiResponse.Success) { return(Ok(apiResponse)); } else if (apiResponse.Errors[0].Code == StatusCodes.Status404NotFound) { return(NotFound(apiResponse)); } return(BadRequest(apiResponse)); } catch (Exception exception) { return(_actionResultMapper.Map(exception)); } }