示例#1
0
        public async Task <ForumPageModel> BuildForumPageModelAsync(Guid siteId, string slug, QueryOptions options)
        {
            var forum = await _dbContext.Forums
                        .Include(x => x.Category)
                        .FirstOrDefaultAsync(x =>
                                             x.Slug == slug &&
                                             x.Category.SiteId == siteId &&
                                             x.Status == ForumStatusType.Published);

            if (forum == null)
            {
                return(null);
            }

            var result = new ForumPageModel
            {
                Forum = new ForumPageModel.ForumModel
                {
                    Id          = forum.Id,
                    Name        = forum.Name,
                    Description = forum.Description,
                    Slug        = forum.Slug
                },
                Topics = await BuildForumPageModelTopicsAsync(forum.Id, options)
            };

            return(result);
        }
示例#2
0
        public ActionResult Forum(int id, int page = 1)
        {
            if (!_forumSettings.ForumsEnabled)
            {
                return(RedirectToRoute("HomePage"));
            }
            var forum = _forumService.GetForumById(id);

            if (forum != null)
            {
                var model = new ForumPageModel();
                model.Id          = forum.Id;
                model.Name        = forum.Name;
                model.SeName      = forum.GetSeName();
                model.Description = forum.Description;
                int pageSize = _forumSettings.TopicsPageSize > 0 ? _forumSettings.TopicsPageSize : 10;
                if (_forumService.IsCustomerAllowedToSubscribe(_workContext.CurrentCustomer))
                {
                    model.WatchForumText = _localizationService.GetResource("Forum.WatchForum");

                    var forumSubscription = _forumService.GetAllSubscriptions(_workContext.CurrentCustomer.Id, forum.Id, 0, 0, 1).FirstOrDefault();
                    if (forumSubscription != null)
                    {
                        model.WatchForumText = _localizationService.GetResource("Forum.UnwatchForum");
                    }
                }
            }
            return(RedirectToRoute("Boards"));
        }
        /// <summary>
        /// Prepare the forum page model
        /// </summary>
        /// <param name="forum">Forum</param>
        /// <param name="page">Number of forum topics page</param>
        /// <returns>
        /// A task that represents the asynchronous operation
        /// The task result contains the forum page model
        /// </returns>
        public virtual async Task <ForumPageModel> PrepareForumPageModelAsync(Forum forum, int page)
        {
            if (forum == null)
            {
                throw new ArgumentNullException(nameof(forum));
            }

            var model = new ForumPageModel
            {
                Id          = forum.Id,
                Name        = forum.Name,
                SeName      = await _forumService.GetForumSeNameAsync(forum),
                Description = forum.Description
            };

            var pageSize = _forumSettings.TopicsPageSize > 0 ? _forumSettings.TopicsPageSize : 10;

            model.AllowPostVoting = _forumSettings.AllowPostVoting;

            //subscription
            var customer = await _workContext.GetCurrentCustomerAsync();

            if (await _forumService.IsCustomerAllowedToSubscribeAsync(customer))
            {
                model.WatchForumText = await _localizationService.GetResourceAsync("Forum.WatchForum");

                var forumSubscription = (await _forumService.GetAllSubscriptionsAsync(customer.Id, forum.Id, 0, 0, 1)).FirstOrDefault();
                if (forumSubscription != null)
                {
                    model.WatchForumText = await _localizationService.GetResourceAsync("Forum.UnwatchForum");
                }
            }

            var topics = await _forumService.GetAllTopicsAsync(forum.Id, 0, string.Empty, ForumSearchType.All, 0, (page - 1), pageSize);

            model.TopicPageSize     = topics.PageSize;
            model.TopicTotalRecords = topics.TotalCount;
            model.TopicPageIndex    = topics.PageIndex;
            foreach (var topic in topics)
            {
                var topicModel = await PrepareForumTopicRowModelAsync(topic);

                model.ForumTopics.Add(topicModel);
            }
            model.IsCustomerAllowedToSubscribe = await _forumService.IsCustomerAllowedToSubscribeAsync(customer);

            model.ForumFeedsEnabled = _forumSettings.ForumFeedsEnabled;
            model.PostsPageSize     = _forumSettings.PostsPageSize;
            return(model);
        }
