public ViewResult TeamFixtureList(int?id)
        {
            IEnumerable <Fixture> fixtures;
            IEnumerable <Fixture> janFixtures;
            IEnumerable <Fixture> febFixtures;
            IEnumerable <Fixture> marchFixtures;
            IEnumerable <Fixture> aprilFixtures;
            IEnumerable <Fixture> mayFixtures;
            IEnumerable <Fixture> juneFixtures;
            IEnumerable <Fixture> julyFixtures;
            IEnumerable <Fixture> augustFixtures;
            IEnumerable <Fixture> septemberFixtures;
            IEnumerable <Fixture> octoberFixtures;
            IEnumerable <Fixture> novemberFixtures;
            IEnumerable <Fixture> decemberFixtures;
            string currentTeam;
            int    teamID;
            int    totalWins;
            int    totalDraws;
            int    totalLosses;
            int    goalsFor;
            int    goalsAgainst;
            int    gamesPlayed;

            if (id == null)
            {
                fixtures          = _fixtureRepository.AllFixtures.OrderBy(p => p.TeamID);
                janFixtures       = _fixtureRepository.JanuaryFixtures.OrderBy(p => p.TeamID);
                febFixtures       = _fixtureRepository.FebruaryFixtures.OrderBy(p => p.TeamID);
                marchFixtures     = _fixtureRepository.MarchFixtures.OrderBy(p => p.TeamID);
                aprilFixtures     = _fixtureRepository.AprilFixtures.OrderBy(p => p.TeamID);
                mayFixtures       = _fixtureRepository.MayFixtures.OrderBy(p => p.TeamID);
                juneFixtures      = _fixtureRepository.JuneFixtures.OrderBy(p => p.TeamID);
                julyFixtures      = _fixtureRepository.JulyFixtures.OrderBy(p => p.TeamID);
                augustFixtures    = _fixtureRepository.AugustFixtures.OrderBy(p => p.TeamID);
                septemberFixtures = _fixtureRepository.SeptemberFixtures.OrderBy(p => p.TeamID);
                octoberFixtures   = _fixtureRepository.OctoberFixtures.OrderBy(p => p.TeamID);
                novemberFixtures  = _fixtureRepository.NovemberFixtures.OrderBy(p => p.TeamID);
                decemberFixtures  = _fixtureRepository.DecemberFixtures.OrderBy(p => p.TeamID);
                currentTeam       = "All Teams";
                teamID            = 1;
                totalWins         = 0;
                totalDraws        = 0;
                totalLosses       = 0;
                goalsFor          = 0;
                goalsAgainst      = 0;
                gamesPlayed       = 0;
            }
            else
            {
                fixtures = _fixtureRepository.AllFixtures.Where(p => p.TeamID == id)
                           .OrderBy(p => p.FixtureDate);
                janFixtures = _fixtureRepository.JanuaryFixtures.Where(p => p.TeamID == id)
                              .OrderBy(p => p.FixtureDate);
                febFixtures = _fixtureRepository.FebruaryFixtures.Where(p => p.TeamID == id)
                              .OrderBy(p => p.FixtureDate);
                marchFixtures = _fixtureRepository.MarchFixtures.Where(p => p.TeamID == id)
                                .OrderBy(p => p.FixtureDate);
                aprilFixtures = _fixtureRepository.AprilFixtures.Where(p => p.TeamID == id)
                                .OrderBy(p => p.FixtureDate);
                mayFixtures = _fixtureRepository.MayFixtures.Where(p => p.TeamID == id)
                              .OrderBy(p => p.FixtureDate);
                juneFixtures = _fixtureRepository.JuneFixtures.Where(p => p.TeamID == id)
                               .OrderBy(p => p.FixtureDate);
                julyFixtures = _fixtureRepository.JulyFixtures.Where(p => p.TeamID == id)
                               .OrderBy(p => p.FixtureDate);
                augustFixtures = _fixtureRepository.AugustFixtures.Where(p => p.TeamID == id)
                                 .OrderBy(p => p.FixtureDate);
                septemberFixtures = _fixtureRepository.SeptemberFixtures.Where(p => p.TeamID == id)
                                    .OrderBy(p => p.FixtureDate);
                octoberFixtures = _fixtureRepository.OctoberFixtures.Where(p => p.TeamID == id)
                                  .OrderBy(p => p.FixtureDate);
                novemberFixtures = _fixtureRepository.NovemberFixtures.Where(p => p.TeamID == id)
                                   .OrderBy(p => p.FixtureDate);
                decemberFixtures = _fixtureRepository.DecemberFixtures.Where(p => p.TeamID == id)
                                   .OrderBy(p => p.FixtureDate);
                currentTeam  = _teamRepository.Teams.FirstOrDefault(c => c.TeamID == id)?.Name;
                teamID       = id.Value;
                totalWins    = _fixtureRepository.TotalWins(id);
                totalDraws   = _fixtureRepository.TotalDraws(id);
                totalLosses  = _fixtureRepository.TotalLosses(id);
                goalsFor     = _fixtureRepository.GoalsFor(id);
                goalsAgainst = _fixtureRepository.GoalsAgainst(id);
                gamesPlayed  = (totalWins + totalDraws + totalLosses);
            }
            return(View(new FixtureListViewModel
            {
                Fixtures = fixtures,
                CurrentTeam = currentTeam,
                TeamID = teamID,
                JanuaryFixtures = janFixtures,
                FebruaryFixtures = febFixtures,
                MarchFixtures = marchFixtures,
                AprilFixtures = aprilFixtures,
                MayFixtures = mayFixtures,
                JuneFixtures = juneFixtures,
                JulyFixtures = julyFixtures,
                AugustFixtures = augustFixtures,
                SeptemberFixtures = septemberFixtures,
                OctoberFixtures = octoberFixtures,
                NovemberFixtures = novemberFixtures,
                DecemberFixtures = decemberFixtures,
                Teams = _teamRepository.Teams,
                TotalWins = totalWins,
                TotalDraws = totalDraws,
                TotalLosses = totalLosses,
                GoalsFor = goalsFor,
                GoalsAgainst = goalsAgainst,
                GamesPlayed = gamesPlayed
            }));
        }
