public async Task Handle(Guid ownerId, long fromAccountId, long toAccountId, decimal transactionAmount, string comment) { if (fromAccountId == toAccountId) { throw new Exception("The source and destination accounts cannot be the same"); } AccountDTO fromAccount = await _accountsService.GetAccountById(fromAccountId); AccountDTO toAccount = await _accountsService.GetAccountById(toAccountId); if (!fromAccount.Owner_id.Equals(ownerId)) { throw new Exception("The source account is not yours!"); } if (fromAccount.closed || toAccount.closed) { throw new Exception("Cannot make transactions with closed accounts!"); } if (fromAccount.Amount - transactionAmount >= 0) { await _accountsService.MakeTransaction(fromAccountId, toAccountId, transactionAmount, comment); } else { throw new Exception("Account balance is not enough to make this transaction!"); } }
public async Task <bool> IsOwner(Guid id, string nameIdentifier) { var @event = await _unitOfWork.Events.GetByIdAsync(id); @event.Account = await _accountsService.GetAccountById(@event.AccountId); if (@event.Account.NameIdentifier == nameIdentifier) { return(true); } return(false); }
public async Task <AccountDTO> HandleGetAccountById(Guid ownerId, long id) { AccountDTO acc = await _accountsService.GetAccountById(id); if (acc.Owner_id != ownerId) { throw new Exception("Not your account"); } return(acc); }
public async Task <List <TransactionDTO> > HandleGet(long accountId, Guid ownerId) { AccountDTO account = await _accountsService.GetAccountById(accountId); if (!account.Owner_id.Equals(ownerId)) { throw new Exception("The account you requesting transactions history is not yours!"); } List <TransactionDTO> res = await _accountsService.GetTransactionsByAccountId(accountId); return(res); }
public async Task <AccountDTO> Handle(long id, Guid ownerId) { AccountDTO accountForClose = await _accountsService.GetAccountById(id); if (!accountForClose.Owner_id.Equals(ownerId)) { throw new Exception("The account you are trying to close is not yours!"); } if (Math.Abs(accountForClose.Amount) == 0) { return(await _accountsService.CloseAccount(id, ownerId)); } else { throw new Exception("Your account is not empty or you have debt on this account!"); } }
public async Task <Account> GetAccount([FromUri] string email = null, [FromUri] string id = null) { var account = new Account(); if (email.IsNullOrWhiteSpace() && id.IsNullOrWhiteSpace()) { throw new ArgumentNullException(nameof(email)); } if (email != null) { return(await _accountsService.GetAccountByEmail(email)); } var userIdAsGuid = Guid.Parse(id); return(await _accountsService.GetAccountById(userIdAsGuid)); }
public async Task <AccountDetail> GetAccountById(int id) { return(await _accountsService.GetAccountById(id)); }
public async Task <ActionResult <AccountResponse> > GetAccountById(Guid id) { var rs = await _accountService.GetAccountById(id); return(Ok(rs)); }