Пример #1
0
        public bool SyncCountries([FromBody] Contracts.Models.User model)
        {
            List <Contracts.Models.ApiIntegrations.Country> countries            = _apiCountryAll.GetAllCountries();
            List <Contracts.DataModels.Country>             countryList          = new List <Contracts.DataModels.Country>();
            IEnumerable <Contracts.DataModels.Country>      availableCountryList = _countryRepository.GetAll(null);

            foreach (Contracts.Models.ApiIntegrations.Country itemCountry in countries)
            {
                Contracts.DataModels.Country isCountryExist = availableCountryList.Where(w => w.Name == itemCountry.name).FirstOrDefault();
                try
                {
                    if (isCountryExist == null)
                    {
                        countryList.Add(new Contracts.DataModels.Country
                        {
                            Name           = itemCountry.name,
                            NativeName     = itemCountry.nativeName,
                            AlphaTwoCode   = itemCountry.alpha2Code,
                            AlphaThreeCode = itemCountry.alpha3Code,
                            Capital        = itemCountry.capital,
                            Flags          = itemCountry.flag,
                            Area           = itemCountry.area.ToString(),
                            Region         = itemCountry.region,
                            SubRegion      = itemCountry.subregion,
                            Population     = itemCountry.population,
                            Currency       = Mapper <string> .MapObjectToJsonString(itemCountry.currencies),
                            Language       = Mapper <string> .MapObjectToJsonString(itemCountry.languages),
                            TimeZone       = itemCountry.timezones != null ? itemCountry.timezones[0] : null,
                            CreatedBy      = model.AltId
                        });
                    }
                }
                catch (Exception ex)
                {
                }
            }
            Dapper.DynamicParameters dynamicParameters = new Dapper.DynamicParameters();
            dynamicParameters.Add("@XmlSeatLayout", Serialize <List <Contracts.DataModels.Country> >(countryList), System.Data.DbType.Xml);
            _countryRepository.ExecuteStoredProcedure("spInsertCountries", dynamicParameters);
            _activityHelper.SaveActivity("Country Data Synchronization", "You have performed country data sync opertion on " + DateTime.Now.ToString("ddd, dd MMM yyy HH:mm:ss"), model.AltId);
            return(true);
        }
Пример #2
0
        public bool SyncCountries([FromBody] Contracts.Models.User model)
        {
            List <Contracts.Models.ApiIntegrations.Country> countries = _apiCountryAll.GetAllCountries();

            foreach (var itemCountry in countries)
            {
                try
                {
                    Contracts.DataModels.Country country = _countryRepository.GetByName(itemCountry.name);
                    if (country == null)
                    {
                        country = _countryRepository.Save(new Contracts.DataModels.Country
                        {
                            AltId          = Guid.NewGuid(),
                            Name           = itemCountry.name,
                            AlphaTwoCode   = itemCountry.alpha2Code,
                            AlphaThreeCode = itemCountry.alpha3Code,
                            Capital        = itemCountry.capital,
                            Flags          = itemCountry.flag,
                            TimeZone       = itemCountry.timezones != null ? itemCountry.timezones[0] : null,
                            IsEnabled      = true,
                            CreatedUtc     = DateTime.UtcNow,
                            CreatedBy      = model.AltId
                        });
                    }
                    foreach (var itemCurrency in itemCountry.currencies)
                    {
                        try
                        {
                            Contracts.DataModels.Currency currency = _currencyRepository.GetByCode(itemCurrency.code);
                            if (currency == null)
                            {
                                currency = _currencyRepository.Save(new Contracts.DataModels.Currency
                                {
                                    Name       = itemCurrency.name,
                                    Code       = itemCurrency.code,
                                    Symbol     = itemCurrency.symbol,
                                    IsEnabled  = true,
                                    CreatedUtc = DateTime.UtcNow,
                                    CreatedBy  = model.AltId
                                });
                            }
                            Contracts.DataModels.CountryCurrencyMapping countryCurrencyMapping = _countryCurrencyMappingRepository.GetByContryAndCurrencyId(country.Id, currency.Id);
                            if (countryCurrencyMapping == null)
                            {
                                countryCurrencyMapping = _countryCurrencyMappingRepository.Save(new Contracts.DataModels.CountryCurrencyMapping
                                {
                                    CountryId  = country.Id,
                                    CurrencyId = currency.Id,
                                    IsEnabled  = true,
                                    CreatedUtc = DateTime.UtcNow,
                                    CreatedBy  = model.AltId
                                });
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }

                    foreach (var itemLanguage in itemCountry.languages)
                    {
                        try
                        {
                            Contracts.DataModels.Language language = _languageRepository.GetByName(itemLanguage.name);
                            if (language == null)
                            {
                                language = _languageRepository.Save(new Contracts.DataModels.Language
                                {
                                    Name       = itemLanguage.name,
                                    IsEnabled  = true,
                                    CreatedUtc = DateTime.UtcNow,
                                    CreatedBy  = model.AltId
                                });
                            }
                            Contracts.DataModels.CountryLanguageMapping countryLanguageMapping = _countryLanguageMappingRepository.GetByContryAndLanguageId(country.Id, language.Id);
                            if (countryLanguageMapping == null)
                            {
                                countryLanguageMapping = _countryLanguageMappingRepository.Save(new Contracts.DataModels.CountryLanguageMapping
                                {
                                    CountryId  = country.Id,
                                    LanguageId = language.Id,
                                    IsEnabled  = true,
                                    CreatedUtc = DateTime.UtcNow,
                                    CreatedBy  = model.AltId
                                });
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
            _activityHelper.SaveActivity("Country Data Synchronization", "You have performed country data sync opertion on " + DateTime.UtcNow.ToString() + " (GMT)", model.AltId);
            return(true);
        }