Пример #1
0
 public RankedPersonPoints(int ranking, PersonLicense license, decimal points, IList <PersonTime> times, bool sameRankingAsPrevious = true)
 {
     this.times            = times;
     Ranking               = ranking;
     License               = license;
     Points                = points;
     SameRankingAsPrevious = sameRankingAsPrevious;
 }
Пример #2
0
        public async Task <PersonLicense> AddNewLicenseAsync(string issuerId, string discipline, string key, Person person, int?season, DateTime?validFrom, DateTime?validTo,
                                                             PersonLicenseFlags flags, string category = null, int?number = null, string sponsor = null, Club club = null, string venueCode = null,
                                                             string transponder1 = null, string transponder2 = null)
        {
            var expert = calculatorManager.Find(discipline);

            if (expert == null)
            {
                throw new InvalidDisciplineException();
            }

            season    = season ?? expert.CurrentSeason;
            validFrom = validFrom ?? expert.SeasonStarts(season.Value);
            validTo   = validTo ?? expert.SeasonEnds(season.Value);

            if (category == null)
            {
                var age            = expert.SeasonAge(season.Value, person.BirthDate);
                var personCategory = await GetDefaultCategoryAsync(issuerId, discipline, person.Gender, age);

                category = personCategory?.Code;
            }

            if (venueCode == null && club != null)
            {
                await context.LoadAsync(club, c => c.Venues, c => c.VenueDiscipline == discipline);

                venueCode = club.Venues?.FirstOrDefault(v => v.VenueDiscipline == discipline)?.VenueCode;
            }

            var license = new PersonLicense
            {
                IssuerId     = issuerId,
                Discipline   = discipline,
                Key          = key,
                Season       = season.Value,
                ValidFrom    = validFrom.Value,
                ValidTo      = validTo.Value,
                Sponsor      = sponsor,
                Club         = club,
                Person       = person,
                Category     = category,
                Number       = number,
                Flags        = flags,
                VenueCode    = venueCode,
                Transponder1 = transponder1,
                Transponder2 = transponder2
            };

            context.PersonLicenses.Add(license);
            await context.SaveChangesAsync();

            recorder.RecordEvent(new PersonLicenseChangedEvent(license));
            return(license);
        }
Пример #3
0
 public async Task <bool> HasVenueSubscriptionAsync(PersonLicense license, string venueCode, string venueDiscipline, DateTime?reference = null)
 {
     reference = reference ?? DateTime.UtcNow;
     return(await context.PersonLicenseVenueSubscriptions.AnyAsync(s => s.LicenseIssuerId == license.IssuerId &&
                                                                   s.LicenseDiscipline == license.Discipline &&
                                                                   s.LicenseKey == license.Key &&
                                                                   s.VenueCode == venueCode &&
                                                                   s.VenueDiscipline == venueDiscipline &&
                                                                   s.ValidFrom <= reference.Value &&
                                                                   s.ValidTo > reference.Value));
 }
Пример #4
0
 private async Task PersonLicenseChangedAsync(PersonLicense license)
 {
     using (var workflow = workflowFactory())
         try
         {
             await workflow.UpdateCompetitorsByLicenseAsync(license);
         }
         catch (Exception e)
         {
             Trace.TraceError("Failed to update competitors by license {0}: {1}", license, e.Message);
         }
 }
Пример #5
0
 public async Task <int?> GetPersonLicenseVenueClassAsync(PersonLicense license, string venueCode, string venueDiscipline, DateTime?reference = null)
 {
     reference = reference ?? DateTime.UtcNow;
     return((await context.PersonLicenseVenueClasses
             .Where(c => c.LicenseIssuerId == license.IssuerId &&
                    c.LicenseDiscipline == license.Discipline &&
                    c.LicenseKey == license.Key &&
                    c.VenueCode == venueCode &&
                    c.VenueDiscipline == venueDiscipline &&
                    c.ValidFrom <= reference.Value &&
                    c.ValidTo > reference.Value)
             .Select(c => new {
         c.Class
     }).FirstOrDefaultAsync())?.Class);
 }
