public ActionResult TSignUp([Bind(Include = "ID,UserID,Name,Password,ConfirmPassword,SectionA, SectionB, SectionC")] TSignUp signUp)
        {
            {
                try
                {
                    TSignUp user = db.TSignUps.FirstOrDefault(u => u.UserID == (signUp.UserID));
                    if (user != null)
                    {
                        ModelState.AddModelError("UserID", "This User is already Registered");
                    }
                    if (ModelState.IsValid && user == null)
                    {
                        db.TSignUps.Add(signUp);
                        db.SaveChanges();
                        return(RedirectToAction("TeacherDashBoard"));
                    }
                }

                catch (DataException)
                {
                    ModelState.AddModelError("", "Unable to save changes");
                }
                return(View(signUp));
            }
        }
Exemple #2
0
        public ActionResult Login(SSignUp entity)
        {
            using (KGEntities db = new KGEntities())
            {
                SSignUp user    = db.SSignUps.FirstOrDefault(u => u.UserID == (entity.UserID));
                TSignUp teacher = db.TSignUps.FirstOrDefault(t => t.UserID == (entity.UserID));
                ASignUp admin   = db.ASignUps.FirstOrDefault(a => a.UserID == (entity.UserID));

                if (user == null || teacher == null || admin == null)
                {
                    TempData["ErrorMessage"] = "Object not found";
                    return(View(entity));
                }

                int c = entity.Password.Count();
                if (user.Password.Substring(0, c) != entity.Password || teacher.Password.Substring(0, c) != entity.Password || admin.Password.Substring(0, c) != entity.Password)
                {
                    TempData["ErrorMessage"] = "Password do not Match";
                    return(View(entity));
                }

                if (user != null || teacher != null || admin != null)
                {
                    if (user.Password.Substring(0, c) == entity.Password)
                    {
                        return(RedirectToAction("StudentDashBoard"));
                    }


                    if (teacher.Password.Substring(0, c) == entity.Password)
                    {
                        return(RedirectToAction("TeacherDashBoard", "TSignUp"));
                    }


                    if (admin.Password.Substring(0, c) == entity.Password)
                    {
                        return(RedirectToAction("AdminDashBoard", "ASignUp"));
                    }

                    return(View(entity));
                }
                return(View(entity));
            }
        }