Exemplo n.º 1
0
        public static void Withdraw(decimal withdrawAmount, decimal balance)
        {
            Withdraw withdraw = new Withdraw(withdrawAmount);

            if (withdraw.CheckIfWithdrawIsGreaterThanBalance(withdrawAmount, balance))
            {
                balance = withdraw.WithdrawAmount(withdrawAmount, balance);
                Console.WriteLine($"Your balance is {balance}");
            }
            else
            {
                Console.WriteLine("You cannot withdraw an amount greater than what you have");
            }
            Menu(balance);
        }
        public ActionResult withdraw(WithdrawDetails details)
        {
            #region Declarations

            string      path        = Constants.path;
            string      json        = "";
            IWithdraw   withdraw    = new Withdraw(details);
            CardDetails cardDetails = new CardDetails();
            string      output      = "";

            #endregion

            #region Read Json File

            using (StreamReader r = new StreamReader(path))
            {
                json = r.ReadToEnd();
            }

            #endregion

            #region Money Withdraw and JSON update

            cardDetails = withdraw.WithdrawAmount(json, details);
            if (cardDetails.IsSufficientBalance == true)
            {
                dynamic jsonObj = Newtonsoft.Json.JsonConvert.DeserializeObject(json);
                foreach (var j in jsonObj)
                {
                    if (j["Username"] == cardDetails.Username)
                    {
                        j["TotalBalance"] = cardDetails.TotalBalance;
                    }
                }
                output = Newtonsoft.Json.JsonConvert.SerializeObject(jsonObj, Newtonsoft.Json.Formatting.Indented);
                System.IO.File.WriteAllText(path, output);
                return(View(cardDetails));
            }
            else
            {
                return(RedirectToAction("Withdrawal_Failed", "Withdrawal"));
            }

            #endregion
        }