public ActionResult Create(int leagueOrCupId, bool isCup)
        {
            FixtureViewModel model = new FixtureViewModel();
            model.LeagueOrCupId = leagueOrCupId;

            model.Fixture.IsCupFixture = isCup;

            PopulateStaticData(model);

            return View(model);
        }
        public ActionResult Create(FixtureViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    model.Validate();

                    // TODO Ideally a service should do this
                    model.Fixture = model.MapToFixture(
                        model.Fixture,
                        this.competitionService.GetTeamLeagueByTeamIdInCurrentSeason(model.HomeTeamId),
                        this.competitionService.GetTeamLeagueByTeamIdInCurrentSeason(model.AwayTeamId),
                        model.Referee1Id.HasValue ? this.refereeService.Get(model.Referee1Id.Value) : null,
                        model.Referee2Id.HasValue ? this.refereeService.Get(model.Referee2Id.Value) : null,
                        this.membershipService.GetLoggedInUser(),
                        model.OneOffVenueId.HasValue ? oneOffVenueService.Get(model.OneOffVenueId.Value) : null);

                    if(model.Fixture.IsCupFixture)
                        model.Fixture.Cup = cupService.Get(model.LeagueOrCupId);

                    fixtureService.Save(model.Fixture);
                    fixtureService.Commit();

                    SuccessMessage(FormMessages.SaveSuccess);

                    if (model.CreateAnotherFixture)
                        return RedirectToAction("Create", new { leagueOrCupId = model.LeagueOrCupId, isCup = model.Fixture.IsCupFixture });
                    else
                        return RedirectToAction("Index");
                }
            }
            catch (FixtureTeamsTheSameException)
            {
                ErrorMessage(FormMessages.FixtureTeamsTheSame);
            }

            PopulateStaticData(model);

            return View(model);
        }
        public ActionResult Edit(FixtureViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    model.Validate();

                    Fixture fixtureToUpdate = fixtureService.Get(model.Fixture.Id);
                    TryUpdateModel(fixtureToUpdate, "Fixture");

                    fixtureToUpdate = model.MapToFixture(
                        fixtureToUpdate,
                        this.competitionService.GetTeamLeagueByTeamIdInCurrentSeason(model.HomeTeamId),
                        this.competitionService.GetTeamLeagueByTeamIdInCurrentSeason(model.AwayTeamId),
                        model.Referee1Id.HasValue ? this.refereeService.Get(model.Referee1Id.Value) : null,
                        model.Referee2Id.HasValue ? this.refereeService.Get(model.Referee2Id.Value) : null,
                        this.membershipService.GetLoggedInUser(),
                        model.OneOffVenueId.HasValue ? oneOffVenueService.Get(model.OneOffVenueId.Value) : null);

                    fixtureService.Save(fixtureToUpdate);
                    fixtureService.Commit();

                    SuccessMessage(FormMessages.SaveSuccess);

                    return RedirectToAction("Index");
                }
            }
            // TODO Create some kind of parent validation exception containing error property
            catch (FixtureTeamsTheSameException)
            {
                ErrorMessage(FormMessages.FixtureTeamsTheSame);
            }
            catch (FixtureRefereesTheSameException)
            {
                ErrorMessage(FormMessages.FixtureRefereesTheSame);
            }

            PopulateStaticData(model);

            return View(model);
        }
        private void PopulateStaticData(FixtureViewModel model)
        {
            // TODO Perhaps get only the teams involved in the cup?
            if(model.Fixture.IsCupFixture)
                model.Teams = teamService.GetTeamsForCurrentSeason().ToSelectList(x => x.ToString(), x => x.Id.ToString(), null);
            else
                model.Teams = teamService.GetTeamsForLeague(model.LeagueOrCupId).ToSelectList(x => x.ToString(), x => x.Id.ToString(), null);

            if(model.Fixture.IsCupFixture)
                model.LeagueOrCupName = cupService.Get(model.LeagueOrCupId).ToString();
            else
                model.LeagueOrCupName = competitionService.GetLeague(model.LeagueOrCupId).ToString();

            model.Referees1 = refereeService.Get(orderBy: q => q.OrderBy(x => x.Forename)).ToSelectListWithHeader(x => x.ToString(), x => x.Id.ToString(), null, "None");
            model.Referees2 = refereeService.Get(orderBy: q => q.OrderBy(x => x.Forename)).ToSelectListWithHeader(x => x.ToString(), x => x.Id.ToString(), null, "None");

            model.OneOffVenues = oneOffVenueService.Get(orderBy: q => q.OrderBy(x => x.Venue)).ToSelectListWithHeader(x => x.ToString(), x => x.Id.ToString(), null, "None");
        }
        public ActionResult Edit(int id)
        {
            FixtureViewModel model = new FixtureViewModel(fixtureService.Get(id));
            model.MapToModel(model.Fixture);

            PopulateStaticData(model);

            return View(model);
        }