コード例 #1
0
        public ActionResult Login(lOGIN1 log)
        {
            if (!ModelState.IsValid)
            {
                TempData["emails"] = log.email;
                var User_type = log.Type;
                if (User_type == "Student")
                {
                    var logmail = (from e in db.Logins
                                   where e.Email == log.email && e.Password == log.pass && e.Type == log.Type
                                   select e).SingleOrDefault();
                    if (logmail == null)
                    {
                        ModelState.AddModelError("", "User Doen't Exists");
                        return(View());
                    }
                    else
                    {
                        string name1 = logmail.Students.First().F_Name.ToString();
                        Session["login"]   = name1;
                        Session["sid"]     = logmail.Students.First().Stu_ID;
                        Session["student"] = true;
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else if (User_type == "Teacher")
                {
                    var logmail = (from e in db.Logins
                                   where e.Email == log.email && e.Password == log.pass && e.Type == log.Type
                                   select e).SingleOrDefault();

                    if (logmail == null)
                    {
                        ModelState.AddModelError("", "User Doesn't Exist Please Register or Check e-mail and Password");
                        return(View());
                    }
                    else
                    {
                        string name1 = logmail.Teachers.First().Teach_Name;
                        Session["login"]   = name1;
                        Session["tid"]     = logmail.Teachers.First().TeacherID;
                        Session["Teacher"] = true;
                        return(RedirectToAction("Index", "TeacherAccess"));
                    }
                }
            }
            else
            {
                ModelState.AddModelError("", "Enter Valid Login emailid annd Password");
                return(View());
            }

            return(View());
        }
コード例 #2
0
        //[ValidateAntiForgeryToken]
        public ActionResult Sign_Up(lOGIN1 log)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    TempData["emails"] = log.email;
                    var User_type = log.Type;
                    if (User_type == "Student")
                    {
                        var email_id = (from e in db.Students
                                        where e.Stu_Email == log.email
                                        select e.Stu_Email).SingleOrDefault();
                        var logmail = (from e in db.Logins
                                       where e.Email == log.email && e.Password == log.pass && log.Type == e.Type
                                       select e.Email).SingleOrDefault();


                        if (logmail == null)
                        {
                            Login lg = new Login();
                            lg.Email    = log.email;
                            lg.Password = log.pass;
                            lg.Type     = log.Type;
                            db.Logins.Add(lg);
                            db.SaveChanges();
                            return(RedirectToAction("Stu_Registration"));
                        }
                        else if (email_id != logmail)
                        {
                            return(RedirectToAction("Stu_Registration"));
                        }
                        else if (email_id == logmail)
                        {
                            ModelState.AddModelError("", "User Already Exists!\n Please Login from Login Tab");
                            return(View());
                        }
                    }
                    else if (User_type == "Teacher")
                    {
                        var email_id = (from e in db.Teachers
                                        where e.Teach_Email == log.email
                                        select e.Teach_Email).SingleOrDefault();
                        var logmail = (from e in db.Logins
                                       where e.Email == log.email && e.Password == log.pass && log.Type == e.Type
                                       select e.Email).SingleOrDefault();
                        if (logmail == null)
                        {
                            Login lg = new Login();
                            lg.Email    = log.email;
                            lg.Password = log.pass;
                            lg.Type     = log.Type;
                            db.Logins.Add(lg);
                            db.SaveChanges();
                            return(RedirectToAction("Teach_Registration"));
                        }
                        else if (email_id == logmail)
                        {
                            ModelState.AddModelError("", "Teacher already Exists \nPlease Login from Login Tab");
                            return(View());
                        }
                        else if (email_id != logmail)
                        {
                            return(RedirectToAction("Teach_Registration"));
                        }
                    }
                    else
                    {
                        return(View());
                    }
                }
            }

            catch (Exception e)
            {
                Response.Write("erroe Occured" + e.Message);
            }

            return(View());
        }