예제 #1
0
        public ActionResult ChangePINconfirm(FormCollection collection)
        {
            ATM atm = (ATM)Session["ATM"];
            Card card = (Card)Session["Card"];
            string newPin = (string)Session["NewPin"];
            string confPin = collection["txtConfPin"];

            if (CheckSystax(confPin))
            {

                return View();

            }
            else if (CheckMatchNewAndConf(confPin, newPin) == false)
            {
                return View();
            }

            card.PIN = newPin;
            Card cardPIN = db.Cards.Find(card.CardNo);
            cardPIN.PIN = card.PIN;
            db.Entry(cardPIN).State = EntityState.Modified;
            db.SaveChanges();

            // Ghi Log cho change PIN
            lc = new LogController();
            string detailsFrom = "";
            lc.WriteLog(4, 1, card.CardNo, 0, detailsFrom);
            return RedirectToAction("SuccessTransAsking", "Home");
        }
        /// <summary>
        /// Kiểm tra số dư
        /// </summary>
        /// <returns></returns>
        public ActionResult CheckBalance()
        {
            ATM atm = (ATM)Session["ATM"];
            Card card = (Card)Session["Card"];
            string cardNo;
            cardNo = card.CardNo;

            Account account = db.Accounts.Find(card.AccountID);
            decimal balance = (decimal)account.Balance;
            ViewBag.balanc = balance;

            lc = new LogController();
            string detailsFrom = "";
            lc.WriteLog(3, 1, card.CardNo, 0, detailsFrom);

            return View();
        }
        public ActionResult Withdraw(string submitButton)
        {
            Card card = (Card)Session["Card"];
            ATM atm = (ATM)Session["ATM"];
            int amount = 0;
            bool kiemTraAcc, kiemTraAtm, kiemTraLimitWithdraw;
            // lay account qua card
            Account account = db.Accounts.Find(card.AccountID);
            // xu ly lua chon rut tien
            switch (submitButton)
            {
                case "500.000":
                    {
                        amount = 500000;
                    }
                    break;
                case "1.000.000":
                    {
                        amount = 1000000;
                    }
                    break;

                case "2.000.000":
                    {
                        amount = 2000000;
                    }
                    break;

                case "3.000.000":
                    {
                        amount = 3000000;
                    }
                    break;

                case "Other":
                    {
                        return RedirectToAction("WithdrawOther", "Account");
                    }
                //break;
                default:
                    {
                        return View();
                    }
                //break;
            }
            kiemTraAcc = checkAccount(amount, account);// goi ham kiem tra  tai khoan account
            kiemTraAtm = checkATM(amount); // goi ham kiem tra tien trong ATM
            string kiemTraType = checkTypeMoney(amount); // goi ham kiem tra tung menh gia trong ATM
            kiemTraLimitWithdraw = checkLimitWithdraw(amount, account);//goi ham kiem tra gioi han rut tien cua tai khoan
            if (kiemTraAcc == true && kiemTraAtm == true && kiemTraLimitWithdraw == true && kiemTraType != "")
            {
                // tru tien trong tai khoan
                account.Balance -= amount;

                //ghi log
                lc = new LogController();
                string detailsFrom = "";
                lc.WriteLog(1, 1, card.CardNo, amount, detailsFrom);
                // goi ham tru tien o ATM và hien view so tien ma khach se nhan duoc
                ViewBag.money = kiemTraType;
                db.SaveChanges();
                return View();

            }
            else
            {
                ViewBag.Error = showError(kiemTraAcc, kiemTraLimitWithdraw, kiemTraAtm, kiemTraType);
                return View();
            }
        }
        public ActionResult WithdrawOther(Account a)
        {
            decimal amount = (decimal)a.Balance;

            if (amount % 50000 == 0)
            {
                if (amount <= 10000000)
                {
                    Card card = (Card)Session["Card"];
                    ATM atm = (ATM)Session["ATM"];

                    Account account = db.Accounts.Find(card.AccountID);
                    bool kiemTraAcc, kiemTraAtm, kiemTraLimitWithdraw;
                    kiemTraAcc = checkAccount(amount, account);// goi ham kiem tra  tai khoan account
                    kiemTraAtm = checkATM(amount); // goi ham kiem tra tien trong ATM
                    string kiemTraType = checkTypeMoney(amount); // goi ham kiem tra tung menh gia trong ATM
                    kiemTraLimitWithdraw = checkLimitWithdraw(amount, account);//goi ham kiem tra gioi han rut tien cua tai khoan
                    if (kiemTraAcc == true && kiemTraAtm == true && kiemTraLimitWithdraw == true && kiemTraType != "")
                    {
                        // tru tien trong tai khoan
                        account.Balance -= amount;

                        //ghi log
                        lc = new LogController();
                        string detailsFrom = "";
                        lc.WriteLog(1, 1, card.CardNo, amount, detailsFrom);
                        // goi ham tru tien o ATM và hien view so tien ma khach se nhan duoc
                        ViewBag.money = kiemTraType;
                        db.SaveChanges();
                        return View();

                    }
                    else
                    {
                        ViewBag.Error = showError(kiemTraAcc, kiemTraLimitWithdraw, kiemTraAtm, kiemTraType);
                        return View();
                    }
                }
                else
                {
                    ViewBag.Error = "Số tiền rút cho phép là dưới mười triệu đồng :10000000";
                    return View();
                }
            }
            else
            {
                ViewBag.Error = "Số tiền rút phải là bội của năm mươi nghìn đồng:50.000";
                return View();

            }
        }
        public ActionResult TransferCashConfirm(Account account)
        {
            ATM atm = (ATM)Session["ATM"];

            Card card = (Card)Session["Card"];
            Account accountFrom = db.Accounts.Find(card.AccountID);

            // Tránh lỗi mutipleEntity ?!?
            Account accountto = (Account)Session["AccountTo"];
            int accountToID = accountto.AccountID;
            Account accountTo = db.Accounts.Find(accountToID);

            decimal amount = (decimal)Session["AmountTransfer"];

            accountFrom.Balance = accountFrom.Balance - amount;
            accountTo.Balance = accountTo.Balance + amount;
            db.Entry(accountFrom).State = EntityState.Modified;
            db.Entry(accountTo).State = EntityState.Modified;
            db.SaveChanges();

            // Ghi Log cho tk gửi
            lc = new LogController();
            // Details chỉ đến tên chủ tài khoản + AccNo
            string detailsFrom = "Transfer cash to " + accountTo.Customer.Name + " AccountID: " + accountTo.AccountID;
            lc.WriteLog(2, atm.ATMID, card.CardNo, amount, detailsFrom);

            //string detailsTo = "Receive cash from " + accountFrom.Customer.Name + " AccountID: " + accountFrom.AccountID;

            // Xóa Session
            Session["AccountTo"] = null;
            Session["AmountTransfer"] = null;

            return RedirectToAction("SuccessTransAsking", "Home");
        }