public async Task <AccountDetailsDTO> GetAccount(GetAccountDTO getAccount) { try { var getCustomerAccount = await _context.Accounts.Where(c => c.CustomerId == getAccount.CustomerId && c.AccountCategory.Name == getAccount.AccountTypeName && c.Bank.BankName == getAccount.BankName).Select(c => new AccountDetailsDTO { AccountName = c.AccountName, AccountBalance = c.AccountBalance.ToString("c"), AccountNo = c.AccountNo, AccountStatus = c.AccountStatus, AccountCategoryName = c.AccountCategory.Name, BankName = c.Bank.BankName, CustomerId = c.CustomerId, DateCreated = c.DateCreated.ToShortDateString() }).SingleOrDefaultAsync(); if (getCustomerAccount == null) { return(null); } else { return(getCustomerAccount); } } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> GetCustomerAccountAsync([FromBody] GetAccountDTO getAccount) { var result = await _account.GetAccount(getAccount); if (result == null) { return(NotFound($"The customer does not have a {getAccount.AccountTypeName} Account")); } else { return(Ok(result)); } }
public IActionResult GetAccount([FromQuery] int accountId) { try { GetAccountDTO account = _accountService.GetAccountById(accountId); return(Ok(account)); } catch (APIException ex) { ErrorMessage errorMessage = new ErrorMessage { message = ex.Message }; return(StatusCode(ex.StatusCode, errorMessage)); } }
public IActionResult TopUpAccount(int destinationId, Double sumToTransfer) { try { GetAccountDTO account = _accountService.TopUpAccount(destinationId, sumToTransfer); return(Ok(account)); } catch (APIException ex) { ErrorMessage errorMessage = new ErrorMessage { message = ex.Message }; return(StatusCode(ex.StatusCode, errorMessage)); } }