コード例 #1
0
        // GET: Games/Create
        public ActionResult NewGame()
        {
            var mpvm = new CreatePoolGameModel
            {
                AllPlayers = _dbContext.Players.ToList()
            };

            return(View(mpvm));
        }
コード例 #2
0
        public async Task <ActionResult> NewGame([FromForm] CreatePoolGameModel collection) //IFormCollection collection)
        {
            try
            {
                var postObj = collection.poolGame;
                postObj.PlayerOne = _dbContext.Players.Find(collection.poolGame.PlayerOne.Id);
                postObj.PlayerTwo = _dbContext.Players.Find(collection.poolGame.PlayerTwo.Id);
                postObj.Winner    = _dbContext.Players.Find(collection.poolGame.Winner.Id);

                _dbContext.PoolGames.Add(postObj);
                await _dbContext.SaveChangesAsync();

                return(RedirectToAction(nameof(NewGame)));
            }
            catch
            {
                return(View());
            }
        }