Esempio n. 1
0
 public T_CUSTOMER GetAuthenCustomer(LoginModel models)
 {
     var query = from a in db.T_CUSTOMER
                 where a.AUTH_USER == models.AUTH_USER && a.AUTH_PASS == models.AUTH_PASS
                 select a;
     return query.FirstOrDefault();
 }
Esempio n. 2
0
        public ActionResult Login(LoginModel model)
        {
            ViewBag.OrderDetail = objSession.GetSessionOrder(this);
            ViewBag.CustomerDetail = objSession.GetSessionCustomer(this);

            if (ModelState.IsValid)
            {
                T_CUSTOMER objCustomer = _DataFactory.GetAuthenCustomer(model);
                if (objCustomer != null)
                {
                    if (model.RememberMe)
                    {
                        var json = JsonConvert.SerializeObject(objCustomer);
                        var userCookie = new HttpCookie("user", json);
                        userCookie.Expires.AddDays(365);
                        this.ControllerContext.HttpContext.Response.Cookies.Add(userCookie);
                    }
                    else
                    {
                        var json = JsonConvert.SerializeObject(objCustomer);
                        var userCookie = new HttpCookie("user", json);
                        userCookie.Expires.AddDays(1);
                        this.ControllerContext.HttpContext.Response.Cookies.Add(userCookie);
                    }
                    Session.Add("IsAuthen", 1);
                    Session.Add("Customer", objCustomer);

                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", "Username / Pasword is wrong");
                }
            }
            return View();
        }