예제 #1
0
        /// <summary>
        /// Prepare the forum topic row model
        /// </summary>
        /// <param name="topic">Forum topic</param>
        /// <returns>Forum topic row model</returns>
        public virtual ForumTopicRowModel PrepareForumTopicRowModel(ForumTopic topic)
        {
            if (topic == null)
            {
                throw new ArgumentNullException(nameof(topic));
            }

            var topicModel = new ForumTopicRowModel
            {
                Id                   = topic.Id,
                Subject              = topic.Subject,
                SeName               = topic.GetSeName(),
                LastPostId           = topic.LastPostId,
                NumPosts             = topic.NumPosts,
                Views                = topic.Views,
                NumReplies           = topic.NumReplies,
                ForumTopicType       = topic.ForumTopicType,
                CustomerId           = topic.CustomerId,
                AllowViewingProfiles = _customerSettings.AllowViewingProfiles && !topic.Customer.IsGuest(),
                CustomerName         = topic.Customer.FormatUserName()
            };

            var forumPosts = _forumService.GetAllPosts(topic.Id, 0, string.Empty, 1, _forumSettings.PostsPageSize);

            topicModel.TotalPostPages = forumPosts.TotalPages;

            var firstPost = topic.GetFirstPost(_forumService);

            topicModel.Votes = firstPost != null ? firstPost.VoteCount : 0;
            return(topicModel);
        }
예제 #2
0
        public virtual async Task <ForumTopicRowModel> PrepareForumTopicRow(ForumTopic topic)
        {
            var customer = await _serviceProvider.GetRequiredService <ICustomerService>().GetCustomerById(topic.CustomerId);

            var topicModel = new ForumTopicRowModel
            {
                Id                   = topic.Id,
                Subject              = topic.Subject,
                SeName               = topic.GetSeName(),
                LastPostId           = topic.LastPostId,
                NumPosts             = topic.NumPosts,
                Views                = topic.Views,
                NumReplies           = topic.NumReplies,
                ForumTopicType       = topic.ForumTopicType,
                CustomerId           = topic.CustomerId,
                AllowViewingProfiles = _customerSettings.AllowViewingProfiles,
                CustomerName         = customer.FormatUserName(_customerSettings.CustomerNameFormat),
                IsCustomerGuest      = customer.IsGuest()
            };

            var forumPosts = await _forumService.GetAllPosts(topic.Id, "", string.Empty, 1, _forumSettings.PostsPageSize);

            topicModel.TotalPostPages = forumPosts.TotalPages;

            var firstPost = await topic.GetFirstPost(_forumService);

            topicModel.Votes = firstPost != null ? firstPost.VoteCount : 0;

            return(topicModel);
        }
예제 #3
0
        public void GetFirstPost_NullTopic_ThrowException()
        {
            ForumTopic forumTopic       = null;
            var        forumServiceMock = new Mock <IForumService>();

            Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await forumTopic.GetFirstPost(forumServiceMock.Object), "forumTopic");
        }
예제 #4
0
        protected virtual object CreateModelPart(ForumTopic part, MessageContext messageContext)
        {
            Guard.NotNull(messageContext, nameof(messageContext));
            Guard.NotNull(part, nameof(part));

            var pageIndex = messageContext.Model.GetFromBag <int>("TopicPageIndex");

            var url = pageIndex > 0 ?
                      BuildRouteUrl("TopicSlugPaged", new { id = part.Id, slug = part.GetSeName(), page = pageIndex }, messageContext) :
                      BuildRouteUrl("TopicSlug", new { id = part.Id, slug = part.GetSeName() }, messageContext);

            var m = new Dictionary <string, object>
            {
                { "Subject", part.Subject.NullEmpty() },
                { "NumReplies", part.NumReplies },
                { "NumPosts", part.NumPosts },
                { "NumViews", part.Views },
                { "Body", part.GetFirstPost(_services.Resolve <IForumService>())?.FormatPostText().NullEmpty() },
                { "Url", url },
            };

            PublishModelPartCreatedEvent <ForumTopic>(part, m);

            return(m);
        }
예제 #5
0
        public async Task GetFirstPost_InvokeRepository()
        {
            var forumTopic = new ForumTopic();

            forumTopic.Id = "1";
            var forumServiceMock = new Mock <IForumService>();

            forumServiceMock.Setup(c => c.GetAllPosts(forumTopic.Id, "", string.Empty, 0, 1)).Returns(() => Task.FromResult(new Mock <IPagedList <ForumPost> >().Object));
            await forumTopic.GetFirstPost(forumServiceMock.Object);

            forumServiceMock.Verify(f => f.GetAllPosts(forumTopic.Id, "", string.Empty, 0, 1), Times.Once);
        }
예제 #6
0
        /// <summary>
        /// Prepare the forum topic edit model
        /// </summary>
        /// <param name="forumTopic">Forum topic</param>
        /// <param name="model">Edit forum topic model</param>
        /// <param name="excludeProperties">Whether to exclude populating of model properties from the entity</param>
        public virtual void PrepareTopicEditModel(ForumTopic forumTopic, EditForumTopicModel model, bool excludeProperties)
        {
            if (forumTopic == null)
            {
                throw new ArgumentNullException("forumTopic");
            }

            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var forum = forumTopic.Forum;

            if (forum == null)
            {
                throw new ArgumentException("forum cannot be loaded");
            }


            model.IsEdit          = true;
            model.Id              = forumTopic.Id;
            model.TopicPriorities = ForumTopicTypesList();
            model.ForumName       = forum.Name;
            model.ForumSeName     = forum.GetSeName();
            model.ForumId         = forum.Id;
            model.ForumEditor     = _forumSettings.ForumEditor;

            model.IsCustomerAllowedToSetTopicPriority = _forumService.IsCustomerAllowedToSetTopicPriority(_workContext.CurrentCustomer);
            model.IsCustomerAllowedToSubscribe        = _forumService.IsCustomerAllowedToSubscribe(_workContext.CurrentCustomer);

            if (!excludeProperties)
            {
                var firstPost = forumTopic.GetFirstPost(_forumService);
                model.Text        = firstPost.Text;
                model.Subject     = forumTopic.Subject;
                model.TopicTypeId = forumTopic.TopicTypeId;
                //subscription
                if (model.IsCustomerAllowedToSubscribe)
                {
                    var forumSubscription = _forumService.GetAllSubscriptions(_workContext.CurrentCustomer.Id, 0, forumTopic.Id, 0, 1).FirstOrDefault();
                    model.Subscribed = forumSubscription != null;
                }
            }
        }
 public string GetFirstPost(ForumTopic topic)
 {
     return(topic.GetFirstPost().Content);
 }