public ActionResult LandingPage()
        {
            if (Session["UserID"] != null)
            {
                List <STUDENT> liStudent = new List <STUDENT>();
                List <STUDENT> liStu     = null;
                using (StudentEntities4 student = new StudentEntities4())
                {
                    liStu = student.STUDENTS.ToList();
                }
                if (Convert.ToInt32(Session["Role"]) == 3)
                {
                    string userName = Convert.ToString(Session["UserName"]);
                    liStudent = liStu.Where(a => a.EMAIL.Equals(userName.Trim())).ToList();
                }
                else if (Convert.ToInt32(Session["Role"]) == 2)
                {
                    string        teacherStd = Convert.ToString(Session["teacherClass"]);
                    List <string> liStd      = teacherStd.Split(',').ToList();
                    foreach (string s in liStd)
                    {
                        liStudent.AddRange(liStu.Where(a => a.STD == s).ToList());
                    }
                }

                return(View(liStudent));
            }
            else
            {
                return(RedirectToAction("Login"));
            }
        }
        // GET: StudentDetails
        public ActionResult ViewStudent(STUDENT objstudent)
        {
            using (StudentEntities4 db4 = new StudentEntities4())
            {

                var obj = db4.UserProfiles.Where(a => a.UserName.Equals(objstudent.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");
                }
            }
        }
        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));
        }
Esempio n. 4
0
        public ActionResult Index(STUDENT obj)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (StudentEntities4 re = new StudentEntities4())
                    {
                        re.STUDENTS.Add(obj);
                        re.SaveChanges();
                        ModelState.Clear();
                        obj             = null;
                        ViewBag.Message = "Success";
                    }
                }
            }
            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Student", "Index")));
            }

            return(View(obj));
        }