예제 #1
0
        /// <summary>
        /// Retrieve customer by account number
        /// </summary>
        /// <param name="accountNo"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <ApiResponse <CustomerResponse> > GetCustomerByAccountNoAsync(string accountNo, CancellationToken cancellationToken = default)
        {
            var responseModel = new ApiResponse <CustomerResponse>();

            var bankAccount = await _bankAccountRepo.FindByAccountNoAsync(accountNo);

            if (bankAccount == null)
            {
                responseModel.AddError(ExceptionCreator.CreateNotFoundError(nameof(bankAccount), $"bank Account of No: {accountNo} not found"));
                return(responseModel);
            }

            var customer = await _customerRepo.FindByAccountNoAsync(accountNo);

            if (customer == null)
            {
                responseModel.AddError(ExceptionCreator.CreateNotFoundError(nameof(customer), $"bank Account's holder of account No: {accountNo} not found"));
                return(responseModel);
            }

            var address = await _addressRepo.FindByIdAsync(customer.AddressId);


            responseModel.Data = CreateCustomerResponse(customer, address);

            return(responseModel);
        }
예제 #2
0
        /// <summary>
        /// Retrieve bank account for the specified account number
        /// </summary>
        /// <param name="accountNo"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <ApiResponse <BankAccountResponse> > GetBankAccountByAccountNoAsync(string accountNo, CancellationToken cancellationToken = default)
        {
            var responseModel = new ApiResponse <BankAccountResponse>();

            var bankAccount = await _bankAccountRepo.FindByAccountNoAsync(accountNo);

            if (bankAccount == null)
            {
                responseModel.AddError(ExceptionCreator.CreateNotFoundError(nameof(bankAccount), $"bank account No: {accountNo} Not found"));

                return(responseModel);
            }

            var accountOwner    = CreateBankAccountOwner(bankAccount);
            var lastTransaction = await _cashTransactionsRepo.GetLastAsync(bankAccount.IBAN);

            responseModel.Data = CreateBankAccountResponse(bankAccount, accountOwner, lastTransaction.CreatedAt);

            return(responseModel);
        }