Exemple #1
0
        /// <summary>
        /// Get topic template view path
        /// </summary>
        /// <param name="topicTemplateId">Topic template identifier</param>
        /// <returns>View path</returns>
        public virtual async Task <string> PrepareTemplateViewPathAsync(int topicTemplateId)
        {
            var template = await _topicTemplateService.GetTopicTemplateByIdAsync(topicTemplateId) ??
                           (await _topicTemplateService.GetAllTopicTemplatesAsync()).FirstOrDefault();

            if (template == null)
            {
                throw new Exception("No default template could be loaded");
            }

            return(template.ViewPath);
        }
        /// <summary>
        /// Prepare paged topic template list model
        /// </summary>
        /// <param name="searchModel">Topic template search model</param>
        /// <returns>Topic template list model</returns>
        public virtual async Task <TopicTemplateListModel> PrepareTopicTemplateListModelAsync(TopicTemplateSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get topic templates
            var topicTemplates = (await _topicTemplateService.GetAllTopicTemplatesAsync()).ToPagedList(searchModel);

            //prepare grid model
            var model = new TopicTemplateListModel().PrepareToGrid(searchModel, topicTemplates,
                                                                   () => topicTemplates.Select(template => template.ToModel <TopicTemplateModel>()));

            return(model);
        }
Exemple #3
0
        public virtual async Task <IActionResult> TopicTemplateDelete(int id)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageMaintenance))
            {
                return(AccessDeniedView());
            }

            if ((await _topicTemplateService.GetAllTopicTemplatesAsync()).Count == 1)
            {
                return(ErrorJson(await _localizationService.GetResourceAsync("Admin.System.Templates.NotDeleteOnlyOne")));
            }

            //try to get a topic template with the specified id
            var template = await _topicTemplateService.GetTopicTemplateByIdAsync(id)
                           ?? throw new ArgumentException("No template found with the specified id");

            await _topicTemplateService.DeleteTopicTemplateAsync(template);

            return(new NullJsonResult());
        }