Example #1
0
 public ActionResult Index(LoginCheckVM log)
 {
     if (string.IsNullOrEmpty(log.EmailId))
     {
         ModelState.AddModelError("EmailId", "EmailId is required!");
     }
     if (string.IsNullOrEmpty(log.Password))
     {
         ModelState.AddModelError("Password", "Password is required!");
     }
     if (ModelState.IsValid)
         {
         List<LoginCheckVM> SubList = new List<LoginCheckVM>();
         using (StudentsEntities context = new StudentsEntities())
             {
              var result = context.LoginCheck(log.EmailId.Trim(), log.Password.Trim()).ToList();
             if (result.Count > 0)
             {
                 foreach (var item in result.ToList())
                 {
                     SubList.Add(new LoginCheckVM
                     {
                         StudentId = item.StudentId,
                         FirstName = item.FirstName,
                         LastName = item.LastName,
                         EmailId = item.EmailId,
                         Role = item.Role
                     });
                 }
                 Session["StudentId"] = SubList[0].StudentId <= 0 ? 0 : SubList[0].StudentId;
                 Session["FirstName"] = SubList[0].FirstName;
                 Session["LastName"] = SubList[0].LastName;
                 Session["EmailId"] = SubList[0].EmailId;
                 Session["Role"] = SubList[0].Role;
                 TempData["UserName"] = SubList[0].FirstName + " " + SubList[0].LastName;
                 TempData["StudentId"] = SubList[0].StudentId;
                 if (SubList[0].Role.Contains("Admin"))
                 {
                     return RedirectToAction("AdminDeshBoard", "Home");
                 }
                 else
                 {
                     return RedirectToAction("UserProfile", "Home");
                 }
             }
             else
             {
                 return RedirectToAction("index", "Home");
             }
         }
     }
     return View();
 }