コード例 #1
0
        public ActionResult TopicDetails(int topicId)
        {
            var cacheKey = string.Format(ModelCacheEventConsumer.TOPIC_MODEL_BY_ID_KEY,
                                         topicId,
                                         _workContext.WorkingLanguage.Id,
                                         _storeContext.CurrentStore.Id,
                                         string.Join(",", _workContext.CurrentCustomer.GetCustomerRoleIds()));
            var cacheModel = _cacheManager.Get(cacheKey, () =>
            {
                var topic = _topicService.GetTopicById(topicId);
                if (topic == null)
                {
                    return(null);
                }
                if (!topic.Published)
                {
                    return(null);
                }
                //Store mapping
                if (!_storeMappingService.Authorize(topic))
                {
                    return(null);
                }
                //ACL (access control list)
                if (!_aclService.Authorize(topic))
                {
                    return(null);
                }
                return(PrepareTopicModel(topic));
            });

            if (cacheModel == null)
            {
                return(RedirectToRoute("HomePage"));
            }

            //template
            var templateCacheKey = string.Format(ModelCacheEventConsumer.TOPIC_TEMPLATE_MODEL_KEY, cacheModel.TopicTemplateId);
            var templateViewPath = _cacheManager.Get(templateCacheKey, () =>
            {
                var template = _topicTemplateService.GetTopicTemplateById(cacheModel.TopicTemplateId);
                if (template == null)
                {
                    template = _topicTemplateService.GetAllTopicTemplates().FirstOrDefault();
                }
                if (template == null)
                {
                    throw new Exception("No default template could be loaded");
                }
                return(template.ViewPath);
            });

            //display "edit" (manage) link
            if (_permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel) && _permissionService.Authorize(StandardPermissionProvider.ManageTopics))
            {
                DisplayEditLink(Url.Action("Edit", "Topic", new { id = cacheModel.Id, area = "Admin" }));
            }

            return(View(templateViewPath, cacheModel));
        }
コード例 #2
0
        public ActionResult TopicDetails(int topicId)
        {
            var cacheKey = string.Format(ModelCacheEventConsumer.TOPIC_MODEL_BY_ID_KEY,
                                         topicId,
                                         _workContext.WorkingLanguage.Id,
                                         _storeContext.CurrentStore.Id,
                                         string.Join(",", _workContext.CurrentCustomer.GetCustomerRoleIds()));
            var cacheModel = _cacheManager.Get(cacheKey, () =>
            {
                var topic = _topicService.GetTopicById(topicId);
                if (topic == null)
                {
                    return(null);
                }
                //Store mapping
                if (!_storeMappingService.Authorize(topic))
                {
                    return(null);
                }
                //ACL (access control list)
                if (!_aclService.Authorize(topic))
                {
                    return(null);
                }

                return(PrepareTopicModel(topic));
            }
                                               );

            if (cacheModel == null)
            {
                return(RedirectToRoute("HomePage"));
            }

            //template
            var templateCacheKey = string.Format(ModelCacheEventConsumer.TOPIC_TEMPLATE_MODEL_KEY, cacheModel.TopicTemplateId);
            var templateViewPath = _cacheManager.Get(templateCacheKey, () =>
            {
                var template = _topicTemplateService.GetTopicTemplateById(cacheModel.TopicTemplateId);
                if (template == null)
                {
                    template = _topicTemplateService.GetAllTopicTemplates().FirstOrDefault();
                }
                if (template == null)
                {
                    throw new Exception("No default template could be loaded");
                }
                return(template.ViewPath);
            });

            return(View(templateViewPath, cacheModel));
        }
コード例 #3
0
        /// <summary>
        /// Get topic template view path
        /// </summary>
        /// <param name="topicTemplateId">Topic template identifier</param>
        /// <returns>View path</returns>
        public virtual string PrepareTemplateViewPath(int topicTemplateId)
        {
            var template = _topicTemplateService.GetTopicTemplateById(topicTemplateId) ??
                           _topicTemplateService.GetAllTopicTemplates().FirstOrDefault();

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

            return(template.ViewPath);
        }
コード例 #4
0
        public async Task <IActionResult> TopicTemplates(DataSourceRequest command)
        {
            var templatesModel = (await _topicTemplateService.GetAllTopicTemplates())
                                 .Select(x => x.ToModel())
                                 .ToList();
            var gridModel = new DataSourceResult
            {
                Data  = templatesModel,
                Total = templatesModel.Count
            };

            return(Json(gridModel));
        }
