예제 #1
0
        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));
        }
예제 #2
0
        public async Task <IActionResult> Post(CreateBankAccountRequest request)
        {
            if (request == null)
            {
                return(BadRequest());
            }

            await _bankAccountService.CreateNewBankAccount(request);

            return(Ok());
        }
예제 #3
0
        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);
        }
예제 #4
0
        /// <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);
        }
예제 #5
0
 public async Task <IActionResult> Post([FromBody] CreateBankAccountRequest request)
 => (await _mediator.Send(new CreateBankAccountCommand(request.Owner, _contextAccessor.CorrelationId)))
 .PipeTo(accountId => Created("api/Queries/Info", accountId));
예제 #6
0
 public async Task CreateNewBankAccount(CreateBankAccountRequest request)
 {
     var command = new CreateNewBankAccountCommand(request.BankId,
                                                   request.AccountNumber, request.CustomerName, request.InitialBalance);
     await _bus.SendCommand(command);
 }
예제 #7
0
        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));
            }
        }