示例#4
0
        protected override async Task OnInitializedAsync()
        {
            try
            {
                Model = await ApiService.GetFromJsonAsync <ForumPageModel>($"api/public/forums/{Slug}?page=1");

                TotalPages  = Model.Topics.TotalPages;
                DisplayPage = true;
            }
            catch (Exception)
            {
                Model       = new ForumPageModel();
                DisplayPage = false;
            }
        }
示例#5
0
        /// <summary>
        /// Prepare the forum page model
        /// </summary>
        /// <param name="forum">Forum</param>
        /// <param name="page">Number of forum topics page</param>
        /// <returns>Forum page model</returns>
        public virtual ForumPageModel PrepareForumPageModel(Forum forum, int page)
        {
            if (forum == null)
            {
                throw new ArgumentNullException(nameof(forum));
            }

            var model = new ForumPageModel();

            model.Id          = forum.Id;
            model.Name        = forum.Name;
            model.SeName      = forum.GetSeName();
            model.Description = forum.Description;

            var pageSize = _forumSettings.TopicsPageSize > 0 ? _forumSettings.TopicsPageSize : 10;

            model.AllowPostVoting = _forumSettings.AllowPostVoting;

            //subscription
            if (_forumService.IsCustomerAllowedToSubscribe(_workContext.CurrentCustomer))
            {
                model.WatchForumText = _localizationService.GetResource("Forum.WatchForum");

                var forumSubscription = _forumService.GetAllSubscriptions(_workContext.CurrentCustomer.Id, forum.Id, 0, 0, 1).FirstOrDefault();
                if (forumSubscription != null)
                {
                    model.WatchForumText = _localizationService.GetResource("Forum.UnwatchForum");
                }
            }

            var topics = _forumService.GetAllTopics(forum.Id, 0, string.Empty, ForumSearchType.All, 0, (page - 1), pageSize);

            model.TopicPageSize     = topics.PageSize;
            model.TopicTotalRecords = topics.TotalCount;
            model.TopicPageIndex    = topics.PageIndex;
            foreach (var topic in topics)
            {
                var topicModel = PrepareForumTopicRowModel(topic);
                model.ForumTopics.Add(topicModel);
            }
            model.IsCustomerAllowedToSubscribe = _forumService.IsCustomerAllowedToSubscribe(_workContext.CurrentCustomer);
            model.ForumFeedsEnabled            = _forumSettings.ForumFeedsEnabled;
            model.PostsPageSize = _forumSettings.PostsPageSize;
            return(model);
        }
示例#6
0
        public virtual async Task <ForumPageModel> PrepareForumPage(Forum forum, int pageNumber)
        {
            var model = new ForumPageModel();

            model.Id          = forum.Id;
            model.Name        = forum.Name;
            model.SeName      = forum.GetSeName();
            model.Description = forum.Description;

            int pageSize = _forumSettings.TopicsPageSize > 0 ? _forumSettings.TopicsPageSize : 10;

            //subscription
            if (_forumService.IsCustomerAllowedToSubscribe(_workContext.CurrentCustomer))
            {
                model.WatchForumText = _localizationService.GetResource("Forum.WatchForum");

                var forumSubscription = (await _forumService.GetAllSubscriptions(_workContext.CurrentCustomer.Id, forum.Id, "", 0, 1)).FirstOrDefault();
                if (forumSubscription != null)
                {
                    model.WatchForumText = _localizationService.GetResource("Forum.UnwatchForum");
                }
            }

            var topics = await _forumService.GetAllTopics(forum.Id, "", string.Empty,
                                                          ForumSearchType.All, 0, (pageNumber - 1), pageSize);

            model.TopicPageSize     = topics.PageSize;
            model.TopicTotalRecords = topics.TotalCount;
            model.TopicPageIndex    = topics.PageIndex;
            foreach (var topic in topics)
            {
                var topicModel = await PrepareForumTopicRow(topic);

                model.ForumTopics.Add(topicModel);
            }
            model.IsCustomerAllowedToSubscribe = _forumService.IsCustomerAllowedToSubscribe(_workContext.CurrentCustomer);
            model.ForumFeedsEnabled            = _forumSettings.ForumFeedsEnabled;
            model.PostsPageSize   = _forumSettings.PostsPageSize;
            model.AllowPostVoting = _forumSettings.AllowPostVoting;
            return(model);
        }