- public ActionResult Login(
- FnBMastersModel.Users LogIn)
- {
- bool blnLogIn = false;
- int Count = 0;
- var model = new List < Users > ();
- if (ModelState.IsValid)
- {
- try
- {
- using(var context = new FnBMastersEntityContext())
- {
- var value = context.Userss.ToList();
- Count = (from r in value where r.UserId ==
- LogIn.UserId && r.PassWord ==
- LogIn.PassWord select new
- {
- r.UserId, r.PassWord
- }).Count();
- if (Count != 0)
- {
- blnLogIn = true;
- }
- else
- {
- blnLogIn = false;
- }
- }
- }
- catch (Exception)
- {
- throw;
- }
- }
- if (blnLogIn == true)
- {
- Session["UserName"] = LogIn.UserId;
- return RedirectToAction("Index",
- "LogIn");
- }
- else
- {
- return View();
- }
- }
This code snippet for Validating login details and giving access to the user using MVC.