Esempio n. 1
0
        public async Task <IActionResult> EditCategory(KnowledgebaseCategoryModel model, bool continueEditing)
        {
            var knowledgebaseCategory = await _knowledgebaseService.GetKnowledgebaseCategory(model.Id);

            if (knowledgebaseCategory == null)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                knowledgebaseCategory = await _knowledgebaseViewModelService.UpdateKnowledgebaseCategoryModel(knowledgebaseCategory, model);

                SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.Knowledgebase.KnowledgebaseCategory.Updated"));
                return(continueEditing ? RedirectToAction("EditCategory", new { id = knowledgebaseCategory.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            await _knowledgebaseViewModelService.PrepareCategory(model);

            //Stores
            await model.PrepareStoresMappingModel(knowledgebaseCategory, _storeService, true);

            //ACL
            await model.PrepareACLModel(knowledgebaseCategory, true, _customerService);

            return(View(model));
        }
        public async Task <IViewComponentResult> InvokeAsync(KnowledgebaseHomePageModel model)
        {
            if (!_knowledgebaseSettings.Enabled)
            {
                return(Content(""));
            }

            var categories = await _knowledgebaseService.GetPublicKnowledgebaseCategories();

            foreach (var category in categories)
            {
                if (string.IsNullOrEmpty(category.ParentCategoryId))
                {
                    var newNode = new KnowledgebaseCategoryModel
                    {
                        Id        = category.Id,
                        Name      = category.GetTranslation(y => y.Name, _workContext.WorkingLanguage.Id),
                        Children  = new List <KnowledgebaseCategoryModel>(),
                        IsCurrent = model.CurrentCategoryId == category.Id,
                        SeName    = category.GetTranslation(y => y.SeName, _workContext.WorkingLanguage.Id)
                    };

                    FillChildNodes(newNode, categories, model.CurrentCategoryId);

                    model.Categories.Add(newNode);
                }
            }

            return(View(model));
        }
        public IViewComponentResult Invoke(KnowledgebaseHomePageModel model)
        {
            if (!_knowledgebaseSettings.Enabled)
            {
                return(Content(""));
            }

            var categories = _knowledgebaseService.GetPublicKnowledgebaseCategories();

            foreach (var category in categories)
            {
                if (string.IsNullOrEmpty(category.ParentCategoryId))
                {
                    var newNode = new KnowledgebaseCategoryModel
                    {
                        Id        = category.Id,
                        Name      = category.GetLocalized(y => y.Name),
                        Children  = new List <KnowledgebaseCategoryModel>(),
                        IsCurrent = model.CurrentCategoryId == category.Id,
                        SeName    = category.GetLocalized(y => y.SeName)
                    };

                    FillChildNodes(newNode, categories, model.CurrentCategoryId);

                    model.Categories.Add(newNode);
                }
            }

            return(View(model));
        }
        public void FillChildNodes(KnowledgebaseCategoryModel parentNode, List <KnowledgebaseCategory> nodes, string currentCategoryId)
        {
            var children = nodes.Where(x => x.ParentCategoryId == parentNode.Id);

            foreach (var child in children)
            {
                var newNode = new KnowledgebaseCategoryModel
                {
                    Id        = child.Id,
                    Name      = child.GetLocalized(y => y.Name),
                    Children  = new List <KnowledgebaseCategoryModel>(),
                    IsCurrent = currentCategoryId == child.Id,
                    SeName    = child.GetLocalized(y => y.SeName),
                    Parent    = parentNode
                };

                if (newNode.IsCurrent)
                {
                    MarkParentsAsCurrent(newNode);
                }

                FillChildNodes(newNode, nodes, currentCategoryId);

                parentNode.Children.Add(newNode);
            }
        }
Esempio n. 5
0
        public virtual KnowledgebaseCategoryModel PrepareKnowledgebaseCategoryModel()
        {
            var model = new KnowledgebaseCategoryModel();

            PrepareCategory(model);
            return(model);
        }
 public void MarkParentsAsCurrent(KnowledgebaseCategoryModel node)
 {
     if (node.Parent != null)
     {
         node.Parent.IsCurrent = true;
         MarkParentsAsCurrent(node.Parent);
     }
 }
Esempio n. 7
0
        public virtual async Task <KnowledgebaseCategoryModel> PrepareKnowledgebaseCategoryModel()
        {
            var model = new KnowledgebaseCategoryModel();

            await PrepareCategory(model);

            return(model);
        }
Esempio n. 8
0
        public async Task <IActionResult> CreateCategory(KnowledgebaseCategoryModel model, bool continueEditing)
        {
            if (ModelState.IsValid)
            {
                var knowledgebaseCategory = await _knowledgebaseViewModelService.InsertKnowledgebaseCategoryModel(model);

                Success(_translationService.GetResource("Admin.Content.Knowledgebase.KnowledgebaseCategory.Added"));
                return(continueEditing ? RedirectToAction("EditCategory", new { knowledgebaseCategory.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 9
0
        public IActionResult EditCategory(KnowledgebaseCategoryModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageKnowledgebase))
            {
                return(AccessDeniedView());
            }

            var knowledgebaseCategory = _knowledgebaseService.GetKnowledgebaseCategory(model.Id);

            if (knowledgebaseCategory == null)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                knowledgebaseCategory = model.ToEntity(knowledgebaseCategory);
                knowledgebaseCategory.UpdatedOnUtc  = DateTime.UtcNow;
                knowledgebaseCategory.Locales       = UpdateLocales(knowledgebaseCategory, model);
                knowledgebaseCategory.CustomerRoles = model.SelectedCustomerRoleIds != null?model.SelectedCustomerRoleIds.ToList() : new List <string>();

                model.SeName = knowledgebaseCategory.ValidateSeName(model.SeName, knowledgebaseCategory.Name, true);
                knowledgebaseCategory.SeName = model.SeName;
                knowledgebaseCategory.Stores = model.SelectedStoreIds != null?model.SelectedStoreIds.ToList() : new List <string>();

                _knowledgebaseService.UpdateKnowledgebaseCategory(knowledgebaseCategory);

                _urlRecordService.SaveSlug(knowledgebaseCategory, model.SeName, "");

                _customerActivityService.InsertActivity("UpdateKnowledgebaseCategory", knowledgebaseCategory.Id,
                                                        _localizationService.GetResource("ActivityLog.UpdateKnowledgebaseCategory"), knowledgebaseCategory.Name);

                model.AvailableCustomerRoles = _customerService
                                               .GetAllCustomerRoles(true)
                                               .Select(cr => cr.ToModel())
                                               .ToList();
                model.AvailableStores = _storeService
                                        .GetAllStores()
                                        .Select(s => s.ToModel())
                                        .ToList();

                SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.Knowledgebase.KnowledgebaseCategory.Updated"));
                return(continueEditing ? RedirectToAction("EditCategory", new { id = knowledgebaseCategory.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
        public IActionResult CreateCategory(KnowledgebaseCategoryModel model, bool continueEditing)
        {
            if (ModelState.IsValid)
            {
                var knowledgebaseCategory = _knowledgebaseViewModelService.InsertKnowledgebaseCategoryModel(model);
                SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.Knowledgebase.KnowledgebaseCategory.Added"));
                return(continueEditing ? RedirectToAction("EditCategory", new { knowledgebaseCategory.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            //Stores
            model.PrepareStoresMappingModel(null, true, _storeService);
            //ACL
            model.PrepareACLModel(null, true, _customerService);
            return(View(model));
        }
Esempio n. 11
0
        public virtual void PrepareCategory(KnowledgebaseCategoryModel model)
        {
            model.Categories.Add(new SelectListItem {
                Text = "[None]", Value = ""
            });
            var categories = _knowledgebaseService.GetKnowledgebaseCategories();

            foreach (var category in categories)
            {
                model.Categories.Add(new SelectListItem
                {
                    Value = category.Id,
                    Text  = category.GetFormattedBreadCrumb(categories)
                });
            }
        }
Esempio n. 12
0
        public virtual KnowledgebaseCategory InsertKnowledgebaseCategoryModel(KnowledgebaseCategoryModel model)
        {
            var knowledgebaseCategory = model.ToEntity();

            knowledgebaseCategory.CreatedOnUtc = DateTime.UtcNow;
            knowledgebaseCategory.UpdatedOnUtc = DateTime.UtcNow;
            knowledgebaseCategory.Locales      = model.Locales.ToLocalizedProperty(knowledgebaseCategory, x => x.Name, _urlRecordService);
            model.SeName = knowledgebaseCategory.ValidateSeName(model.SeName, knowledgebaseCategory.Name, true);
            knowledgebaseCategory.SeName = model.SeName;
            _knowledgebaseService.InsertKnowledgebaseCategory(knowledgebaseCategory);

            _urlRecordService.SaveSlug(knowledgebaseCategory, model.SeName, "");

            _customerActivityService.InsertActivity("CreateKnowledgebaseCategory", knowledgebaseCategory.Id,
                                                    _localizationService.GetResource("ActivityLog.CreateKnowledgebaseCategory"), knowledgebaseCategory.Name);
            return(knowledgebaseCategory);
        }
Esempio n. 13
0
        public async Task <IActionResult> EditCategory(KnowledgebaseCategoryModel model, bool continueEditing)
        {
            var knowledgebaseCategory = await _knowledgebaseService.GetKnowledgebaseCategory(model.Id);

            if (knowledgebaseCategory == null)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                knowledgebaseCategory = await _knowledgebaseViewModelService.UpdateKnowledgebaseCategoryModel(knowledgebaseCategory, model);

                Success(_translationService.GetResource("Admin.Content.Knowledgebase.KnowledgebaseCategory.Updated"));
                return(continueEditing ? RedirectToAction("EditCategory", new { id = knowledgebaseCategory.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            await _knowledgebaseViewModelService.PrepareCategory(model);

            return(View(model));
        }
Esempio n. 14
0
        public IActionResult CreateCategory()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageKnowledgebase))
            {
                return(AccessDeniedView());
            }

            var model = new KnowledgebaseCategoryModel();

            model.Categories.Add(new SelectListItem {
                Text = "[None]", Value = ""
            });
            var categories = _knowledgebaseService.GetKnowledgebaseCategories();

            foreach (var category in categories)
            {
                model.Categories.Add(new SelectListItem
                {
                    Value = category.Id,
                    Text  = category.GetFormattedBreadCrumb(categories)
                });
            }

            model.AvailableCustomerRoles = _customerService
                                           .GetAllCustomerRoles(true)
                                           .Select(cr => cr.ToModel())
                                           .ToList();
            model.Published       = true;
            model.AvailableStores = _storeService
                                    .GetAllStores()
                                    .Select(s => s.ToModel())
                                    .ToList();

            AddLocales(_languageService, model.Locales);
            return(View(model));
        }
Esempio n. 15
0
        protected virtual List <LocalizedProperty> UpdateLocales(KnowledgebaseCategory category, KnowledgebaseCategoryModel model)
        {
            List <LocalizedProperty> localized = new List <LocalizedProperty>();

            foreach (var local in model.Locales)
            {
                var seName = category.ValidateSeName(local.SeName, local.Name, false);
                _urlRecordService.SaveSlug(category, seName, local.LanguageId);

                if (!(String.IsNullOrEmpty(local.Name)))
                {
                    localized.Add(new LocalizedProperty()
                    {
                        LanguageId  = local.LanguageId,
                        LocaleKey   = "Name",
                        LocaleValue = local.Name,
                    });
                }

                if (!(String.IsNullOrEmpty(local.Description)))
                {
                    localized.Add(new LocalizedProperty()
                    {
                        LanguageId  = local.LanguageId,
                        LocaleKey   = "Description",
                        LocaleValue = local.Description,
                    });
                }

                if (!(String.IsNullOrEmpty(local.MetaDescription)))
                {
                    localized.Add(new LocalizedProperty()
                    {
                        LanguageId  = local.LanguageId,
                        LocaleKey   = "MetaDescription",
                        LocaleValue = local.MetaDescription,
                    });
                }

                if (!(String.IsNullOrEmpty(local.MetaKeywords)))
                {
                    localized.Add(new LocalizedProperty()
                    {
                        LanguageId  = local.LanguageId,
                        LocaleKey   = "MetaKeywords",
                        LocaleValue = local.MetaKeywords,
                    });
                }

                if (!(String.IsNullOrEmpty(local.MetaTitle)))
                {
                    localized.Add(new LocalizedProperty()
                    {
                        LanguageId  = local.LanguageId,
                        LocaleKey   = "MetaTitle",
                        LocaleValue = local.MetaTitle,
                    });
                }

                if (!(String.IsNullOrEmpty(seName)))
                {
                    localized.Add(new LocalizedProperty()
                    {
                        LanguageId  = local.LanguageId,
                        LocaleKey   = "SeName",
                        LocaleValue = seName,
                    });
                }
            }

            return(localized);
        }
Esempio n. 16
0
 public static KnowledgebaseCategory ToEntity(this KnowledgebaseCategoryModel model, KnowledgebaseCategory destination)
 {
     return(model.MapTo(destination));
 }
Esempio n. 17
0
 public static KnowledgebaseCategory ToEntity(this KnowledgebaseCategoryModel model)
 {
     return(model.MapTo <KnowledgebaseCategoryModel, KnowledgebaseCategory>());
 }
        public virtual async Task <KnowledgebaseCategory> UpdateKnowledgebaseCategoryModel(KnowledgebaseCategory knowledgebaseCategory, KnowledgebaseCategoryModel model)
        {
            knowledgebaseCategory = model.ToEntity(knowledgebaseCategory);
            knowledgebaseCategory.UpdatedOnUtc = DateTime.UtcNow;
            knowledgebaseCategory.Locales      = await model.Locales.ToLocalizedProperty(knowledgebaseCategory, x => x.Name, _seoSettings, _urlRecordService, _languageService);

            model.SeName = await knowledgebaseCategory.ValidateSeName(model.SeName, knowledgebaseCategory.Name, true, _seoSettings, _urlRecordService, _languageService);

            knowledgebaseCategory.SeName = model.SeName;
            await _knowledgebaseService.UpdateKnowledgebaseCategory(knowledgebaseCategory);

            await _urlRecordService.SaveSlug(knowledgebaseCategory, model.SeName, "");

            await _customerActivityService.InsertActivity("UpdateKnowledgebaseCategory", knowledgebaseCategory.Id,
                                                          _localizationService.GetResource("ActivityLog.UpdateKnowledgebaseCategory"), knowledgebaseCategory.Name);

            return(knowledgebaseCategory);
        }