public ActionResult StudentClasses()
 {
     if (Session["user"] == null)
     {
         return(Redirect("/Home/Login"));
     }
     MiniCStructure.Models.User user = (MiniCStructure.Models.User)Session["user"];
     return(View(user.Classes));
 }
        public async Task <ActionResult> EnrollInClass(string classId)
        {
            int classIdInt = int.Parse(classId);

            if (Session["user"] == null)
            {
                return(Redirect("/Home/Login"));
            }
            MiniCStructure.Models.User user = (MiniCStructure.Models.User)Session["user"];
            User updatedUser = await Models.User.AddClass(classIdInt, user.UserId);

            Session["user"] = updatedUser;
            return(Redirect("/Home/StudentClasses"));
        }
        public async Task <ActionResult> Register(string email, string password, string passwordConfirm)
        {
            User newUser = new MiniCStructure.Models.User
            {
                UserEmail    = email,
                UserPassword = password
            };
            ValidationContext validationContext    = new ValidationContext(newUser);
            ICollection <ValidationResult> results = new List <ValidationResult>();
            bool          isValid = Validator.TryValidateObject(newUser, validationContext, results, true);
            List <string> errors  = new List <string>();

            foreach (ValidationResult result in results)
            {
                errors.Add(result.ToString());
            }
            TempData["errorMessages"] = errors;
            if (errors.Count > 0)
            {
                return(View(newUser));
            }
            try
            {
                int id = await MiniCStructure.Models.User.Create(newUser);

                if (id > 0)
                {
                    newUser.UserId  = id;
                    Session["user"] = newUser;
                    return(Redirect("/"));
                }
                errors.Add("That email has already been registered");
                TempData["errorMessages"] = errors;
                return(View(new User()));
            }
            catch (Exception ex)
            {
                errors.Add("There was a problem creating your account");
                TempData["errorMessages"] = errors;
                return(View(newUser));
            }
        }