Exemple #1
0
        public void AddLocalization(LocalizedStringFull localizedString)
        {
            _localizationRepository
            .Add(
                _mapper.Map <LocalizedStringFull, Localization>(localizedString)
                );
            _localizationRepository
            .Save();

            var cacheKey = _GetCacheKey(localizedString.Culture, localizedString.Key);

            _cache
            .Remove(cacheKey);
        }
        protected override ActionResult Add()
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (var scope = new UnitOfWorkScope())
                    {
                        Localization localization = _repository.GetLocalizationByKey(GridModel.Key);
                        if (localization != null)
                        {
                            throw new DuplicateKeyException();
                        }

                        localization = new Localization(GridModel.Key, GridModel.Value, GridModel.JavaScript, GridModel.Language);

                        _repository.Save(localization);
                        scope.Commit();
                    }
                    return(Json(GridModel));
                }
            }
            catch (DuplicateKeyException)
            {
                ModelState.AddModelError(string.Empty, string.Format("localization with name {0} already exists in the system.", GridModel.Key));
            }

            throw CreateModelException(GridModel);
        }