示例#1
0
        protected virtual void UpdateLocales(TopicCategory topic, TopicCategoryModel model)
        {
            foreach (var localized in model.Locales)
            {
                _localizedEntityService.SaveLocalizedValue(topic,
                                                           x => x.Name,
                                                           localized.Name,
                                                           localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(topic,
                                                           x => x.MetaKeywords,
                                                           localized.MetaKeywords,
                                                           localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(topic,
                                                           x => x.MetaDescription,
                                                           localized.MetaDescription,
                                                           localized.LanguageId);

                _localizedEntityService.SaveLocalizedValue(topic,
                                                           x => x.MetaTitle,
                                                           localized.MetaTitle,
                                                           localized.LanguageId);
            }
        }
示例#2
0
        public virtual IActionResult EditCategory(TopicCategoryModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageTopics))
            {
                return(AccessDeniedView());
            }

            //try to get a topic with the specified id
            var topic = _topicService.GetTopicCategoryById(model.Id);

            if (topic == null)
            {
                return(RedirectToAction("ListCategory"));
            }

            if (ModelState.IsValid)
            {
                topic = model.ToEntity(topic);
                _topicService.UpdateTopicCategory(topic);

                //locales
                UpdateLocales(topic, model);

                SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.TopicCategories.Updated"));

                //activity log
                _customerActivityService.InsertActivity("EditTopicCategory",
                                                        string.Format(_localizationService.GetResource("ActivityLog.EditTopic"), topic.Name), topic);

                if (!continueEditing)
                {
                    return(RedirectToAction("ListCategory"));
                }

                //selected tab
                SaveSelectedTabName();

                return(RedirectToAction("EditCategory", new { id = topic.Id }));
            }

            //prepare model
            model = _topicModelFactory.PrepareTopicCategoryModel(model, topic, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
示例#3
0
        public virtual TopicCategoryModel PrepareTopicCategoryModel(TopicCategoryModel model, TopicCategory topic, bool excludeProperties = false)
        {
            Action <TopicCategoryLocalizedModel, int> localizedModelConfiguration = null;

            if (topic != null)
            {
                //fill in model values from the entity
                model = model ?? topic.ToModel <TopicCategoryModel>();

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name            = _localizationService.GetLocalized(topic, entity => entity.Name, languageId, false, false);
                    locale.MetaKeywords    = _localizationService.GetLocalized(topic, entity => entity.MetaKeywords, languageId, false, false);
                    locale.MetaDescription = _localizationService.GetLocalized(topic, entity => entity.MetaDescription, languageId, false, false);
                    locale.MetaTitle       = _localizationService.GetLocalized(topic, entity => entity.MetaTitle, languageId, false, false);
                };
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
            }

            model.TopicCategories.Add(new TopicCategory()
            {
                Id = 0, Name = "ROOT"
            });
            _topicService
            .GetAllTopicCategories()
            .Where(x => x.Id != topic?.Id)
            .ToList()
            .ForEach(x => model.TopicCategories.Add(x));

            return(model);
        }