Exemplo n.º 1
0
        public ActionResult Login(User user)
        {
            using (OLearningEntities data = new OLearningEntities())
            {
                var obj = data.Users.Where(a => a.UserName.Equals(user.UserName) && a.Password.Equals(user.Password)).FirstOrDefault();
                if (obj != null)
                {
                    if (obj.Status == "Ban")
                    {
                        ViewBag.Ban = "You are banned contact [email protected]";
                        return(View());
                    }
                    Session["UserID"]   = obj.UserId.ToString();
                    Session["Username"] = obj.UserName.ToString();
                    //Session["UserType"] = obj.UserType.ToString();
                    if (obj.UserType.ToString() == "Admin")
                    {
                        return(RedirectToAction("AdminDashboard"));
                    }

                    else if (obj.UserType.ToString() == "Teacher")
                    {
                        return(RedirectToAction("Index", "TeacherHome"));
                    }

                    else if (obj.UserType.ToString() == "Student")
                    {
                        return(RedirectToAction("StudentDashboard"));
                    }
                }
                else
                {
                    ViewBag.Error = "Invalid User Name or Password";

                    // return View();
                }

                return(View());
            }

            //return RedirectToAction("Login");
        }