Exemple #1
0
        public PlayerValidationModel CheckPassword(string name, string password)
        {
            PlayerValidationModel playerValidationModel = new PlayerValidationModel();
            var p = _context.Players.Where(x => x.Name == name).FirstOrDefault();

            if (p != null)
            {
                playerValidationModel.PlayerExist     = true;
                playerValidationModel.PasswordCorrect = p.Password == password ? true : false;
            }
            else
            {
                playerValidationModel.PlayerExist     = false;
                playerValidationModel.PasswordCorrect = true;
            }
            return(playerValidationModel);
        }
Exemple #2
0
        public ActionResult Board(GameModel model)
        {
            var pongRepo = new PongRepo();
            PlayerValidationModel playerOneValidationModel = pongRepo.CheckPassword(model.PlayerOneName, model.PlayerOnePassword);
            PlayerValidationModel playerTwoValidationModel = pongRepo.CheckPassword(model.PlayerTwoName, model.PlayerTwoPassword);

            if (!playerOneValidationModel.PasswordCorrect || !playerTwoValidationModel.PasswordCorrect)
            {
                if (!playerOneValidationModel.PasswordCorrect)
                {
                    ModelState.AddModelError("PlayerOneValidation", "Not correct");
                }
                if (!playerTwoValidationModel.PasswordCorrect)
                {
                    ModelState.AddModelError("PlayerTwoValidation", "Not correct");
                }
                return(View("~/Views/Game/Index.cshtml", model));
            }
            else
            {
                model.Game = pongRepo.CreateGame(model);
                return(View(model));
            }
        }