public ActionResult CheckStudentCTELogin(LoginModel model)
        {
            ActionResult response = null;
            string strUnencryptedPWD = string.Empty;

            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    //save strUnencryptedPWD to save in cookie
                    strUnencryptedPWD = model.PWD;

                    DateTime currentDate = DateTime.Now;
                    IList<uspCheckStudentCTELogin_Result> LoginUserEntity = _LoginRepository.CheckStudentCTELogin(model.ID, model.PWD, currentDate);
                    if (LoginUserEntity.Count > 0)
                    {
                        Session["StartTime"] = DateTime.Now; /* get the current time here */

                        foreach (var item in LoginUserEntity)
                        {
                            if (item.StudentId > 0 || item.Name != string.Empty)
                            {
                                Session["LoggedIn"] = true;
                                Session["StudentId"] = item.StudentId;
                                Session["SchoolId"] = item.SchoolID;
                                Session["username"] = model.ID; //added newly for changepwd
                                Session["Grade"] = item.GradePL;

                                //Creating a COOKIE for user...
                                FormsAuthentication.SetAuthCookie("ESP", false);

                                if (model.RememberMe == true)
                                {
                                    HttpCookie cookieUserInfo = new HttpCookie("UserInfo");
                                    cookieUserInfo.Values["UserName"] = model.ID;
                                    cookieUserInfo.Values["Password"] = model.PWD;
                                    cookieUserInfo.Expires = DateTime.Now.AddDays(14); // two weeks 
                                    Response.Cookies.Add(cookieUserInfo);
                                }
                                else
                                {
                                    if (Request.Cookies["UserInfo"] != null)
                                    {
                                        HttpCookie myCookie = new HttpCookie("UserInfo");
                                        myCookie.Expires = DateTime.Now.AddDays(-1d);
                                        Response.Cookies.Add(myCookie);
                                    }
                                }
                                // return RedirectToAction("Index", "Admin");
                                response = Json(new
                                {
                                    result = "Success",
                                    schoolId = item.SchoolID,
                                    schoolYearPL = item.SchoolYearPL,
                                    studentId = item.StudentId,
                                    studentName = item.Name,
                                    SchoolName = item.SchoolName,
                                    Grade = item.GradePL,
                                    url = Url.Action("CTEOption", "Login")
                                });
                            }
                            else
                            {
                                Session["LoggedIn"] = false;
                                response = Json(new { result = "InvalidLogin", url = Url.Action("Login", "Login") });
                            }
                        }
                    }
                    else
                    {
                        Session["LoggedIn"] = false;
                        response = Json(new { result = "InvalidLogin", url = Url.Action("Login", "Login") });
                    }
                }
            }
            catch (Exception ex)
            {
                ViewBag.MSG = ex.Message.ToString();
                return View(ViewBag.MSG);
            }

            return response;
        }