Пример #1
0
        // GET: Games/NewGame
        public ActionResult NewGame()
        {
            var game = new Game();
            var vm = new NewGameViewModel();

            game.UserId = UserId;
            game.User = db.Users.Where(u => u.Id == UserId).First();
            vm.Game = game;

            vm.Actives = new List<Activeness>();
            var countries = db.Countries.ToList();
            countries.ForEach(c => vm.Actives.Add(new Activeness(c)));

            return View(vm);
        }
Пример #2
0
        public ActionResult NewGame(NewGameViewModel vm)
        {
            if (ModelState.IsValid)
            {
                G = vm.Game;
                db.Games.Add(G);

                var activeCountries = vm.Actives.Where(a => a.Active).ToList();
                activeCountries.ForEach(a => db.GameCountries.Add(new GameCountry(G.Id, a.CountryId)));

                db.SaveChanges();

                return RedirectToAction("Play");
                //return RedirectToAction("Play", new { id = G.Id }); // don't think we need to use this one
            }

            return View(vm);
        }