public ActionResult EditInfo(User user)
        {
            if (ModelState.IsValid)
            {
                user.Name = user.Name.Trim();
                user.Address = user.Address.Trim();
                user.Email = user.Email.Trim();
                user.Gender = user.Gender.Trim();
                user.Password = user.Password.Trim();
                user.phoneNumber = user.phoneNumber.Trim();
                db.Entry(user).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                // Come back and send them to the appropriate menu
                // Admins
                if ((int)Session["Type"] == 1)
                {
                    return RedirectToAction("Index", "Admin");
                }

                // Professors
                else if ((int)Session["Type"] == 2)
                {
                    return RedirectToAction("Index", "Professor");
                }

                // Students
                else if ((int)Session["Type"] == 3)
                {
                    return RedirectToAction("Index", "Student");
                }

                // Advisors
                else if ((int)Session["Type"] == 4)
                {
                    return RedirectToAction("Index", "Advisor");
                }

                else
                {
                    ViewBag.errorMessage = "Something went wrong; please contact your adminstrator.";
                    return View();
                }
            }

            else
            {
                return View(user);
            }
        }
        public ActionResult EditUserInfo(User input, String Major, String Advisor)
        {
            if (input.Email == null)
            {
                TempData["error"] = "Invalid email. Please try again";
                return RedirectToAction("Index");
            }
            Models.User user = new Models.User();
            user = (from m in db.Users
                    where m.Id == input.Id
                    select m).First();
            user.Name = input.Name.Trim();
            user.Password = input.Password.Trim();
            user.Email = input.Email.Trim();
            user.phoneNumber = input.phoneNumber.Trim();
            user.Address = input.Address.Trim();
            user.Status = input.Status;

            if (input.Gender.ToUpper().StartsWith("M"))
                user.Gender = "M";
            else user.Gender = "F";

            if (user.userType == 3)
            {
                Student editStudent = (from m in db.Students
                                     where m.UserID == user.Id
                                     select m).First();

                Major = Major.ToUpper();

                int? major = (from m in db.Majors
                              where m.majorName == Major
                              select m.majorId).FirstOrDefault();

                if (major != null)
                    editStudent.MajorID = major.Value;

                if (Advisor != null)
                {
                    int advisorId = (from m in db.Users
                                     where m.Name == Advisor
                                     select m.Id).FirstOrDefault();

                    editStudent.AdvisorID = advisorId;
                }
            }

            db.SaveChanges();

            return RedirectToAction("Index");
        }
        public ActionResult RegisterForSystem(User user)
        {
            if (ModelState.IsValid)
            {
                db.Entry(user).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                Session["Type"] = user.userType;
                Session["User"] = user.Id;

                // Come back and send them to the appropriate menu
                // Admins
                if ((int)Session["Type"] == 1)
                {
                    return RedirectToAction("Index", "Admin");
                }

                // Professors
                else if ((int)Session["Type"] == 2)
                {
                    return RedirectToAction("Index", "Professor");
                }

                // Students
                else if ((int)Session["Type"] == 3)
                {
                    return RedirectToAction("Index", "Student");
                }

                // Advisors
                else if ((int)Session["Type"] == 4)
                {
                    return RedirectToAction("Index", "Advisor");
                }

                else
                {
                    ViewBag.errorMessage = "Something went wrong; please contact your adminstrator.";
                    return View();
                }
            }

            else
            {
                return View(user);
            }
        }
        public ActionResult AddUser(User input, String Major, String Advisor)
        {
            User check = (from m in db.Users
                          where m.Email == input.Email
                          select m).FirstOrDefault();

            if (check == null && input.Email != null) {
                input.registrationLink = "";
                input.Status = false;

                if (input.Gender != null && input.Gender.ToUpper().StartsWith("M"))
                    input.Gender = "M";
                else input.Gender = "F";

                db.Users.Add(input);

                db.SaveChanges();

                if (input.userType == 3) {
                    Student newStudent = new Student();
                    newStudent.UserID = (from m in db.Users
                                         where m.Email == input.Email
                                         select m.Id).First();

                    newStudent.creditHours = 0;

                    Major = Major.ToUpper();

                    int? major = (from m in db.Majors
                                   where m.majorName == Major
                                   select m.majorId).FirstOrDefault();

                    if (major != null)
                        newStudent.MajorID = major.Value;

                    if (Advisor != null)
                    {
                        int advisorId = (from m in db.Users
                                         where m.Name == Advisor
                                         select m.Id).FirstOrDefault();

                        newStudent.AdvisorID = advisorId;
                    }

                    db.Students.Add(newStudent);
                }

                db.SaveChanges();
            }
            else
            {
                TempData["error"] = "User exists or email is invalid. Please try again.";
                return RedirectToAction("AddUser");
            }

            return RedirectToAction("Index");
        }