public ActionResult Login(User user)
 {
     if (vl.Users.Any((u) => u.Email == user.Email && u.Password == user.Password))
     {
         //new instance of the Activity class
         Activity userActivity = new Activity();
         //assigns the user's name as whatever email the user enters
         userActivity.ActivityName = "Login: "******"User", user);
         return(View("Index", vl.Users));
     }
     else
     {
         //error handling
         ViewBag["error"] = "Login failed. Could not find a user with that email and password";
         return(View("Login"));
     }
 }
Ejemplo n.º 2
0
        public ActionResult Game(GameViewModel game)
        {
            Session["Guess"] = game.Guess;

            //Get the current player from the Database
            int id             = Convert.ToInt32(Session["StudentID"]);
            var currentstudent = vl.Students.SingleOrDefault(s => s.StudentID == id);

            //get the currentgame for the student
            var currentGame = vl.Games.SingleOrDefault(g => g.studentID == currentstudent.StudentID);

            if (currentGame != null)
            {
                int gameid         = currentGame.GameId;
                int totalCorrect   = currentGame.TotalCorrect;
                int totalIncorrect = currentGame.TotalIncorrect;
            }

            if (currentGame == null)
            {
                currentGame                = new Game();
                currentGame.studentID      = currentstudent.StudentID;
                currentGame.TotalCorrect   = 0;
                currentGame.TotalIncorrect = 0;
                vl.Games.Add(currentGame);
                vl.SaveChanges();
                currentstudent.GameId = currentGame.GameId;
            }


            if (Convert.ToUInt32(Session["Answer"]) == Convert.ToUInt32(Session["Guess"]))
            {
                //add to total correct answers
                currentGame.TotalCorrect++;
                //vl.Games.Add(currentGame);
                ////save to database
                vl.SaveChanges();
                Session["TotalCorrect"] = currentGame.TotalCorrect;
                ModelState.Clear();
                //redirect to winning page with reward
                return(View());
            }
            else
            {   //add to incorrect total answers
                currentGame.TotalIncorrect++;
                //vl.Games.Add(currentGame);
                //save to database
                vl.SaveChanges();
                Session["TotalIncorrect"] = currentGame.TotalIncorrect;
                //replay game
                ModelState.Clear();
                ViewBag.Message = "Sorry, try again";
                return(View());
            }
        }
Ejemplo n.º 3
0
        public ActionResult Login(User user)
        {
            //find current user by id

            //int id = Convert.ToInt32(user.UserID);
            //var currentuser = vl.Users.Single(u => u.UserID == id);

            // search users by password
            var userpasswords = vl.Users.Where(u => u.Password == user.Password);

            if (user.Password != null)
            {
                //create a new activity in the log
                Activity activity = new Activity();
                activity.ActivityName = "LoggedIn";
                activity.ActivityDate = DateTime.Now;
                activity.IpAddress    = Request.UserHostAddress;
                //update the database
                vl.Activities.Add(activity);
                vl.SaveChanges();
                //show the visitor log
                return(RedirectToAction("Index", "Home"));
            }

            else
            {
                return(View());
            }
        }
        public ActionResult PasswordGenerator(PasswordGen user)
        {
            if (user.SelectedPassword != "Suggest A Password")
            {
                var Current = GetTempUser();

                Current.Password = user.SelectedPassword;
                db.Users.Add(Current);
                db.SaveChanges();
                return(View("Login"));
            }

            //Insert Code here that generates a list and displays it in the PasswordGenerator View
            List <string> passwordList = new List <string>();

            passwordList = sugPass(user);



            ViewBag.PasswordOptions = passwordList;
            return(View());
        }
Ejemplo n.º 5
0
 public ActionResult NewAccount(User newAcct)    //passing  to newAcct paramater
 {
     if (ModelState.IsValid)                     //Checking a model is valid or not.
     {
         using (VisitorLogContext db = new VisitorLogContext())
         {
             db.Users.Add(newAcct);
             db.SaveChanges();
         }
         //Create message to user once it's succeded.
         ModelState.Clear();
         ViewBag.Message = newAcct.FirstName + " " + newAcct.LastName + ", You just registered";
     }
     return(View());
 }
        public ActionResult Login(LoginViewModel user)
        {
            if (isUser(user.UserName))
            {
                Activity newActivity = new Activity();
                newActivity.ActivityDate = DateTime.Now;
                newActivity.ActivityName = user.UserName;
                newActivity.IpAddress    = Request.UserHostAddress;
                db.Activities.Add(newActivity);
                db.SaveChanges();

                return(View("./HomeController/Index", db.Activities));
            }

            else
            {
                ModelState.Clear();
                ModelState.AddModelError("ErrorMessage", "Your login attempt was not successful. Please try again.");

                return(View("Login"));
            }
        }
Ejemplo n.º 7
0
 public ActionResult Create(Student student)
 {
     db.Students.Add(student);
     db.SaveChanges();
     return(RedirectToAction("StudentLogin"));
 }