Esempio n. 1
0
        protected void ProcessPersons(IDictionary <int, Person> dbPersons, ProductEntity product,
                                      IEnumerable <Contract.Product.Person> persons)
        {
            foreach (var person in persons)
            {
                if (dbPersons.TryGetValue(person.PersonIdentifier, out var dbPerson))
                {
                    if (!string.Equals(dbPerson.Name, person.Name))
                    {
                        dbPerson.Name = person.Name;
                        _persons.Add(dbPerson);
                    }
                }
                else
                {
                    dbPerson = _mapper.Map <Person>(person);
                    _persons.Add(dbPerson);
                    dbPersons.Add(dbPerson.ExternalIdentifier, dbPerson);
                }

                // Product Person activity period should fit the StartDate <= date < EndDate pattern in the database.
                // Due to the fact that Landmark sends StartDate/EndDate as inclusive dates without time part,
                // the Person activity period is adjusted to fit the pattern above.
                _productPersons.Add(new ProductPerson
                {
                    Product   = product,
                    Person    = dbPerson,
                    StartDate = person.StartDate.Date,
                    EndDate   = person.EndDate.Date.AddDays(1)
                });
            }
        }
Esempio n. 2
0
        protected void ProcessAgencies(
            IDictionary <string, Agency> dbAgencies,
            IDictionary <int, AgencyGroup> dbAgencyGroups,
            ProductEntity product,
            IEnumerable <Contract.Product.Agency> agencies)
        {
            foreach (var agency in agencies)
            {
                AgencyGroup dbAgencyGroup = null;

                if (!(string.IsNullOrEmpty(agency.AgencyGroupShortName) &&
                      string.IsNullOrEmpty(agency.AgencyGroupCode)))
                {
                    var aGroupKey = HashCode.Combine(agency.AgencyGroupShortName?.ToUpperInvariant(),
                                                     agency.AgencyGroupCode?.ToUpperInvariant());

                    if (!dbAgencyGroups.TryGetValue(aGroupKey, out dbAgencyGroup))
                    {
                        dbAgencyGroup = _mapper.Map <AgencyGroup>(agency);
                        dbAgencyGroups.Add(aGroupKey, dbAgencyGroup);
                        _agencyGroups.Add(dbAgencyGroup);
                    }
                }

                if (dbAgencies.TryGetValue(agency.AgencyIdentifier, out var dbAgency))
                {
                    if (!string.Equals(dbAgency.ShortName, agency.ShortName) ||
                        !string.Equals(dbAgency.Name, agency.Name))
                    {
                        dbAgency.Name      = agency.Name;
                        dbAgency.ShortName = agency.ShortName;
                        _agencies.Add(dbAgency);
                    }
                }
                else
                {
                    dbAgency = _mapper.Map <Agency>(agency);
                    _agencies.Add(dbAgency);
                    dbAgencies.Add(dbAgency.ExternalIdentifier, dbAgency);
                }

                // Product Agency activity period should fit the StartDate <= date < EndDate pattern in the database.
                // Due to the fact that Landmark sends StartDate/EndDate as inclusive dates without time part,
                // the Agency activity period is adjusted to fit the pattern above.
                _productAgencies.Add(new ProductAgency
                {
                    Product     = product,
                    Agency      = dbAgency,
                    AgencyGroup = dbAgencyGroup,
                    StartDate   = agency.StartDate.Date,
                    EndDate     = agency.EndDate.Date.AddDays(1)
                });
            }
        }
Esempio n. 3
0
        protected void ProcessAdvertisers(IDictionary <string, Advertiser> dbAdvertisers, ProductEntity product,
                                          IEnumerable <Contract.Product.Advertiser> advertisers)
        {
            foreach (var adv in advertisers)
            {
                if (dbAdvertisers.TryGetValue(adv.AdvertiserIdentifier, out var dbAdv))
                {
                    if (!string.Equals(dbAdv.ShortName, adv.ShortName) || !string.Equals(dbAdv.Name, adv.Name))
                    {
                        dbAdv.Name      = adv.Name;
                        dbAdv.ShortName = adv.ShortName;
                        _advertisers.Add(dbAdv);
                    }
                }
                else
                {
                    dbAdv = _mapper.Map <Advertiser>(adv);
                    _advertisers.Add(dbAdv);
                    dbAdvertisers.Add(dbAdv.ExternalIdentifier, dbAdv);
                }

                // Product Advertiser activity period should fit the StartDate <= date < EndDate pattern in the database.
                // Due to the fact that Landmark sends StartDate/EndDate as inclusive dates without time part,
                // the Advertiser activity period is adjusted to fit the pattern above.
                _productAdvertisers.Add(new ProductAdvertiser
                {
                    Product    = product,
                    Advertiser = dbAdv,
                    StartDate  = adv.StartDate.Date,
                    EndDate    = adv.EndDate.Date.AddDays(1)
                });
            }
        }