public ActionResult Login(UserProfile objUser)
 {
     if (ModelState.IsValid)
     {
         using (StudentEntities1 db = new StudentEntities1())
         {
             var obj = db.UserProfiles.Where(a => a.UserName.Equals(objUser.UserName) && a.Password.Equals(objUser.Password)).FirstOrDefault();
             if (obj != null)
             {
                 Session["UserID"]   = obj.UserId.ToString();
                 Session["UserName"] = obj.UserName.ToString();
                 Session["Name"]     = obj.UserName.ToString();
                 Session["Role"]     = obj.Role.ToString();
                 if (obj.Role.ToString() == "2")
                 {
                     using (StudentEntities5 re = new StudentEntities5())
                     {
                         var objTeacher = re.TEACHERS.Where(a => a.EMAIL.Equals(objUser.UserName)).FirstOrDefault();
                         Session["teacherClass"] = objTeacher.STD.ToString();
                         Session["teacherName"]  = objTeacher.NAME.ToString();
                         Session["teacherId"]    = objTeacher.TID.ToString();
                     }
                 }
                 return(RedirectToAction("LandingPage"));
             }
         }
     }
     return(View(objUser));
 }
Exemple #2
0
        public ActionResult RegisterTeacher(TEACHER obj)
        {
            try
            {
                UserProfile objUser = new UserProfile();
                if (ModelState.IsValid)
                {
                    using (StudentEntities5 re = new StudentEntities5())
                    {
                        re.TEACHERS.Add(obj);
                        re.SaveChanges();
                        ModelState.Clear();
                        objUser.UserName = obj.EMAIL;
                        objUser.Password = "******";
                        objUser.Role     = 2;
                        objUser.IsActive = true;
                        obj             = null;
                        obj             = null;
                        ViewBag.Message = "Success";
                    }
                    using (StudentEntities1 db = new StudentEntities1())
                    {
                        db.UserProfiles.Add(objUser);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Student", "Index")));
            }

            return(View(obj));
        }
 public ActionResult Login(UserProfile objUser)
 {
     if (ModelState.IsValid)
     {
         using (StudentEntities1 db = new StudentEntities1())
         {
             var obj = db.UserProfiles.Where(a => a.UserName.Equals(objUser.UserName) && a.Password.Equals(objUser.Password)).FirstOrDefault();
             if (obj != null)
             {
                 Session["UserID"]   = obj.UserId.ToString();
                 Session["UserName"] = obj.UserName.ToString();
                 Session["Role"]     = obj.Role.ToString();
                 return(RedirectToAction("LandingPage"));
             }
         }
     }
     return(View(objUser));
 }
        public ActionResult RegisterStudent(STUDENT obj)
        {
            try
            {
                UserProfile objUser = new UserProfile();
                if (ModelState.IsValid)
                {
                    using (StudentEntities4 re = new StudentEntities4())
                    {
                        re.STUDENTS.Add(obj);
                        re.SaveChanges();
                        ModelState.Clear();

                        objUser.UserName = obj.EMAIL;
                        objUser.Password = "******";
                        objUser.Role     = 3;
                        objUser.IsActive = true;
                        obj             = null;
                        ViewBag.Message = "Success";
                    }



                    using (StudentEntities1 db = new StudentEntities1())
                    {
                        if (!db.UserProfiles.Any(x => x.UserName == objUser.UserName))
                        {
                            db.UserProfiles.Add(objUser);
                            db.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Student", "Index")));
            }

            return(View(obj));
        }