Dheeraj Sharma

Dheeraj Sharma

  • NA
  • 98
  • 28.9k

prevent multiple login using mvc-4

Jan 4 2018 4:54 AM
i have two table name Register and Login,
when user logs in the, user id and its status=1 will be store in Logins table and when user logs out status will become 0.
my problem is how should i check at login time that user is already logged in or not,
any if conditions to check, below is my code
 
 
 
 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)
{

List ddd = new List();
ddd = (from a in db.Logins where a.LogID == user.ID where (a.Status == (false)) select a).ToList();
if (ddd!=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);
}
}
return View();
}
}

Answers (2)