Beispiel #1
0
        public async Task <IActionResult> Create([Bind("Id,Username,Birthdate")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(user));
        }
Beispiel #2
0
        public async Task <IActionResult> Create(CreateGameViewModel game)
        {
            if (ModelState.IsValid)
            {
                // Use the passed in data to create new game objects

                // Create game
                var newGame = new Game {
                    StartDate = DateTime.Now,
                    Teams     = new List <Team> {
                        new Team {
                            Type    = TeamType.Red,
                            Players = new List <Player> {
                                new Player {
                                    Type   = PlayerType.Goalie,
                                    UserId = game.RedTeam.GoalieId
                                },
                                new Player {
                                    Type   = PlayerType.Defender,
                                    UserId = game.RedTeam.DefenderId
                                },
                                new Player {
                                    Type   = PlayerType.Center,
                                    UserId = game.RedTeam.CenterId
                                },
                                new Player {
                                    Type   = PlayerType.Striker,
                                    UserId = game.RedTeam.StrikerId
                                }
                            }
                        },
                        new Team {
                            Type    = TeamType.Blue,
                            Players = new List <Player> {
                                new Player {
                                    Type   = PlayerType.Goalie,
                                    UserId = game.BlueTeam.GoalieId
                                },
                                new Player {
                                    Type   = PlayerType.Defender,
                                    UserId = game.BlueTeam.DefenderId
                                },
                                new Player {
                                    Type   = PlayerType.Center,
                                    UserId = game.BlueTeam.CenterId
                                },
                                new Player {
                                    Type   = PlayerType.Striker,
                                    UserId = game.BlueTeam.StrikerId
                                }
                            }
                        }
                    }
                };

                _context.Add(newGame);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(game));
        }