コード例 #1
0
 public ActionResult Login(EduMartFYP1.Models.Cmembership model)
 {
     using (var Context = new EduMartEntities())
     {
         bool isvalid = Context.College.Any(x => x.CollegeEmail == model.CollegeEmail && x.CollegePassword == model.CollegePassword);
         if (isvalid)
         {
             var username = (from c in Context.College
                             where c.CollegeEmail == model.CollegeEmail && c.CollegePassword == model.CollegePassword
                             select c.CollegeName).FirstOrDefault();
             var id = (from c in Context.College
                       where c.CollegeEmail == model.CollegeEmail && c.CollegePassword == model.CollegePassword
                       select c.CollegeID).FirstOrDefault();
             Session["Collegeusername"] = username;
             Session["Collegeid"]       = id;
             FormsAuthentication.SetAuthCookie(username, false);
             return(RedirectToAction("Index", "Applications/Index"));
         }
         ModelState.AddModelError("", "Invalid Username and Password");
         return(View());
     }
 }
コード例 #2
0
        public ActionResult Create(College college)
        {
            using (var Context = new EduMartEntities())
                if (ModelState.IsValid)
                {
                    var username = (from c in Context.College
                                    where c.CollegeEmail == college.CollegeEmail && c.CollegePassword == college.CollegePassword
                                    select c.CollegeName).FirstOrDefault();
                    if (username == null)
                    {
                        db.College.Add(college);
                        db.SaveChanges();
                        return(RedirectToAction("Application/Index"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Email Already Exists");
                        return(View());
                    }
                }

            return(View(college));
        }
コード例 #3
0
 public ActionResult Login(EduMartFYP1.Models.Adminmembership model)
 {
     using (var Context = new EduMartEntities())
     {
         bool isvalid = Context.Admin.Any(x => x.adminusername == model.adminusername && x.adminpassword == model.adminpassword);
         if (isvalid)
         {
             var username = (from a in Context.Admin
                             where a.adminusername == model.adminusername && a.adminpassword == model.adminpassword
                             select a.adminusername).FirstOrDefault();
             var id = (from a in Context.Admin
                       where a.adminusername == model.adminusername && a.adminpassword == model.adminpassword
                       select a.adminid).FirstOrDefault();
             Session["admin"]   = username;
             Session["adminid"] = id;
             ViewBag.username   = username;
             FormsAuthentication.SetAuthCookie(username, false);
             return(RedirectToAction("Index", "Applications/Index"));
         }
         ModelState.AddModelError("", "Invalid Username and Password");
         return(View());
     }
 }
コード例 #4
0
 public ActionResult Login(Models.Membership model)
 {
     using (var Context = new EduMartEntities())
     {
         bool isvalid = Context.Student.Any(x => x.Email == model.Email && x.Password == model.Password);
         if (isvalid)
         {
             var username = (from s in Context.Student
                             where s.Email == model.Email && s.Password == model.Password
                             select s.FirstName).FirstOrDefault();
             var id = (from s in Context.Student
                       where s.Email == model.Email && s.Password == model.Password
                       select s.StudentID).FirstOrDefault();
             Session["username"] = username;
             Session["id"]       = id;
             ViewBag.username    = username;
             FormsAuthentication.SetAuthCookie(username, false);
             return(RedirectToAction("Index", "Applications/Index"));
         }
         ModelState.AddModelError("", "Invalid Username and Password");
         return(View());
     }
 }
コード例 #5
0
        public ActionResult Create(Student student)
        {
            var Context = new EduMartEntities();

            if (ModelState.IsValid)
            {
                var username = (from s in Context.Student
                                where s.Email == student.Email && s.Password == student.Password
                                select s.FirstName).FirstOrDefault();
                if (username == null)
                {
                    db.Student.Add(student);
                    db.SaveChanges();
                    return(RedirectToAction("Application/Index"));
                }
                else
                {
                    ModelState.AddModelError("", "Email Already Exists");
                    return(View());
                }
            }

            return(View(student));
        }