コード例 #1
0
        public ActionResult Create(GameCreateModel gameModel, string tournamentSlug)
        {
            if (gameModel.HomeTeamId == gameModel.AwayTeamId)
            {
                ModelState.AddModelError("AwayTeamId", "A team cannot play itself");
            }
            if (ModelState.IsValid)
            {
                var game = new Game
                {
                    RoundId = gameModel.RoundId.Value,
                    GameTime = gameModel.GameTime
                };
                db.Games.Add(game);
                db.SaveChanges();

                var model = new GameEditModel
                {
                    Id = game.Id,
                    HomeTeamId = gameModel.HomeTeamId,
                    AwayTeamId = gameModel.AwayTeamId,
                    GameTime = gameModel.GameTime,
                    FieldId = gameModel.FieldId
                };
                return Edit(model, tournamentSlug);
            }

            var teams = db.Teams.Where(t => t.Tournament.Slug == tournamentSlug);
            ViewBag.HomeTeamId = new SelectList(teams, "Id", "Name");
            ViewBag.AwayTeamId = new SelectList(teams, "Id", "Name");

            ViewBag.RoundId = new SelectList(db.Rounds, "Id", "Name", gameModel.RoundId);
            return View(gameModel);
        }
コード例 #2
0
        public ActionResult Edit(GameEditModel game, string tournamentSlug)
        {
            if (game.HomeTeamId == game.AwayTeamId) {
                ModelState.AddModelError("AwayTeamId", "A team cannot play itself");
            }

            if (ModelState.IsValid) {
                var dbGame = db.Games.Find(game.Id);
                db.Teams.Find(game.HomeTeamId).Games.Add(dbGame);
                db.Teams.Find(game.AwayTeamId).Games.Add(dbGame);

                db.SaveChanges();
                return RedirectToAction("Standings", "Home", new { tournamentSlug });
            }
            var teams = db.Teams.Where(t => t.Tournament.Slug == tournamentSlug);
            ViewBag.HomeTeamId = new SelectList(teams, "Id", "Name");
            ViewBag.AwayTeamId = new SelectList(teams, "Id", "Name");

            return View(game);
        }
コード例 #3
0
        public ActionResult Edit(int id, string tournamentSlug)
        {
            Game game = db.Games.Include(g => g.Teams).FirstOrDefault(g => g.Id == id);
            var teams = db.Teams.Where(t => t.Tournament.Slug == tournamentSlug);
            ViewBag.HomeTeamId = new SelectList(teams, "Id", "Name");
            ViewBag.AwayTeamId = new SelectList(teams, "Id", "Name");

            var model = new GameEditModel {
                Id = game.Id
            };

            if (game.HomeTeam != null) {
                model.HomeTeamId = game.HomeTeam.Id;
            }
            if (game.AwayTeam != null) {
                model.AwayTeamId = game.AwayTeam.Id;
            }

            return View(model);
        }
コード例 #4
0
        public ActionResult Edit(int id, string tournamentSlug)
        {
            var game = db.Games.Include(g => g.Teams).FirstOrDefault(g => g.Id == id);
            if (game == null) return HttpNotFound();

            var model = new GameEditModel
            {
                Id = game.Id
            };

            if (game.HomeTeam != null)
            {
                model.HomeTeamId = game.HomeTeam.Id;
            }
            if (game.AwayTeam != null)
            {
                model.AwayTeamId = game.AwayTeam.Id;
            }
            model.GameTime = game.GameTime;

            var teams = db.Teams.Where(t => t.Tournament.Slug == tournamentSlug);
            ViewBag.HomeTeamId = new SelectList(teams, "Id", "Name", model.HomeTeamId);
            ViewBag.AwayTeamId = new SelectList(teams, "Id", "Name", model.AwayTeamId);

            var fields = db.Fields.ToList();
            ViewBag.FieldId = new SelectList(fields, "Id", "Name", model.FieldId);

            return View(model);
        }
コード例 #5
0
        public ActionResult Edit(GameEditModel game, string tournamentSlug)
        {
            if (game.HomeTeamId == game.AwayTeamId)
            {
                ModelState.AddModelError("AwayTeamId", "A team cannot play itself");
            }

            if (ModelState.IsValid)
            {
                var dbGame = db.Games.Include(g => g.Teams).FirstOrDefault(g => g.Id == game.Id);
                if (dbGame == null) return HttpNotFound();

                dbGame.AddTeams(db.Teams.Find(game.HomeTeamId), db.Teams.Find(game.AwayTeamId));
                dbGame.GameTime = game.GameTime;
                dbGame.FieldId = game.FieldId;
                db.SaveChanges();
                return RedirectToAction("Standings", "Home", new {tournamentSlug});
            }
            var teams = db.Teams.Where(t => t.Tournament.Slug == tournamentSlug);
            ViewBag.HomeTeamId = new SelectList(teams, "Id", "Name", game.HomeTeamId);
            ViewBag.AwayTeamId = new SelectList(teams, "Id", "Name", game.AwayTeamId);

            return View(game);
        }