Exemple #1
0
        public async Task <IActionResult> Confirm(ATMFormModel model)
        {
            //methods to retrieve have to be different because int? vs int
            var account = await _acctRepo.Get(model.AccountNumber);

            var destAccount = await _acctRepo.GetDest(model.DestinationAccountNumber);

            var    amount  = model.Amount;
            string comment = model.Comment;

            switch (model.TransactionType)
            {
            case ("W"):
                NWBASystem.GetInstance().Withdraw(account, amount);
                break;

            case ("D"):
                NWBASystem.GetInstance().Deposit(account, amount);
                break;

            case ("T"):
                NWBASystem.GetInstance().Transfer(account, destAccount, amount, comment);
                break;
            }
            _acctRepo.Save();
            return(RedirectToAction(nameof(Success)));
        }
Exemple #2
0
        public IActionResult Confirm()
        {
            string customerJson = HttpContext.Session.GetString("CustomerJson");

            if (customerJson == null)
            {
                return(NotFound());
            }

            ATMFormModel model = JsonConvert.DeserializeObject <ATMFormModel>(customerJson);

            return(View(model));
        }
Exemple #3
0
        public async Task <IActionResult> Index(ATMFormModel model)
        {
            //methods to retrieve have to be different because int? vs int
            var account = await _acctRepo.Get(model.AccountNumber);

            var destAccount = await _acctRepo.GetDest(model.DestinationAccountNumber);

            var    amount  = model.Amount;
            string comment = model.Comment;

            if (string.IsNullOrEmpty(comment))
            {
                comment = " ";
            }

            if (model.TransactionType == "T" && (destAccount == null || destAccount == account))
            {
                ModelState.AddModelError(nameof(model.DestinationAccountNumber), "Please ensure destination account number is valid");
            }

            this.CheckAmountError(amount);

            if (model.TransactionType != "D")
            {
                this.CanProceed(model.TransactionType, account, amount);
            }

            if (!ModelState.IsValid)
            {
                return(await this.Index());
            }

            string customerJson = JsonConvert.SerializeObject(model);

            HttpContext.Session.SetString("CustomerJson", customerJson);

            return(RedirectToAction(nameof(Confirm)));
        }