Exemplo n.º 1
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);
        }
        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);
        }
Exemplo n.º 3
0
        public IActionResult CreateCategory(KnowledgebaseCategoryModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageKnowledgebase))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var knowledgebaseCategory = model.ToEntity();
                knowledgebaseCategory.CreatedOnUtc  = DateTime.UtcNow;
                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.InsertKnowledgebaseCategory(knowledgebaseCategory);

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

                _customerActivityService.InsertActivity("CreateKnowledgebaseCategory", knowledgebaseCategory.Id,
                                                        _localizationService.GetResource("ActivityLog.CreateKnowledgebaseCategory"), 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.Added"));
                return(continueEditing ? RedirectToAction("EditCategory", new { knowledgebaseCategory.Id }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }