public IActionResult Transfer(int id)
        {
            var bankAccountDTO = bankAccountRepository.GetBankAccountDTOById(id);
            BankAccountTransferViewModel bankAccountToTransferViewModel = BankAccountMapHelpers.MapBankAccountDTOToTransferViewModel(bankAccountDTO);

            return(View(bankAccountToTransferViewModel));
        }
Ejemplo n.º 2
0
        public static BankAccountTransferViewModel MapBankAccountDTOToTransferViewModel(BankAccountDTO bankAccountDTO)
        {
            BankAccountTransferViewModel bankAccountToTransferViewModel = new BankAccountTransferViewModel
            {
                ID                      = bankAccountDTO.ID,
                AmountCurrent           = bankAccountDTO.Amount,
                Owner                   = bankAccountDTO.Owner.UserName,
                AmountToTransfer        = 0,
                BankAccountIDToTransfer = null,
                ModifiedDate            = bankAccountDTO.ModifiedDate
            };

            return(bankAccountToTransferViewModel);
        }
        public IActionResult Transfer(int id, BankAccountTransferViewModel bankAccountTransferViewModel)
        {
            if (ModelState.IsValid)
            {
                if (bankAccountTransferViewModel.BankAccountIDToTransfer.HasValue &&
                    bankAccountRepository.DoesBankAccountExists(bankAccountTransferViewModel.BankAccountIDToTransfer.Value))
                {
                    try
                    {
                        bool withdrawOperationResult =
                            bankAccountRepository.TransferAmountFromAccountToAccount(id, bankAccountTransferViewModel.BankAccountIDToTransfer.Value,
                                                                                     bankAccountTransferViewModel.AmountCurrent, bankAccountTransferViewModel.AmountToTransfer, bankAccountTransferViewModel.ModifiedDate);

                        if (withdrawOperationResult)
                        {
                            return(RedirectToAction("Index", "BankAccount", new { @id = id }));
                        }
                    }
                    catch (InvalidBankAccountModifiedTimeStamp ex)
                    {
                        //ViewData["AmountToTransferError"] = "The Amount of the Bank account has been modified Please, refresh the page and try to deposit again!";
                        return(RedirectToAction("Transfer", "BankAccount", new { @id = id }));
                    }
                    catch (InvalidBankAccountWithdrawException ex)
                    {
                        ModelState.AddModelError("AmountToWithdraw", "The Amount of money to withdraw exceeds the Amount of money in the Bank Account!");
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError(string.Empty, "Something wen wrong! Please retry the operation!");
                    }
                }
                else
                {
                    ModelState.AddModelError("BankAccountIDToTransfer", "The target Account ID does not exists!");
                }
            }

            return(View(bankAccountTransferViewModel));
        }