예제 #1
0
 private static void AddByeWeekTeams(UserWeeklySchedule schedule, UserTeamStatus team, IQueryable<UserWeeklySchedule> week, int weekNumber)
 {
     foreach (var byeWeekTeam in week.Where(w => w.TeamId != schedule.TeamId))
     {
         if (!team.SharedByWeekTeamIds.Contains(new KeyValuePair<int,int>(weekNumber, byeWeekTeam.TeamId)))
         {
             //team.SharedByWeekTeamIds.Add(weekNumber, byeWeekTeam.TeamId);
         }
     }
 }
예제 #2
0
        public IEnumerable<UserTeamStatus> GetUserSchedule(int userId, int week = 1)
        {
            List<UserTeamStatus> teams = new List<UserTeamStatus>();

            //get the schedules
            var schedules = _jeauxContext.UserWeeklySchedule.Where(us => us.UserId == userId);

            Dictionary<int, IQueryable<UserWeeklySchedule>> byeWeekSchedules = new Dictionary<int, IQueryable<UserWeeklySchedule>>();

            //Load the bye weeks
            byeWeekSchedules.Add(1, schedules.Where(s => s.Week1Opponent == string.Empty));
            byeWeekSchedules.Add(2, schedules.Where(s => s.Week2Opponent == string.Empty));
            byeWeekSchedules.Add(3, schedules.Where(s => s.Week3Opponent == string.Empty));
            byeWeekSchedules.Add(4, schedules.Where(s => s.Week4Opponent == string.Empty));
            byeWeekSchedules.Add(5, schedules.Where(s => s.Week5Opponent == string.Empty));
            byeWeekSchedules.Add(6, schedules.Where(s => s.Week6Opponent == string.Empty));
            byeWeekSchedules.Add(7, schedules.Where(s => s.Week7Opponent == string.Empty));
            byeWeekSchedules.Add(8, schedules.Where(s => s.Week8Opponent == string.Empty));
            byeWeekSchedules.Add(9, schedules.Where(s => s.Week9Opponent == string.Empty));
            byeWeekSchedules.Add(10, schedules.Where(s => s.Week10Opponent == string.Empty));
            byeWeekSchedules.Add(11, schedules.Where(s => s.Week11Opponent == string.Empty));
            byeWeekSchedules.Add(12, schedules.Where(s => s.Week12Opponent == string.Empty));
            byeWeekSchedules.Add(13, schedules.Where(s => s.Week13Opponent == string.Empty));
            byeWeekSchedules.Add(14, schedules.Where(s => s.Week14Opponent == string.Empty));
            byeWeekSchedules.Add(15, schedules.Where(s => s.Week15Opponent == string.Empty));

            foreach (var schedule in schedules)
            {
                UserTeamStatus team = new UserTeamStatus();
                team.Schedule = schedule;
                team.TeamInfo = _jeauxContext.COLFOOT_TEAM.First(t => t.TeamID == schedule.TeamId);

                team.SharedByWeekTeamIds = new Dictionary<int,int>();
                team.ByeWeeks = new List<int>();

                foreach(var byeWeek in byeWeekSchedules.Keys.Where(k => k > week))
                {
                    var byeWeekSchedule = byeWeekSchedules[byeWeek];

                    if (byeWeekSchedule.Count(s => s.TeamId == schedule.TeamId) == 1)
                    {
                        team.ByeWeeks.Add(byeWeek);
                    }

                    if (byeWeek < 14 && byeWeekSchedule.Count() > 1 && byeWeekSchedule.Count(s => s.TeamId == schedule.TeamId) == 1)
                    {
                        AddByeWeekTeams(schedule, team, byeWeekSchedule, byeWeek);
                    }
                }

                team.SharesByeWeek = team.SharedByWeekTeamIds.Count > 0;

                teams.Add(team);

            }

            return teams;
        }