Exemplo n.º 1
0
        public async Task <IActionResult> Index()
        {
            if (_dataCookies.TryGetPlayerCode(out var code))
            {
                var player = await _playerData.Get(code);

                if (player != null)
                {
                    var vm = new MeViewModel
                    {
                        Code = player.Code,
                        Name = player.Name
                    };
                    return(View(vm));
                }
            }

            _logger.LogInformation("New player");

            return(RedirectToAction("New", "Players", new { returnUrl = Url.Action("Index") }));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Play()
        {
            if (!_dataCookies.TryGetPlayerCode(out var code))
            {
                return(RedirectToAction("New", "Players", new { returnUrl = Url.Action("Play") }));
            }

            var player = await _playerData.Get(code);

            if (player == null)
            {
                return(RedirectToAction("New", "Players", new { returnUrl = Url.Action("Play") }));
            }

            var vm = await CreateGameViewModel();

            vm.ColumnCount = Constants.SquaresPerLine;

            vm.PlayerName = player.Name;

            return(View(vm));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> CreatePlayer([FromForm] NewPlayerViewModel model, [FromQuery] string returnUrl)
        {
            if (!string.IsNullOrWhiteSpace(model.Code))
            {
                var player = await _playerData.Get(model.Code);

                if (player == null)
                {
                    return(RedirectToAction("New", new { message = "No matching code found." }));
                }

                _dataCookies.SetPlayerCode(player.Code);
            }
            else if (!string.IsNullOrWhiteSpace(model.Name))
            {
                var(created, player) = await _playerData.TryCreate(model.Name);

                if (!created)
                {
                    return(RedirectToAction("New", new { message = "Sorry, that name is taken." }));
                }

                _dataCookies.SetPlayerCode(player.Code);
            }
            else
            {
                return(RedirectToAction("New", new { message = "Enter a Name or Code." }));
            }

            if (!string.IsNullOrWhiteSpace(model.ReturnUrl))
            {
                return(Redirect(model.ReturnUrl));
            }

            return(RedirectToAction("Play", "Game"));
        }