コード例 #5
0
        /// <summary>
        /// Prepare paged topic template list model
        /// </summary>
        /// <param name="searchModel">Topic template search model</param>
        /// <returns>Topic template list model</returns>
        public virtual TopicTemplateListModel PrepareTopicTemplateListModel(TopicTemplateSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

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

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

            return(model);
        }
コード例 #6
0
        public virtual async Task PrepareTemplatesModel(TopicModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var templates = await _topicTemplateService.GetAllTopicTemplates();

            foreach (var template in templates)
            {
                model.AvailableTopicTemplates.Add(new SelectListItem
                {
                    Text  = template.Name,
                    Value = template.Id.ToString()
                });
            }
        }
コード例 #7
0
        public virtual ActionResult TopicTemplates(DataSourceRequest command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageMaintenance))
            {
                return(AccessDeniedKendoGridJson());
            }

            var templatesModel = _topicTemplateService.GetAllTopicTemplates()
                                 .Select(x => x.ToModel())
                                 .ToList();
            var gridModel = new DataSourceResult
            {
                Data  = templatesModel,
                Total = templatesModel.Count
            };

            return(Json(gridModel));
        }
コード例 #8
0
        protected virtual void PrepareTemplatesModel(TopicModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var templates = _topicTemplateService.GetAllTopicTemplates();

            foreach (var template in templates)
            {
                model.AvailableTopicTemplates.Add(new SelectListItem
                {
                    Text  = template.Name,
                    Value = template.Id.ToString()
                });
            }
        }
コード例 #9
0
ファイル: TopicModelFactory.cs プロジェクト: wzh9801/src
        /// <summary>
        /// Get topic template view path
        /// </summary>
        /// <param name="topicTemplateId">Topic template identifier</param>
        /// <returns>View path</returns>
        public virtual string PrepareTemplateViewPath(int topicTemplateId)
        {
            var templateCacheKey = string.Format(ModelCacheEventConsumer.TOPIC_TEMPLATE_MODEL_KEY, topicTemplateId);
            var templateViewPath = _cacheManager.Get(templateCacheKey, () =>
            {
                var template = _topicTemplateService.GetTopicTemplateById(topicTemplateId);
                if (template == null)
                {
                    template = _topicTemplateService.GetAllTopicTemplates().FirstOrDefault();
                }
                if (template == null)
                {
                    throw new Exception("No default template could be loaded");
                }
                return(template.ViewPath);
            });

            return(templateViewPath);
        }
コード例 #10
0
        public async Task <string> Handle(GetTopicTemplateViewPath request, CancellationToken cancellationToken)
        {
            var templateCacheKey = string.Format(ModelCacheEventConst.TOPIC_TEMPLATE_MODEL_KEY, request.TemplateId);
            var templateViewPath = await _cacheManager.GetAsync(templateCacheKey, async() =>
            {
                var template = await _topicTemplateService.GetTopicTemplateById(request.TemplateId);
                if (template == null)
                {
                    template = (await _topicTemplateService.GetAllTopicTemplates()).FirstOrDefault();
                }
                if (template == null)
                {
                    throw new Exception("No default template could be loaded");
                }
                return(template.ViewPath);
            });

            return(templateViewPath);
        }
コード例 #11
0
        public virtual async Task <string> PrepareTopicTemplateViewPath(string templateId)
        {
            var templateCacheKey = string.Format(ModelCacheEventConst.TOPIC_TEMPLATE_MODEL_KEY, templateId);
            var templateViewPath = await _cacheManager.GetAsync(templateCacheKey, async() =>
            {
                var template = await _topicTemplateService.GetTopicTemplateById(templateId);
                if (template == null)
                {
                    template = (await _topicTemplateService.GetAllTopicTemplates()).FirstOrDefault();
                }
                if (template == null)
                {
                    throw new Exception("No default template could be loaded");
                }
                return(template.ViewPath);
            });

            return(templateViewPath);
        }