Пример #6
0
 public static PersonCompetitor FromLicense(PersonLicense license)
 {
     return(new PersonCompetitor
     {
         LicenseDiscipline = license.Discipline,
         LicenseKey = license.Key,
         LicenseFlags = license.Flags,
         Person = license.Person,
         Name = license.Person.Name,
         Gender = license.Person.Gender,
         Category = license.Category,
         ClubCountryCode = license.Club?.CountryCode,
         ClubCode = license.Club?.Code,
         ClubFullName = license.Club?.FullName,
         ClubShortName = license.Club?.ShortName,
         LegNumber = license.LegNumber,
         NationalityCode = license.Person.NationalityCode,
         VenueCode = license.VenueCode
     });
 }
        public async Task UpdateCompetitorsByLicenseAsync(PersonLicense license)
        {
            var expert = calculatorManager.Find(license.Discipline);

            if (expert == null)
            {
                throw new InvalidDisciplineException();
            }

            using (var transaction = context.BeginTransaction(IsolationLevel.RepeatableRead))
                try
                {
                    context.PersonLicenses.Attach(license);
                    await context.LoadAsync(license, l => l.Club);

                    var competitors = await(from c in Competitors(license.IssuerId, license.Discipline, license.Key)
                                            where c.List.Competition.Starts > DateTime.UtcNow
                                            select c).ToListAsync();
                    foreach (var competitor in competitors)
                    {
                        competitor.Sponsor         = license.Sponsor;
                        competitor.ClubCountryCode = license.ClubCountryCode;
                        competitor.ClubCode        = license.ClubCode;
                        competitor.ClubShortName   = license.Club?.ShortName;
                        competitor.ClubFullName    = license.Club?.FullName;
                        competitor.Category        = license.Category;
                        competitor.StartNumber     = !expert.AutomaticStartNumbers && license.Number.HasValue ? license.Number.Value : competitor.StartNumber;
                        competitor.Transponder1    = license.Transponder1;
                        competitor.Transponder2    = license.Transponder2;
                        await UpdateCompetitorAsync(competitor);
                    }
                    transaction.Commit();
                }
                catch
                {
                    transaction.Rollback();
                    throw;
                }
        }
