public void Transfer(AccountTransferDto accountTransfer) { var createTransferCommand = new CreateTransferCommand( accountTransfer.FromAccount, accountTransfer.ToAccount, accountTransfer.TransferAmount); _bus.SendCommand(createTransferCommand); }
public IActionResult TransferAsync(AccountTransferDto account) { //BackgroundJob.Enqueue(() => _account.TransferMoney(account)); //_hubContext.Clients.All.SendAsync("getAllDebitTransaction"); var result = _account.TransferMoney(account); if (result == $"{account.Amount.ToString("c")} was successfully transferred to {account.DestinationAccount}; Thank you for banking with us") { return(Ok(result)); } return(BadRequest(result)); }
public async Task Transfer(AccountTransferDto accountTransfer) { var result1 = await AuthorizationService.AuthorizeAsync(BankingPermissions.Accounts.Default); var result2 = await AuthorizationService.AuthorizeAsync(BankingPermissions.Accounts.Create); var result3 = await AuthorizationService.AuthorizeAsync(BankingPermissions.Accounts.Update); var result4 = await AuthorizationService.AuthorizeAsync(BankingPermissions.Accounts.Delete); var result5 = await AuthorizationService.AuthorizeAsync(BankingPermissions.Accounts.Transfer); var user = CurrentUser; var userRoles = CurrentUser.FindClaims(AbpClaimTypes.Role); var createTransferCommand = ObjectMapper.Map <AccountTransferDto, CreateTransferCommand>(accountTransfer); await _bus.SendCommand(createTransferCommand); }
public string TransferMoney(AccountTransferDto transfer) { try { var account = _context.AccountTransactions.Where(c => c.AccountNo == transfer.AccountNo).SingleOrDefault(); var accountss = _context.Accounts.Where(c => c.AccountNo == transfer.AccountNo).SingleOrDefault(); var destAccount = _context.Accounts.Where(c => c.AccountNo == transfer.DestinationAccount).SingleOrDefault(); var sourceAccountName = _context.Accounts.Where(c => c.AccountNo == transfer.AccountNo).Select(c => c.Bank.BankName).FirstOrDefault(); var destinationAccountName = _context.Accounts.Where(c => c.AccountNo == transfer.DestinationAccount).Select(c => c.Bank.BankName).FirstOrDefault(); if (transfer.Amount > account.Balance) { return("Insufficient Funds"); } if (transfer.Pin != account.Pin) { return("Invalid Pin code"); } if (sourceAccountName != destinationAccountName) { if (account.AccountNo == transfer.AccountNo && destAccount.AccountNo == transfer.DestinationAccount && transfer.Pin == account.Pin) { account.Balance -= transfer.Amount; accountss.AccountBalance -= transfer.Amount; destAccount.AccountBalance += transfer.Amount; decimal transferCharge = 65.0M; var intertransaction = new Transaction { TransactionDate = DateTime.Now, Amount = transfer.Amount, DestinationAccountName = destAccount.AccountName, SourceAccountNo = transfer.AccountNo, SourceAccountName = account.AccountName, DestinationAccountNo = destAccount.AccountNo, DestinationAccountType = _context.AccountCategories.Where(c => c.AccountCategoryId == destAccount.AccountCategoryId).Select(c => c.Name).SingleOrDefault(), SourceAccountType = _context.AccountCategories.Where(c => c.AccountCategoryId == account.AccountCategoryId).Select(c => c.Name).SingleOrDefault(), TotalAmount = transfer.Amount + transferCharge, Charge = transferCharge, TransactionReference = Guid.NewGuid().ToString(), TransactionStatus = "Successful", IsSuccessful = true, IsFalied = false, SenderCustomerId = _context.Accounts.Where(c => c.AccountNo == transfer.AccountNo).Select(c => c.CustomerId).SingleOrDefault(), RecieverCustomerId = _context.Accounts.Where(c => c.AccountNo == transfer.DestinationAccount).Select(c => c.CustomerId).SingleOrDefault(), SourceBankName = _context.Accounts.Where(c => c.AccountNo == account.AccountNo).Select(c => c.Bank.BankName).FirstOrDefault(), DestinationBankName = _context.Accounts.Where(c => c.AccountNo == destAccount.AccountNo).Select(c => c.Bank.BankName).FirstOrDefault() }; _context.Transactions.Add(intertransaction); } } if (sourceAccountName == destinationAccountName) { if (account.AccountNo == transfer.AccountNo && destAccount.AccountNo == transfer.DestinationAccount && transfer.Pin == account.Pin) { account.Balance -= transfer.Amount; accountss.AccountBalance -= transfer.Amount; destAccount.AccountBalance += transfer.Amount; var intratransactions = new Transaction { TransactionDate = DateTime.Now, Amount = transfer.Amount, DestinationAccountName = destAccount.AccountName, SourceAccountNo = transfer.AccountNo, SourceAccountName = account.AccountName, DestinationAccountNo = destAccount.AccountNo, DestinationAccountType = _context.AccountCategories.Where(c => c.AccountCategoryId == destAccount.AccountCategoryId).Select(c => c.Name).SingleOrDefault(), SourceAccountType = _context.AccountCategories.Where(c => c.AccountCategoryId == account.AccountCategoryId).Select(c => c.Name).SingleOrDefault(), TotalAmount = transfer.Amount, TransactionReference = Guid.NewGuid().ToString(), TransactionStatus = "Successful", IsSuccessful = true, IsFalied = false, SenderCustomerId = _context.Accounts.Where(c => c.AccountNo == transfer.AccountNo).Select(c => c.CustomerId).SingleOrDefault(), RecieverCustomerId = _context.Accounts.Where(c => c.AccountNo == transfer.DestinationAccount).Select(c => c.CustomerId).SingleOrDefault(), SourceBankName = _context.Accounts.Where(c => c.AccountNo == account.AccountNo).Select(c => c.Bank.BankName).FirstOrDefault(), DestinationBankName = _context.Accounts.Where(c => c.AccountNo == destAccount.AccountNo).Select(c => c.Bank.BankName).FirstOrDefault() }; _context.Transactions.Add(intratransactions); } } _context.SaveChanges(); return($"{transfer.Amount.ToString("c")} was successfully transferred to {transfer.DestinationAccount}; Thank you for banking with us"); } catch (Exception ex) { return(ex.Message); throw ex; } }
public IActionResult Post([FromBody] AccountTransferDto accountTransfer) { _accountService.Transfer(accountTransfer); return(Ok(accountTransfer)); }
/// <summary> /// Создание DTO ответа по результату транзакции между двумя сччетами для передачи во внешние системы /// </summary> /// <param name="result">DTO для передачи счетов</param> /// <returns>DTO успешного ответа</returns> public ResponseOkDto <AccountTransferDto> FormResponseForCreateEntrySolo(AccountTransferDto result) => new ResponseOkDto <AccountTransferDto> { Status = "Ok", Result = result };
/// <summary> /// Добавление записи об изменении счета /// </summary> /// <param name="account">DTO счета</param> /// <param name="operationId">Id операции</param> /// <param name="amount">Сумма изменения по счету</param> /// <param name="isTopUp">Проверка действмя</param> /// <param name="dueDate">Дата влияния на счет</param> /// <param name="description">Описание</param> /// <param name="accountPresent">Нужно ли создавать счет</param> /// <returns></returns> public async Task <ResponseBaseDto> FormAccountEntryResponse(AccountDto account, Guid operationId, decimal amount, bool isTopUp, DateTimeOffset dueDate, string description, bool accountPresent) { var helperListForAccounts = new List <AccountModel>(); var initialBalance = account.Balance; var balance = new decimal(); AccountHistoryModel entry; if (isTopUp) { balance = _helper.TopUpBalance(initialBalance, amount); } else { if (_helper.ValidateAmmount(initialBalance, amount)) { return(_helper.FormMessageResponse(_errorStatus, _message)); } else { balance = _helper.WithDrawlBalance(initialBalance, amount); } } if (accountPresent) { helperListForAccounts.Add(_helper.entryForUpdate(account, balance)); } else { account.Id = await _helper.SaveAccount(account, balance); } if (isTopUp) { entry = new AccountHistoryModel(Guid.Empty, account.Id, amount, balance, dueDate, operationId, description); } else { entry = new AccountHistoryModel(account.Id, amount, balance, dueDate, description, operationId); } await _accountsHistoryRepository.AddEntry(entry); if (helperListForAccounts.Count != 0) { _accountRepository.Update(helperListForAccounts); } if (await _accountsHistoryRepository.SaveChangesAsync() == 0) { throw new ApplicationException(); } var result = new AccountTransferDto { AccountId = account.Id, CurrentBalance = balance }; return(_helper.FormResponseForCreateEntrySolo(result)); }