コード例 #1
0
        public IActionResult Create([FromForm] LocalizationCreateModel entity)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    AuditedEntityMapper <LocalizationCreateModel> .FillCountryEntityField(entity, CountryId);

                    bool statusResult = _localizationService.Add(entity);
                    if (statusResult)
                    {
                        return(RedirectToAction(nameof(Index)).WithSuccess(LOCALIZATION_SUCCESS_DEFAULT));
                    }
                    else
                    {
                        return(RedirectToAction(nameof(Index)).WithError(LOCALIZATION_ERROR_DEFAULT));
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, ex.Message);
                    return(RedirectToAction(nameof(Index)).WithError(ex.Message));
                }
            }

            ViewBag.Languages = _languageService.GetAllAsLookup(CountryId);
            return(View(entity).WithWarning(LOCALIZATION_WARNING_INVALID_MODELSTATE));
        }
コード例 #2
0
        public static async Task ImportLocalizations(IServiceProvider serviceProvider, IConfiguration configuration)
        {
            var logger = serviceProvider.GetRequiredService <ILogger <SeedExtension> >();

            logger.LogInformation("importing localizations start");

            try
            {
                var _countryService = serviceProvider.GetService <ICountryService>();
                var countries       = _countryService.GetAll();
                if (countries != null)
                {
                    foreach (var country in countries)
                    {
                        var _languageService = serviceProvider.GetService <ILanguageService>();
                        foreach (var countryLanguage in _languageService.GetAll(country.ID))
                        {
                            string      defaultLanguage    = configuration["DefaultLanguage:Value"];
                            CultureInfo defaultCultureInfo = new CultureInfo(defaultLanguage);
                            if (countryLanguage.CultureId == defaultCultureInfo.LCID)
                            {
                                var language              = _languageService.GetByCultureId(defaultCultureInfo.LCID, country.ID);
                                var _localizationService  = serviceProvider.GetService <ILocalizationService>();
                                var firstItemInDictionary = localizations.First();

                                if (!(_localizationService.GetByKey(firstItemInDictionary.Key, language.CultureId)
                                      == firstItemInDictionary.Value))
                                {
                                    foreach (KeyValuePair <string, string> localizationItem in localizations)
                                    {
                                        LocalizationCreateModel localization = new LocalizationCreateModel();
                                        localization.CountryId         = country.ID;
                                        localization.LanguageId        = language.ID;
                                        localization.LocalizationKey   = localizationItem.Key;
                                        localization.LocalizationValue = localizationItem.Value;

                                        _localizationService.Add(localization);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogInformation("Import localizations failed." + ex.Message);
                throw new Exception("Import localizations failed. " + ex.Message);
            }
        }
コード例 #3
0
        public bool Add(LocalizationCreateModel entity)
        {
            var language = _languageRepository.Get(entity.LanguageId);

            if (language == null)
            {
                throw new Exception(LOCALIZATION_LOCALIZATIONCLASS_NOT_FOUND);
            }

            Localization localization = new Localization
            {
                LocalizationKey   = entity.LocalizationKey,
                LocalizationValue = entity.LocalizationValue,
                Language          = language,
                CountryId         = entity.CountryId
            };

            return(_repository.Add(localization));
        }