Exemplo n.º 1
0
        public async Task <IEnumerable <Country> > GetCountriesAsync()
        {
            var countries = await listsRepository.GetCountriesAsync();

            return(countries.Select(c => new Country {
                Code = c.era_countrycode, Name = c.era_name
            }).OrderBy(c => c.Name));
        }
Exemplo n.º 2
0
        private async Task <Submission> ResolveEntitiesReferences(Submission submission)
        {
            var countries      = (await cachedListsProvider.GetCountriesAsync()).ToArray();
            var stateProvinces = (await cachedListsProvider.GetStateProvincesAsync()).ToArray();
            var jurisdictions  = (await cachedListsProvider.GetJurisdictionsAsync()).ToArray();
            var supports       = (await cachedListsProvider.GetSupportsAsync()).ToArray();

            foreach (var supplierInformation in submission.Suppliers)
            {
                var cityCode = supplierInformation?.Address?.CityCode;
                if (cityCode != null)
                {
                    var jurisdiction = jurisdictions.SingleOrDefault(j => j.era_jurisdictionid.Equals(cityCode, StringComparison.OrdinalIgnoreCase));
                    if (jurisdiction == null)
                    {
                        throw new ValidationException($"City code '{cityCode}' doesn't exists in Dynamics");
                    }
                    supplierInformation.Address.CityCode = jurisdiction.era_jurisdictionid;
                }

                var stateProvinceCode = supplierInformation?.Address?.StateProvinceCode;
                if (stateProvinceCode != null)
                {
                    var stateProvince = stateProvinces.SingleOrDefault(sp => sp.era_code.Equals(stateProvinceCode, StringComparison.OrdinalIgnoreCase));
                    if (stateProvince == null)
                    {
                        throw new ValidationException($"StateProvinceCode '{stateProvinceCode}' doesn't exists in Dynamics");
                    }
                    supplierInformation.Address.StateProvinceCode = stateProvince.era_provinceterritoriesid;
                }

                var countryCode = supplierInformation?.Address?.CountryCode;
                if (countryCode != null)
                {
                    var country = countries.SingleOrDefault(c => c.era_countrycode.Equals(supplierInformation.Address?.CountryCode, StringComparison.OrdinalIgnoreCase));
                    if (country == null)
                    {
                        throw new ValidationException($"CountryCode '{supplierInformation?.Address?.CountryCode}' doesn't exists in Dynamics");
                    }
                    supplierInformation.Address.CountryCode = country.era_countryid;
                }
            }

            foreach (var lineItem in submission.LineItems)
            {
                var support = supports.SingleOrDefault(s => s.era_name.Equals(lineItem?.SupportProvided, StringComparison.OrdinalIgnoreCase));
                if (support == null)
                {
                    throw new ValidationException($"in line item referral '{lineItem?.ReferralNumber}', SupportProvided '{lineItem?.SupportProvided}' is null or doesn't exists in Dynamics");
                }
                lineItem.SupportProvided = support.era_supportid;
            }

            return(submission);
        }