コード例 #12
0
        /// <summary>
        /// Return a template part for a given reference
        /// </summary>
        /// <param name="systemName">Topic System name (created in admin)</param>
        /// <returns>View, a partial html page</returns>
        public ActionResult TopicPartial(string systemName)
        {
            var cacheKey = string.Format(ModelCacheEventConsumer.TOPIC_MODEL_BY_SYSTEMNAME_KEY,
                                         systemName,
                                         _workContext.WorkingLanguage.Id,
                                         _storeContext.CurrentStore.Id,
                                         string.Join(",", _workContext.CurrentCustomer.GetCustomerRoleIds()));
            var cacheModel = _cacheManager.Get(cacheKey, () =>
            {
                var topic = _topicService.GetTopicBySystemName(systemName, _storeContext.CurrentStore.Id);
                if (topic == null)
                {
                    return(null);
                }

                return(PrepareTopicModel(topic));
            }
                                               );

            if (cacheModel == null)
            {
                return(PartialView("~/Plugins/Misc.Solutions/Views/Solutions/Shared/NoContent.cshtml"));
            }

            //template
            var templateCacheKey = string.Format(ModelCacheEventConsumer.TOPIC_TEMPLATE_MODEL_KEY, cacheModel.TopicTemplateId);
            var templateViewPath = _cacheManager.Get(templateCacheKey, () =>
            {
                var template = _topicTemplateService.GetTopicTemplateById(cacheModel.TopicTemplateId);
                if (template == null)
                {
                    template = _topicTemplateService.GetAllTopicTemplates().FirstOrDefault();
                }
                if (template == null)
                {
                    throw new Exception("No default template could be loaded");
                }
                return(template.ViewPath);
            });

            return(PartialView(templateViewPath, cacheModel));
        }
コード例 #13
0
        /// <summary>
        /// Prepare paged topic template list model
        /// </summary>
        /// <param name="searchModel">Topic template search model</param>
        /// <returns>Topic template list model</returns>
        public virtual TopicTemplateListModel PrepareTopicTemplateListModel(TopicTemplateSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get topic templates
            var topicTemplates = _topicTemplateService.GetAllTopicTemplates();

            //prepare grid model
            var model = new TopicTemplateListModel
            {
                //fill in model values from the entity
                Data  = topicTemplates.PaginationByRequestModel(searchModel).Select(template => template.ToModel <TopicTemplateModel>()),
                Total = topicTemplates.Count
            };

            return(model);
        }
コード例 #14
0
        /// <summary>
        /// Prepare available topic templates
        /// </summary>
        /// <param name="items">Topic template items</param>
        /// <param name="withSpecialDefaultItem">Whether to insert the first special item for the default value</param>
        /// <param name="defaultItemText">Default item text; pass null to use default value of the default item text</param>
        public virtual void PrepareTopicTemplates(IList <SelectListItem> items, bool withSpecialDefaultItem = true, string defaultItemText = null)
        {
            if (items == null)
            {
                throw new ArgumentNullException(nameof(items));
            }

            //prepare available topic templates
            var availableTemplates = _topicTemplateService.GetAllTopicTemplates();

            foreach (var template in availableTemplates)
            {
                items.Add(new SelectListItem {
                    Value = template.Id.ToString(), Text = template.Name
                });
            }

            //insert special item for the default value
            PrepareDefaultItem(items, withSpecialDefaultItem, defaultItemText);
        }
コード例 #15
0
        /// <summary>
        /// Get topic template view path
        /// </summary>
        /// <param name="topicTemplateId">Topic template identifier</param>
        /// <returns>View path</returns>
        public virtual string PrepareTemplateViewPath(int topicTemplateId)
        {
            var templateCacheKey = string.Format(NopModelCacheDefaults.TopicTemplateModelKey, topicTemplateId);
            var templateViewPath = _cacheManager.Get(templateCacheKey, () =>
            {
                var template = _topicTemplateService.GetTopicTemplateById(topicTemplateId) ?? _topicTemplateService.GetAllTopicTemplates().FirstOrDefault();
                if (template == null)
                {
                    throw new Exception("No default template could be loaded");
                }

                return(template.ViewPath);
            });

            return(templateViewPath);
        }
コード例 #16
0
ファイル: TopicsController.cs プロジェクト: thophamhuu/APIWB
 /// <summary>
 /// Gets all topic templates
 /// </summary>
 /// <returns>Topic templates</returns>
 public IList <TopicTemplate> GetAllTopicTemplates()
 {
     return(_topicTemplateService.GetAllTopicTemplates());
 }