コード例 #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 void AddTest()
        {
            var count = _memoryDbContext.Localizations.Count();
            var localizationCreateModel = Builder <LocalizationCreateModel> .CreateNew()
                                          .With(c => c.LanguageId = LanguageId)
                                          .Build();

            Assert.IsTrue(_localizationService.Add(localizationCreateModel));
            Assert.IsTrue(_memoryDbContext.Localizations.Count() == count + 1);
        }
コード例 #3
0
        public static void AddOrUpdatePluginLocaleResource(this BasePlugin plugin,
                                                           ILocalizationService localizationService, ILanguagesService languageService,
                                                           string resourceName, string resourceValue, string languageISO = null)
        {
            //actually plugin instance is not required
            if (plugin == null)
            {
                throw new ArgumentNullException(nameof(plugin));
            }
            if (localizationService == null)
            {
                throw new ArgumentNullException(nameof(localizationService));
            }
            if (languageService == null)
            {
                throw new ArgumentNullException(nameof(languageService));
            }

            foreach (var lang in languageService.GetAsEnumerable())
            {
                if (!string.IsNullOrEmpty(languageISO) && !languageISO.Equals(lang.IsoCode))
                {
                    continue;
                }

                var lsr = localizationService.FindByName(resourceName, lang.Id);
                if (lsr == null)
                {
                    lsr = new TblLocalizedStrings()
                    {
                        LanguageId    = lang.Id,
                        ResourceName  = resourceName,
                        ResourceValue = resourceValue
                    };
                    localizationService.Add(lsr);
                }
                else
                {
                    lsr.ResourceValue = resourceValue;
                    localizationService.Update(lsr);
                }
            }
        }
コード例 #4
0
 public virtual ActionResult Insert(TblLocalizedStrings value)
 {
     _localizationService.Add(value);
     return(Json(value, JsonRequestBehavior.AllowGet));
 }