public async Task ExportAsync(Guid competitionId, Stream stream, CultureInfo culture) { var data = new VantageSyncData(); using (var context = contextFactory()) { data.Competition = await context.Competitions .Include(c => c.ReportTemplate.Logos) .Include(c => c.CompetitorLists.Select(cl => cl.Competitors.Select(co => co.DistanceCombinations))) .Include(c => c.Distances.Select(d => d.Races.Select(r => r.Results))) .Include(c => c.Distances.Select(d => d.Races.Select(r => r.Times))) .Include(c => c.Distances.Select(d => d.Races.Select(r => r.Laps))) .Include(c => c.Distances.Select(d => d.Races.Select(r => r.Passings))) .Include(c => c.Distances.Select(d => d.DistancePointsTable.Points)) .Include(c => c.DistanceCombinations.Select(dc => dc.Distances)) .FirstOrDefaultAsync(c => c.Id == competitionId); await context.TeamCompetitorMembers .Include(tcm => tcm.Member) .Where(tcm => tcm.Team.List.CompetitionId == competitionId).LoadAsync(); var projection = await context.Competitors.OfType <PersonCompetitor>() .Where(p => p.List.CompetitionId == competitionId) .Select(p => new { p.Person, Licenses = p.Person.Licenses.Where(l => p.List.Competition.Discipline.StartsWith(l.Discipline)) }) .ToListAsync(); data.People = projection.Select(p => p.Person).ToList(); } VantageXml.Save(data, stream); }
public async Task ImportAsync(Guid competitionId, string name, Stream stream, CultureInfo cultureInfo) { var data = VantageXml.Load(stream); using (var context = contextFactory()) using (var transaction = context.BeginTransaction(IsolationLevel.Serializable)) try { if (data.Competition != null) { var competition = await context.Competitions.FirstOrDefaultAsync(c => c.Id == competitionId); if (competition == null) { throw new CompetitionNotFoundException(); } if (data.Competition.Id != competitionId) { throw new VantageImportException(Resources.CompetitionIdDoesNotMatch); } await ImportCompetitionResultsAsync(context, competition, data.Competition); } transaction.Commit(); } catch { transaction.Rollback(); throw; } }
public async Task ImportAsync(string name, Stream stream, bool importPeople = true, Func <Competition, int> overrideClass = null) { var data = VantageXml.Load(stream); var competition = data.Competition; if (competition != null && overrideClass != null) { competition.Class = overrideClass(competition); } using (var context = contextFactory()) using (var transaction = context.BeginTransaction(IsolationLevel.Serializable)) try { if (data.People != null && importPeople) { await ImportPeopleAsync(context, data.People); } if (competition != null) { var current = await context.Competitions.FirstOrDefaultAsync(c => c.Id == competition.Id); if (current != null) { await ImportCompetitionResultsAsync(context, current, competition); } else { await ImportReportTemplateAsync(context, competition); context.Competitions.Add(competition); await context.SaveChangesAsync(); } } transaction.Commit(); } catch { transaction.Rollback(); throw; } }