示例#1
0
        private static async Task ImportPeopleAsync(IVantageContext context, ICollection <Person> people)
        {
            var identifiers    = people.Select(p => p.Id);
            var existingPeople = await(from p in context.Persons.Include(p => p.Licenses)
                                       where identifiers.Contains(p.Id)
                                       select p).ToListAsync();

            foreach (var item in from np in people
                     join ep in existingPeople on np.Id equals ep.Id into g
                     from ep in g.DefaultIfEmpty()
                     select new
            {
                New = np,
                Existing = ep
            })
            {
                if (item.Existing == null)
                {
                    context.Persons.Add(item.New);
                }
                else
                {
                    Mapper.Map(item.New, item.Existing);
                    foreach (var license in from nl in item.New.Licenses
                             join el in item.Existing.Licenses on new
                    {
                        nl.IssuerId,
                        nl.Discipline,
                        nl.Key
                    } equals new
                    {
                        el.IssuerId,
                        el.Discipline,
                        el.Key
                    } into g
                             from el in g.DefaultIfEmpty()
                             select new
                    {
                        New = nl,
                        Existing = el
                    })
                    {
                        if (license.Existing == null)
                        {
                            context.PersonLicenses.Add(license.New);
                        }
                        else
                        {
                            Mapper.Map(license.New, license.Existing);
                        }
                    }
                }
            }
            await context.SaveChangesAsync();
        }
        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);
        }
 public async Task AddTransponderAsync(Transponder transponder)
 {
     context.Transponders.Add(transponder);
     await context.SaveChangesAsync();
 }
示例#4
0
 public async Task AddAsync(ReportTemplate template)
 {
     context.ReportTemplates.Add(template);
     await context.SaveChangesAsync();
 }
示例#5
0
 public async Task AddClubAsync(Club club)
 {
     context.Clubs.Add(club);
     await context.SaveChangesAsync();
 }