Exemple #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));
        }
        public virtual ActionResult TopicTemplateUpdate(TopicTemplateModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageMaintenance))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                return(Json(new DataSourceResult {
                    Errors = ModelState.SerializeErrors()
                }));
            }

            var template = _topicTemplateService.GetTopicTemplateById(model.Id);

            if (template == null)
            {
                throw new ArgumentException("No template found with the specified id");
            }
            template = model.ToEntity(template);
            _topicTemplateService.UpdateTopicTemplate(template);

            return(new NullJsonResult());
        }
Exemple #3
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));
        }
Exemple #4
0
        public virtual IActionResult TopicTemplateUpdate(TopicTemplateModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new DataSourceResult {
                    Errors = ModelState.SerializeErrors()
                }));
            }

            //try to get a topic template with the specified id
            TopicTemplate template = _topicTemplateService.GetTopicTemplateById(model.Id)
                                     ?? throw new ArgumentException("No template found with the specified id");

            template = model.ToEntity(template);
            _topicTemplateService.UpdateTopicTemplate(template);

            return(new NullJsonResult());
        }
        /// <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);
        }
        public IActionResult TopicTemplateUpdate(TopicTemplateModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new DataSourceResult {
                    Errors = ModelState.SerializeErrors()
                }));
            }

            var template = _topicTemplateService.GetTopicTemplateById(model.Id);

            if (template == null)
            {
                throw new ArgumentException("No template found with the specified id");
            }
            if (ModelState.IsValid)
            {
                template = model.ToEntity(template);
                _topicTemplateService.UpdateTopicTemplate(template);
                return(new NullJsonResult());
            }
            return(ErrorForKendoGridJson(ModelState));
        }
        /// <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);
        }
Exemple #8
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(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);
        }
        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);
        }
        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);
        }
Exemple #11
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));
        }
Exemple #12
0
 /// <summary>
 /// Gets a topic template
 /// </summary>
 /// <param name="topicTemplateId">Topic template identifier</param>
 /// <returns>Topic template</returns>
 public TopicTemplate GetTopicTemplateById(int topicTemplateId)
 {
     return(_topicTemplateService.GetTopicTemplateById(topicTemplateId));
 }