public async Task Execute(IAccountRepository accountRepository) { var checksum = NumberAccountHelper.GetChecksum(_transferModel.AccountFrom); var number = NumberAccountHelper.GetNumberAccount(_transferModel.AccountFrom); var accountFrom = await accountRepository.GetAccountByNumberAndCheckSumAsync(checksum, number); accountFrom.Balance -= _transferModel.GetAmount; /* * przed wysłaniem transferu do innego banku zapisanie stanu konta * (operaja może się nie udać, wówczas transfer do innego banku nie zostanie zrealizowany) * w przypadku wystąpienia problemów w innym banku operacja zostanie wycofana przez transakcję */ await Save(accountRepository, accountFrom); if (NumberAccountHelper.IsAccountInMyBank(_transferModel.AccountTo)) { var transferReceiver = new TransferReceiveOperationCommand(_transferModel); await transferReceiver.Execute(accountRepository); } else { await SendTransferToAnotherBank(); } }
public async Task Execute(IAccountRepository accountRepository) { var checksum = NumberAccountHelper.GetChecksum(_transferModel.AccountTo); var number = NumberAccountHelper.GetNumberAccount(_transferModel.AccountTo); var accountTo = await accountRepository.GetAccountByNumberAndCheckSumAsync(checksum, number); accountTo.Balance += _transferModel.GetAmount; await Save(accountRepository, accountTo); }
public async Task Execute(IAccountRepository accountRepository) { var checksum = NumberAccountHelper.GetChecksum(_accountTo); var number = NumberAccountHelper.GetNumberAccount(_accountTo); var account = await accountRepository.GetAccountByNumberAndCheckSumAsync(checksum, number); var value = (decimal)_amount / 100; account.Balance += value; await Save(accountRepository, account); }
public async Task <HistoryOfAccountModel> GetHistoryOfAccount(string token, string account, int currentPage, int sizePage) { var checksum = NumberAccountHelper.GetChecksum(account); var number = NumberAccountHelper.GetNumberAccount(account); var operationsDb = await _accountRepository.OperationRepository.GetOperationsOfAccountAsync(checksum, number, currentPage, sizePage); var enumerable = operationsDb as IList <BaseOperation> ?? operationsDb.ToList(); if (operationsDb == null || !enumerable.Any()) { throw new FaultException("Account hasn't any operations."); } var operations = new List <OperationModel>(); foreach (var operation in enumerable) { var operationModel = new OperationModel(); operationModel.Balance = (double)operation.Balance; operationModel.Amount = (double)operation.Amount; operationModel.Date = operation.Date; if (operation is TransferReceiveOperation) { operationModel.Name = (operation as TransferReceiveOperation).Title; operationModel.Details = $"Source account: {NumberAccountHelper.FormatNumber((operation as TransferReceiveOperation).Source)}"; } if (operation is TransferSendOperation) { operationModel.Name = (operation as TransferSendOperation).Title; operationModel.Details = $"Destination account: {NumberAccountHelper.FormatNumber((operation as TransferSendOperation).Destination)}"; } if (operation is PayOutOperation) { operationModel.Details = (operation as PayOutOperation).Name; } if (operation is PayInOperation) { operationModel.Details = (operation as PayInOperation).Name; } if (operation is BankChargeOperation) { operationModel.Details = (operation as BankChargeOperation).Name; } operations.Add(operationModel); } var result = new HistoryOfAccountModel(); result.Operations = operations; result.CurrentPage = currentPage; result.CountOfAllPages = await _accountRepository.OperationRepository.GetCountOfAllPagesAsync(checksum, number, sizePage); return(result); }