public ScoringTableDataDTO MapToScoringTableDataDTO(ScoringTableEntity source, ScoringTableDataDTO target = null) { if (source == null) { return(null); } if (target == null) { target = new ScoringTableDataDTO(); } MapToScoringTableInfoDTO(source, target); target.AverageRaceNr = source.AverageRaceNr; target.DropWeeks = source.DropWeeks; target.ScoringFactors = source.ScoringFactors; target.ScoringKind = source.ScoringKind; target.ScoringIds = source.Scorings.Select(x => x.ScoringId).ToArray(); target.SeasonId = source.SeasonId; // MapToSeasonInfoDTO(source.Season); target.SessionIds = source.Sessions.Select(x => x.SessionId).ToArray(); target.DropRacesOption = source.DropRacesOption; target.ResultsPerRaceCount = source.ResultsPerRaceCount; return(target); }
public ScoringTableInfoDTO MapToScoringTableInfoDTO(ScoringTableEntity source, ScoringTableInfoDTO target = null) { if (source == null) { return(null); } if (target == null) { target = new ScoringTableInfoDTO(); } MapToVersionInfoDTO(source, target); target.ScoringTableId = source.ScoringTableId; target.Name = source.Name; return(target); }
public ScoringTableDataDTO MapToScoringTableDataDTO(ScoringTableEntity source, ScoringTableDataDTO target = null) { if (source == null) { return(null); } if (target == null) { target = new ScoringTableDataDTO(); } MapToScoringTableInfoDTO(source, target); target.AverageRaceNr = source.AverageRaceNr; target.DropWeeks = source.DropWeeks; target.ScoringFactors = source.ScoringFactors; target.Scorings = source.Scorings.Select(x => MapToScoringInfoDTO(x)).ToArray(); target.Season = MapToSeasonInfoDTO(source.Season); target.Sessions = source.Sessions.Select(x => MapToSessionInfoDTO(x)).ToArray(); return(target); }
public ScoringTableEntity MapToScoringTableEntity(ScoringTableDataDTO source, ScoringTableEntity target = null) { if (source == null) { return(null); } if (target == null) { target = GetScoringTableEntity(source); } if (MapToRevision(source, target) == false) { return(target); } target.DropWeeks = source.DropWeeks; target.Name = source.Name; target.ScoringKind = source.ScoringKind; target.AverageRaceNr = source.AverageRaceNr; target.ScoringFactors = source.ScoringFactors; if (target.Scorings == null) { target.Scorings = new List <ScoringEntity>(); } MapCollection(source.ScoringIds.Select(x => new ScoringInfoDTO() { ScoringId = x }), target.Scorings, GetScoringEntity, x => x.Keys, removeFromCollection: true); target.ResultsPerRaceCount = source.ResultsPerRaceCount; target.DropRacesOption = source.DropRacesOption; return(target); }
public ScoringTableEntity MapToScoringTableEntity(ScoringTableDataDTO source, ScoringTableEntity target = null) { if (source == null) { return(null); } if (target == null) { target = GetScoringTableEntity(source); } if (MapToRevision(source, target) == false) { return(target); } target.DropWeeks = source.DropWeeks; target.Name = source.Name; target.ScoringFactors = source.ScoringFactors; if (target.Scorings == null) { target.Scorings = new List <ScoringEntity>(); } MapCollection(source.Scorings, target.Scorings, GetScoringEntity, x => x.Keys, removeFromCollection: true); return(target); }
public StandingsDataDTO[] GetStandings(long[][] requestIds) { var mapper = new DTOMapper(DbContext); DbContext.Configuration.LazyLoadingEnabled = false; List <StandingsDataDTO> responseItems = new List <StandingsDataDTO>(); List <long> loadedScoringEntityIds = new List <long>(); foreach (var requestId in requestIds) { var scoringTableId = requestId[0]; var sessionId = requestId.Count() > 1 ? requestId[1] : 0; ScoringTableEntity scoringTable = null; try { scoringTable = DbContext.Set <ScoringTableEntity>() .Where(x => x.ScoringTableId == scoringTableId) .Include(x => x.Scorings.Select(y => y.ExtScoringSource)) //.Include(x => x.Scorings.Select(y => y.Sessions.Select(z => z.SessionResult))) //.Include(x => x.Scorings.Select(y => y.ScoredResults.Select(z => z.FinalResults.Select(q => q.ResultRow.Member)))) //.Include(x => x.Scorings.Select(y => y.ExtScoringSource.ScoredResults.Select(z => z.FinalResults.Select(q => q.ResultRow.Member)))) .FirstOrDefault(); var loadScoringEntityIds = DbContext.Set <ScoringEntity>().Local.Select(y => y.ScoringId).Except(loadedScoringEntityIds); if (loadScoringEntityIds.Count() > 0) { var loadScorings = DbContext.Set <ScoringEntity>() .Where(x => loadScoringEntityIds.Contains(x.ScoringId)) .Include(x => x.Sessions.Select(y => y.SessionResult)) .ToList(); var loadScoredResults = DbContext.Set <ScoredResultEntity>() .Where(x => loadScoringEntityIds.Contains(x.ScoringId)) .Include(x => x.FinalResults.Select(y => y.ResultRow.Member)) .Include(x => x.FinalResults.Select(y => y.Team)) .ToList(); } DbContext.ChangeTracker.DetectChanges(); } catch (Exception e) { throw new Exception("Error while getting data from Database.", e); } try { if (scoringTable != null) { StandingsEntity standings; if (sessionId == 0) { standings = scoringTable.GetSeasonStandings(DbContext); } else { var scoringSession = scoringTable.GetAllSessions().SingleOrDefault(x => x.SessionId == sessionId); if (scoringSession == null) { var session = DbContext.Set <SessionBaseEntity>().Find(sessionId); scoringSession = scoringTable.GetAllSessions().LastOrDefault(x => x.Date <= session?.Date); } standings = scoringTable.GetSeasonStandings(scoringSession, DbContext); } var standingsDTO = mapper.MapTo <StandingsDataDTO>(standings); responseItems.Add(standingsDTO); } } catch (Exception e) { throw new Exception("Error while mapping data.", e); } } DbContext.Configuration.LazyLoadingEnabled = true; return(responseItems.ToArray()); }