public async Task <BaseDTO <bool> > Withdraw(int accountId, float amount) { var result = new BaseDTO <bool>(); var account = await _accountRepository.GetById(accountId); if (account == null) { result.AddError($"Account {accountId} not found"); return(result); } if (amount > account.Balance) { result.AddError("Insufficient balance."); return(result); } var accountType = await _accountTypeRepository.GetById(account.AccountTypeId); if (accountType.Type == AccountTypeEnum.DepositAccount) { if ((DateTime.UtcNow.Date - account.DateCreated.Date).TotalDays < accountType.DepositPeriodInDays) { result.AddError("Withdraw can be made only at maturity."); return(result); } } account.Balance -= amount; result.Data = await _accountRepository.Update(account); return(result); }
public async Task <BaseDTO <ClientDTO> > GetById(int id) { var result = new BaseDTO <ClientDTO>(); var client = await _clientRepository.GetById(id); if (client == null) { result.AddError($"Client with id {id} not found."); return(result); } result.Data = client.Map(); return(result); }
public async Task <BaseDTO <bool> > Deposit(int accountId, float amount) { var result = new BaseDTO <bool>(); var account = await _accountRepository.GetById(accountId); if (account == null) { result.AddError($"Account {accountId} not found"); return(result); } account.Balance += amount; result.Data = await _accountRepository.Update(account); return(result); }