Dheeraj Sharma

Dheeraj Sharma

  • NA
  • 98
  • 29.1k

check if user already logged in

Jan 3 2018 5:55 AM
i want to check if user is already logged in,
do anyone have code to check that user is already logged in,
my code is below, 
 
   public ActionResult GetLogin(Register d,Login r)
   {
      using (simpleEntities _LoginEntities = new simpleEntities())
         {
            var user = _LoginEntities.Registers.Where(u => u.Email.Equals(d.Email) &&             u.Password.Equals(d.Password)).FirstOrDefault();
            string message = "User already logged in";
            if (user != null)
            {
               //var user1 = _LoginEntities.Logins.Where(v => v.Status == 0);
               //if (r.Status != 1 && d.ID ==r.LogID)
               //if (user1!=null)
               {
                  Session["ID"] = user.ID.ToString();
                  Session["Email"] = user.Email.ToString();
                  Session["Username"] = user.Fname.ToString() + "" + user.Lname.ToString();
                  return RedirectToAction("UserDashBoard");
               }
            //else
            //{
                  //
             //}
         }
         return Json(message, JsonRequestBehavior.AllowGet);
}
 
first it will check in register table that credential are correct or not then it will check in logins table that user is already logged in 
if anyone have if condition to check conditions from both table then it will be helpful

Answers (1)