Esempio n. 1
0
        private void UpdateIfDifferentObject(ExcelGameDto dto, GamesCycle ctxModel)
        {
            #region If/Else
            if (ctxModel.StartDate != dto.Date)
            {
                ctxModel.StartDate = dto.Date;
            }

            else if (ctxModel.Auditorium != null && ctxModel.Auditorium.Name != dto.Auditorium)
            {
                ctxModel.StartDate = dto.Date;
            }

            else if (ctxModel.Group != null && ctxModel.Group.Name != dto.Groupe)
            {
                ctxModel.StartDate = dto.Date;
            }

            else if (ctxModel.GuestTeam != null && ctxModel.GuestTeam.Title != dto.GuestTeam)
            {
                ctxModel.StartDate = dto.Date;
            }

            else if (ctxModel.GuestTeamScore != dto.GuestTeamScore)
            {
                ctxModel.StartDate = dto.Date;
            }
            else if (ctxModel.HomeTeamScore != dto.HomeTeamScore)
            {
                ctxModel.StartDate = dto.Date;
            }
            else if (ctxModel.User != null && ctxModel.User.FullName != dto.Referee)
            {
                ctxModel.StartDate = dto.Date;
            }
            else if (ctxModel.HomeTeam != null && ctxModel.HomeTeam.Title != dto.HomeTeam)
            {
                ctxModel.StartDate = dto.Date;
            }
            else if (ctxModel.GameSets.Any())
            {
                var sets = ctxModel.GameSets.ToArray();

                var set1 = sets.Length > 0 && sets[0].HomeTeamScore > 0 && sets[0].GuestTeamScore > 0 ? string.Format("{0} - {1}", sets[0].HomeTeamScore, sets[0].GuestTeamScore) : "";
                var set2 = sets.Length > 1 && sets[1].HomeTeamScore > 0 && sets[1].GuestTeamScore > 0 ? string.Format("{0} - {1}", sets[1].HomeTeamScore, sets[1].GuestTeamScore) : "";
                var set3 = sets.Length > 2 && sets[2].HomeTeamScore > 0 && sets[2].GuestTeamScore > 0 ? string.Format("{0} - {1}", sets[2].HomeTeamScore, sets[2].GuestTeamScore) : "";
                if (set1 != dto.Set1 || set2 != dto.Set2 || set3 != dto.Set3)
                {
                    ctxModel.StartDate = dto.Date;
                }
            }
            #endregion
        }
Esempio n. 2
0
        protected IEnumerable <ExcelGameDto> MapResults(IEnumerable <GamesCycle> gamesList, int?seasonId = null)
        {
            var dtos = new List <ExcelGameDto>();

            foreach (var gc in gamesList)
            {
                var dto = new ExcelGameDto();

                dto.League      = gc.Stage.League.Name;
                dto.LeagueId    = gc.Stage.LeagueId;
                dto.Stage       = gc.Stage.Number;
                dto.Groupe      = (gc.Group != null) ? gc.Group.Name : "";
                dto.CycleNumber = (gc.CycleNum + 1);
                dto.Date        = gc.StartDate;
                dto.HomeTeamId  = gc.HomeTeam != null ? gc.HomeTeam.TeamId : 0;
                dto.GuestTeamId = gc.GuestTeam != null ? gc.GuestTeam.TeamId : 0;
                var section = gc.Stage.League.Season.Union.Section.Alias;
                switch (section)
                {
                case GamesAlias.WaterPolo:
                case GamesAlias.BasketBall:
                    dto.HomeTeamScore  = gc.GameSets.Sum(x => x.HomeTeamScore);
                    dto.GuestTeamScore = gc.GameSets.Sum(x => x.GuestTeamScore);
                    break;

                default:
                    dto.HomeTeamScore  = gc.HomeTeamScore;
                    dto.GuestTeamScore = gc.GuestTeamScore;
                    break;
                }
                dto.GameId = gc.CycleId;
                dto.Time   = gc.StartDate.ToString("HH:mm");

                if (seasonId.HasValue)
                {
                    var homeTeamDetails = gc.HomeTeam?.TeamsDetails.FirstOrDefault(t => t.SeasonId == seasonId.Value);
                    if (homeTeamDetails != null)
                    {
                        dto.HomeTeam = homeTeamDetails.TeamName;
                    }
                    else
                    {
                        dto.HomeTeam = gc.HomeTeam?.Title ?? "";
                    }

                    var guesTeamDetails = gc.GuestTeam?.TeamsDetails.FirstOrDefault(t => t.SeasonId == seasonId.Value);
                    if (guesTeamDetails != null)
                    {
                        dto.GuestTeam = guesTeamDetails.TeamName;
                    }
                    else
                    {
                        dto.GuestTeam = gc.GuestTeam?.Title ?? "";
                    }
                }
                else
                {
                    dto.HomeTeam  = gc.HomeTeam != null ? gc.HomeTeam.Title : "";
                    dto.GuestTeam = gc.GuestTeam != null ? gc.GuestTeam.Title : "";
                }

                if (gc.GameSets.Any())
                {
                    var sets = gc.GameSets.ToArray();

                    dto.Set1 = sets.Length > 0 && sets[0].HomeTeamScore > 0 && sets[0].GuestTeamScore > 0 ? string.Format("{0} - {1}", sets[0].HomeTeamScore, sets[0].GuestTeamScore) : "";
                    dto.Set2 = sets.Length > 1 && sets[1].HomeTeamScore > 0 && sets[1].GuestTeamScore > 0 ? string.Format("{0} - {1}", sets[1].HomeTeamScore, sets[1].GuestTeamScore) : "";
                    dto.Set3 = sets.Length > 2 && sets[2].HomeTeamScore > 0 && sets[2].GuestTeamScore > 0 ? string.Format("{0} - {1}", sets[2].HomeTeamScore, sets[2].GuestTeamScore) : "";
                    dto.Set4 = sets.Length > 3 && sets[3].HomeTeamScore > 0 && sets[3].GuestTeamScore > 0 ? string.Format("{0} - {1}", sets[3].HomeTeamScore, sets[3].GuestTeamScore) : "";
                }

                if (gc.AuditoriumId.HasValue)
                {
                    dto.Auditorium   = gc.Auditorium.Name;
                    dto.AuditoriumId = gc.AuditoriumId.Value;
                }
                if (gc.RefereeId.HasValue)
                {
                    dto.Referee   = gc.User.FullName;
                    dto.RefereeId = gc.RefereeId.Value;
                }


                dtos.Add(dto);
            }

            return(dtos);
        }