Ejemplo n.º 1
0
        public async Task <IActionResult> ChargeAsync(string cardNo, string cardPwd, string cardName, double chargeAmount, int cardMonth, int cardYear, string cardCvc)
        {
            CardInfo cardInfo      = new CardInfo(cardNo, cardPwd, cardName, chargeAmount, cardMonth, cardYear, cardCvc);
            var      baseUri       = new Uri(urlString);
            var      serverClient  = new ServerClient(urlString);
            double   formerBalance = login_user.balance;

            login_user.balance = formerBalance + chargeAmount;
            System.Net.HttpStatusCode result = await serverClient.ChargeAsync(cardInfo);

            if (result == System.Net.HttpStatusCode.OK)
            {
                ViewBag.User = login_user;
                string charge_record = chargeAmount + " has been added to user's account successfully!";
                Log    log_charge    = new Log(login_user.userID, charge_record);
                await serverClient.UpdateBalance(login_user);

                await serverClient.RecordLog(log_charge);

                ViewBag.Message = "Add Balance Succeeded! - status code 200!";

                return(View("UpdateUserInfo"));
            }
            else
            {
                login_user.balance = formerBalance;
                ViewBag.User       = login_user;
                string charge_record = "Something wrong here, balance isn't added to user's account successfully!";
                Log    log_charge    = new Log(login_user.userID, charge_record);
                await serverClient.RecordLog(log_charge);

                ViewBag.Message = "Charge Failed, Please Check Card Info! - status code" + result + "!";
                return(View("UpdateUserInfo"));
            }
        }