public async Task <IPersonLicenseTime> FindHistoricalTimeAsync(string licenseIssuerId, string discipline, string distanceDiscipline, int distanceValue, string licenseKey, params IHistoricalTimeSelector[] selectors) { var expert = calculatorManager.Find(discipline); if (expert == null) { throw new InvalidDisciplineException(); } var query = Query(licenseIssuerId, discipline, distanceDiscipline, distanceValue, licenseKey); foreach (var selector in selectors) { PersonTime time = null; var personTimeSelector = selector as IPersonTimeSelector; if (personTimeSelector != null) { time = await personTimeSelector.Query(expert, query).OrderBy(pt => pt.Time).FirstOrDefaultAsync(); } if (time != null) { return(time); } } return(null); }
public async Task ExportAsync(Guid competitionId, Stream stream, CultureInfo culture) { using (var context = contextFactory()) using (var writer = new StreamWriter(stream, Encoding.UTF8)) { var competition = await context.Competitions.Where(c => c.Id == competitionId).FirstOrDefaultAsync(); if (competition == null) { return; } var calculator = calculatorManager.Find(competition.Discipline); if (calculator == null) { return; } switch (calculator.PrimaryGroup) { case PrimaryGroup.Distances: await ExportDistancesAsync(competition, writer, culture, context); break; case PrimaryGroup.DistanceCombinations: await ExportDistanceCombinationsAsync(competition, writer, culture, context); break; } } }
public async Task <PersonLicensePrice> GetCompetitionLicenseRenewalPriceAsync(Competition competition, PersonLicense license) { if (!IsLicenseExpired(license, competition) && !license.Flags.HasFlag(PersonLicenseFlags.TemporaryLicense)) { return(null); } var expert = calculatorManager.Find(competition.Discipline); if (expert == null) { throw new InvalidDisciplineException(); } var age = license.Flags.HasFlag(PersonLicenseFlags.TemporaryLicense) ? license.Person.BirthDate.Age() : expert.SeasonAge(expert.Season(competition.Starts), license.Person.BirthDate); return(await LicensesWorkflow.GetPersonLicensePriceAsync(competition.LicenseIssuerId, competition.Discipline, license.Person.Gender, age, license.Flags)); }
public Task <PersonCategory> GetDefaultCategoryAsync(string issuerId, string discipline, Gender gender, DateTime birthDate, DateTime?reference = null) { var expert = calculatorManager.Find(discipline); if (expert == null) { throw new InvalidDisciplineException(); } var season = reference.HasValue ? expert.Season(reference.Value) : expert.CurrentSeason; var age = expert.SeasonAge(season, birthDate); return(GetDefaultCategoryAsync(issuerId, discipline, gender, age)); }
private async Task UpdateCompetitorBestTimesAsync(Distance distance, Race race) { var personCompetitor = race.Competitor as PersonCompetitor; if (personCompetitor == null) { return; } await context.LoadAsync(distance, d => d.Competition); var expert = calculatorManager.Find(distance.Competition.Discipline); if (expert == null) { return; } var previousRaces = await(from r in context.Races.Include(r => r.Results).Include(r => r.Times) where r.Distance.CompetitionId == distance.CompetitionId && r.Distance.Number < distance.Number && r.Distance.Discipline == distance.Discipline && r.Distance.Value == distance.Value && r.Distance.ValueQuantity == distance.ValueQuantity && r.CompetitorId == race.Competitor.Id select r).ToListAsync(); var previousFastest = (from t in previousRaces where t.PresentedTime != null orderby t.PresentedTime.Time select new TimeSpan?(t.PresentedTime.Time)).FirstOrDefault(); var seasonStarts = expert.SeasonStarts(expert.CurrentSeason); var seasonEnds = expert.SeasonEnds(expert.CurrentSeason); var seasonBest = await personTimesWorkflow.FindHistoricalTimeAsync(distance.Competition.LicenseIssuerId, distance.Competition.Discipline, distance.Discipline, distance.Value, race.Competitor.LicenseKey, new SeasonBestSelector(seasonStarts, seasonEnds)); race.SeasonBest = previousFastest != null && seasonBest != null ? (previousFastest.Value < seasonBest.Time ? previousFastest.Value : seasonBest?.Time) : (seasonBest?.Time ?? previousFastest); var personalBest = await personTimesWorkflow.FindHistoricalTimeAsync(distance.Competition.LicenseIssuerId, distance.Competition.Discipline, distance.Discipline, distance.Value, race.Competitor.LicenseKey, new PersonalBestSelector()); race.PersonalBest = previousFastest != null && personalBest != null ? (previousFastest.Value < personalBest.Time ? previousFastest.Value : personalBest?.Time) : (personalBest?.Time ?? previousFastest); }