Beispiel #2
0
        public void Index_TestTeamStats()
        {
            //Arrange
            IFixtureRepository sut     = GetInMemoryFixtureRepository();
            Fixture            fixture = new Fixture()
            {
                TeamID            = 1,
                FixtureID         = 1,
                FixtureDate       = DateTime.Parse("2020-01-01"),
                FixtureType       = FixtureType.Cup,
                Opponent          = "Leeds",
                ResultDescription = ResultDescription.Win,
                OurScore          = 3,
                OpponentScore     = 1,
                HomeOrAway        = HomeOrAway.Home,
                Location          = "Bushy Park",
                MeetLocation      = "Bushy Park Entrance",
                MeetTime          = DateTime.Parse("2020-01-01"),
                MatchReport       = "This was a good game.... "
            };
            Fixture fixture2 = new Fixture()
            {
                TeamID            = 1,
                FixtureID         = 2,
                FixtureDate       = DateTime.Parse("2020-02-02"),
                FixtureType       = FixtureType.Cup,
                Opponent          = "Team2",
                ResultDescription = ResultDescription.Win,
                OurScore          = 3,
                OpponentScore     = 1,
                HomeOrAway        = HomeOrAway.Home,
                Location          = "Bushy Park",
                MeetLocation      = "Bushy Park Entrance",
                MeetTime          = DateTime.Parse("2020-01-01"),
                MatchReport       = "This was a good game.... "
            };
            Fixture fixture3 = new Fixture()
            {
                TeamID            = 1,
                FixtureID         = 3,
                FixtureDate       = DateTime.Parse("2020-01-01"),
                FixtureType       = FixtureType.Cup,
                Opponent          = "Team3",
                ResultDescription = ResultDescription.Win,
                OurScore          = 3,
                OpponentScore     = 1,
                HomeOrAway        = HomeOrAway.Home,
                Location          = "Bushy Park",
                MeetLocation      = "Bushy Park Entrance",
                MeetTime          = DateTime.Parse("2020-01-01"),
                MatchReport       = "This was a good game.... "
            };
            Fixture fixture4 = new Fixture()
            {
                TeamID            = 1,
                FixtureID         = 4,
                FixtureDate       = DateTime.Parse("2020-01-01"),
                FixtureType       = FixtureType.Cup,
                Opponent          = "Team4",
                ResultDescription = ResultDescription.Loss,
                OurScore          = 1,
                OpponentScore     = 2,
                HomeOrAway        = HomeOrAway.Home,
                Location          = "Bushy Park",
                MeetLocation      = "Bushy Park Entrance",
                MeetTime          = DateTime.Parse("2020-01-01"),
                MatchReport       = "This was a good game.... "
            };

            //Act
            Fixture savedFixture  = sut.CreateFixture(fixture);
            Fixture savedFixture2 = sut.CreateFixture(fixture2);
            Fixture savedFixture3 = sut.CreateFixture(fixture3);
            Fixture savedFixture4 = sut.CreateFixture(fixture4);

            //Assert
            Assert.Equal(3, sut.JanuaryFixtures.Count());
            Assert.Equal(3, sut.TotalWins(1));
            Assert.Equal(0, sut.TotalDraws(1));
            Assert.Equal(1, sut.TotalLosses(1));
            Assert.Equal(10, sut.GoalsFor(1));
            Assert.Equal(5, sut.GoalsAgainst(1));
        }