Example #1
0
        public IActionResult Create(Users userRegister, string password)
        {
            Users userLog = _context.users.SingleOrDefault(user => user.email == userRegister.email);

            if (userLog != null)
            {
                return(RedirectToAction("Index"));
            }
            else if (ModelState.IsValid && userRegister.password == password)
            {
                PasswordHasher <Users> hasher = new PasswordHasher <Users>();
                userRegister.password   = hasher.HashPassword(userRegister, userRegister.password);
                userRegister.created_at = DateTime.Now;
                userRegister.points     = 0;
                _context.Add(userRegister);
                _context.SaveChanges();

                userLog = _context.users.SingleOrDefault(user => user.email == userRegister.email);

                HttpContext.Session.SetInt32("LogedUserID", userLog.id);
                return(RedirectToAction("Home"));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
Example #2
0
        public async Task <ActionResult> GenerateGame(string category = "", string difficulty = "easy", string type = "", int amount = 10)
        {
            int?userID = HttpContext.Session.GetInt32("LogedUserID");

            if (userID != null)
            {
                dbUser = _context.users.SingleOrDefault(u => u.id == 1);
                if (dbUser != null)
                {
                    Games game = new Games()
                    {
                        status    = "Open",
                        dificulty = dif,
                        User      = dbUser
                    };
                    _context.Add(game);
                    _context.SaveChanges();

                    string question_URL = URL + "amount=" + amount;
                    if (category != "")
                    {
                        question_URL += "&category=" + category;
                    }

                    question_URL += "&difficulty=" + difficulty;
                    dif           = difficulty;

                    if (type != "")
                    {
                        question_URL += "&type=" + type;
                    }

                    SaveData(await GetRequest(question_URL));

                    return(View("PlayGround"));
                }
            }
            return(RedirectToAction("Index"));
        }
Example #3
0
        public async Task <ActionResult> GenerateGame(string category, string difficulty, string type, int amount)
        {
            // Console.WriteLine("*********************************");
            // Console.WriteLine(category);
            // Console.WriteLine(type);
            // Console.WriteLine(difficulty);
            // Console.WriteLine(amount);
            // Console.WriteLine("*********************************");
            int?userID = HttpContext.Session.GetInt32("LogedUserID");

            if (userID != null)
            {
                dbUser = _context.users.SingleOrDefault(u => u.id == userID);
                if (dbUser != null)
                {
                    ViewBag.LogedUser = dbUser;
                    score             = 0;
                    ViewBag.amount    = amount;

                    game = new Games()
                    {
                        status    = "Open",
                        dificulty = dif,
                        User      = dbUser
                    };
                    _context.Add(game);
                    // dbUser.Games.Add(game);
                    _context.SaveChanges();

                    string question_URL = URL + "amount=" + amount;
                    if (category != "any")
                    {
                        question_URL += "&category=" + category;
                    }
                    if (difficulty != "any")
                    {
                        question_URL += "&difficulty=" + difficulty;
                    }
                    // question_URL += "&difficulty=" + difficulty;
                    dif = difficulty;
                    if (type != "any")
                    {
                        question_URL += "&type=" + type;
                    }
                    Console.WriteLine("*********************************");
                    Console.WriteLine(question_URL);
                    Console.WriteLine("*********************************");

                    SaveData(await GetRequest(question_URL));

                    return(View("PlayGround"));
                }
            }
            return(RedirectToAction("Index", "Home"));
        }