Пример #8
0
        public async Task <PersonLicense> UpdatePersonLicenseAsync(PersonLicense license, PersonLicenseExpertise expertise, int?season = null,
                                                                   DateTime?validFrom = null, DateTime?validTo = null, string sponsor   = null, Club club           = null, PersonLicenseFlags flags = PersonLicenseFlags.None,
                                                                   string category    = null, int?number       = null, string venueCode = null, string transponder1 = null, string transponder2      = null)
        {
            var expert = calculatorManager.Find(license.Discipline);

            if (expert == null)
            {
                throw new InvalidDisciplineException();
            }

            season = season ?? expert.CurrentSeason;

            using (var transaction = context.UseOrBeginTransaction(IsolationLevel.RepeatableRead))
                try
                {
                    if (license.Season != season.Value)
                    {
                        license.Flags     = flags;
                        license.Season    = season.Value;
                        license.ValidFrom = validFrom ?? expert.SeasonStarts(season.Value);
                        license.ValidTo   = validTo ?? expert.SeasonEnds(season.Value);
                        license.Sponsor   = sponsor;
                        license.Club      = club;

                        if (category == null)
                        {
                            var age            = expert.SeasonAge(season.Value, license.Person.BirthDate);
                            var personCategory = await GetDefaultCategoryAsync(license.IssuerId, license.Discipline, license.Person.Gender, age);

                            license.Category = personCategory?.Code;
                        }
                        else
                        {
                            license.Category = category;
                        }

                        if (expertise.HasFlag(PersonLicenseExpertise.Number))
                        {
                            license.Number = number;
                        }

                        if (venueCode != null)
                        {
                            license.VenueCode = venueCode;
                        }

                        license.Transponder1 = transponder1;
                        license.Transponder2 = transponder2;
                    }
                    else
                    {
                        license.Flags = flags;
                        if (expertise.HasFlag(PersonLicenseExpertise.Validity))
                        {
                            license.ValidFrom = validFrom ?? expert.SeasonStarts(season.Value);
                            license.ValidTo   = validTo ?? expert.SeasonEnds(season.Value);
                        }
                        if (expertise.HasFlag(PersonLicenseExpertise.Sponsor))
                        {
                            license.Sponsor = sponsor;
                        }
                        if (expertise.HasFlag(PersonLicenseExpertise.Club))
                        {
                            license.Club = club;
                        }
                        if (expertise.HasFlag(PersonLicenseExpertise.Category))
                        {
                            if (category == null)
                            {
                                var age            = expert.SeasonAge(season.Value, license.Person.BirthDate);
                                var personCategory = await GetDefaultCategoryAsync(license.IssuerId, license.Discipline, license.Person.Gender, age);

                                license.Category = personCategory?.Code;
                            }
                            else
                            {
                                license.Category = category;
                            }
                        }
                        if (expertise.HasFlag(PersonLicenseExpertise.Number))
                        {
                            license.Number = number;
                        }
                        if (expertise.HasFlag(PersonLicenseExpertise.Venue))
                        {
                            license.VenueCode = venueCode;
                        }
                        if (expertise.HasFlag(PersonLicenseExpertise.Transponders))
                        {
                            license.Transponder1 = transponder1;
                            license.Transponder2 = transponder2;
                        }
                    }

                    await context.SaveChangesAsync();

                    transaction.Commit();
                    recorder.RecordEvent(new PersonLicenseChangedEvent(license));
                }
                catch
                {
                    transaction.Rollback();
                    throw;
                }

            return(license);
        }
Пример #9
0
 public async Task DeletePersonLicenseAsync(PersonLicense license)
 {
     context.PersonLicenses.Remove(license);
     await context.SaveChangesAsync();
 }
 public PersonLicenseChangedEvent(PersonLicense license)
 {
     License = license;
 }
        public async Task <PersonCompetitor> AddNewCompetitorAsync(Competition competition, Guid listId, PersonLicense license, CompetitorStatus status, CompetitorSource source)
        {
            await context.LoadAsync(license, l => l.Club);

            var @class = await LicensesWorkflow.GetPersonLicenseVenueClassAsync(license, competition.VenueCode, competition.Discipline, competition.Starts);

            var competitor = new PersonCompetitor
            {
                ListId            = listId,
                Person            = license.Person,
                Name              = license.Person.Name,
                ShortName         = new string(license.Person.Name.PrefixedSurname.Take(50).ToArray()),
                LicenseDiscipline = license.Discipline,
                LicenseKey        = license.Key,
                LicenseFlags      = license.Flags,
                Gender            = license.Person.Gender,
                Status            = status,
                Category          = license.Category,
                Class             = @class,
                Sponsor           = license.Sponsor,
                ClubCountryCode   = license.ClubCountryCode,
                ClubCode          = license.ClubCode,
                ClubShortName     = license.Club?.ShortName,
                ClubFullName      = license.Club?.FullName,
                From              = license.Person.Address.City,
                StartNumber       = license.Number ?? 0,
                NationalityCode   = license.Person.NationalityCode,
                VenueCode         = license.VenueCode,
                Transponder1      = license.Transponder1,
                Transponder2      = license.Transponder2,
                Source            = source
            };

            await AddCompetitorAsync(competition, competitor);

            return(competitor);
        }
        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 bool IsLicenseExpired(PersonLicense license, Competition competition)
 {
     return(license.ValidTo < competition.Starts || license.ValidFrom >= competition.Starts);
 }