Пример #1
0
        public ActionResult CheckLogin()
        {
            string username = Request.Params["Username"].ToLower().Trim();
            string password = Request.Params["Password"];

            /// ล็อกอิน staff
            Database   db     = new Database();
            UsersDAO   uDAO   = new UsersDAO(db);
            UsersModel uModel = uDAO.GetLogin(username, password);

            db.Close();

            ///  ล็อกอิน ลูกค้า
            db = new Database();
            CustomerDAO   cDAO   = new CustomerDAO(db);
            CustomerModel cModel = cDAO.GetLogin(username, password);

            db.Close();

            // userModel มีค่า
            if (uModel != null)
            {
                Session["ID"]    = uModel.USER_NO;
                Session["PRIO"]  = uModel.PRIORITY.PRIO_ID;
                Session["LEVEL"] = uModel.PRIORITY.PRIO_NAME;
                Session["NAME"]  = uModel.NAME + " " + uModel.LASTNAME;
                Session.Timeout  = 1800;

                return(Redirect("~/Main/Staff"));
            }
            // userModel ไม่มีค่า
            // เช็คค่าของ CustomerModel
            else if (cModel != null)
            {
                Session["ID"]    = cModel.CUST_NO;
                Session["PRIO"]  = cModel.PRIORITY.PRIO_ID;
                Session["LEVEL"] = cModel.PRIORITY.PRIO_NAME;
                Session["NAME"]  = cModel.C_NAME + " " + cModel.C_LASTNAME;
                Session.Timeout  = 1800;

                return(Redirect("~/Main/C")); // C = Customer
            } // end else if
            // ค่าเป็นค่าว่างท้งหมดให้กลับไปหน้า Login
            else
            {
                return(RedirectToAction("Alert", new { msg = "ข้อมูลเข้าสูระบบไม่ถูกต้อง", link = "../Login" }));
            } // จบ else
        }