예제 #1
0
파일: PongRepo.cs 프로젝트: romus666/Pong
        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);
        }
예제 #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));
            }
        }