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); }
/// <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); }
/// <summary> /// Prepare the forum topic row model /// </summary> /// <param name="topic">Forum topic</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the forum topic row model /// </returns> public virtual async Task <ForumTopicRowModel> PrepareForumTopicRowModelAsync(ForumTopic topic) { if (topic == null) { throw new ArgumentNullException(nameof(topic)); } var customer = await _customerService.GetCustomerByIdAsync(topic.CustomerId); var topicModel = new ForumTopicRowModel { Id = topic.Id, Subject = topic.Subject, SeName = await _forumService.GetTopicSeNameAsync(topic), LastPostId = topic.LastPostId, NumPosts = topic.NumPosts, Views = topic.Views, NumReplies = topic.NumPosts > 0 ? topic.NumPosts - 1 : 0, ForumTopicType = topic.ForumTopicType, CustomerId = topic.CustomerId, AllowViewingProfiles = _customerSettings.AllowViewingProfiles && !await _customerService.IsGuestAsync(customer), CustomerName = await _customerService.FormatUsernameAsync(customer) }; var forumPosts = await _forumService.GetAllPostsAsync(topic.Id, 0, string.Empty, 1, _forumSettings.PostsPageSize); topicModel.TotalPostPages = forumPosts.TotalPages; var firstPost = await _forumService.GetFirstPostAsync(topic); topicModel.Votes = firstPost != null ? firstPost.VoteCount : 0; return(topicModel); }
protected virtual ForumTopicRowModel PrepareForumTopicRowModel(ForumTopic 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, CustomerName = topic.Customer.FormatUserName(), IsCustomerGuest = topic.Customer.IsGuest() }; var forumPosts = _forumService.GetAllPosts(topic.Id, 0, string.Empty, 1, _forumSettings.PostsPageSize); topicModel.TotalPostPages = forumPosts.TotalPages; return(topicModel); }
public static IHtmlContent ForumTopicSmallPager <TModel>(this IHtmlHelper <TModel> html, ForumTopicRowModel model) { var localizationService = EngineContext.Current.Resolve <ILocalizationService>(); var forumTopicId = model.Id; var forumTopicSlug = model.SeName; var totalPages = model.TotalPostPages; if (totalPages > 0) { var links = new StringBuilder(); if (totalPages <= 4) { for (int x = 1; x <= totalPages; x++) { links.Append(html.RouteLink(x.ToString(), "TopicSlugPaged", new { id = forumTopicId, pageNumber = (x), slug = forumTopicSlug }, new { title = String.Format(localizationService.GetResource("Pager.PageLinkTitle"), x.ToString()) }).ToHtmlString()); if (x < totalPages) { links.Append(", "); } } } else { links.Append(html.RouteLink("1", "TopicSlugPaged", new { id = forumTopicId, pageNumber = (1), slug = forumTopicSlug }, new { title = String.Format(localizationService.GetResource("Pager.PageLinkTitle"), 1) }).ToHtmlString()); links.Append(" ... "); for (int x = (totalPages - 2); x <= totalPages; x++) { links.Append(html.RouteLink(x.ToString(), "TopicSlugPaged", new { id = forumTopicId, pageNumber = (x), slug = forumTopicSlug }, new { title = String.Format(localizationService.GetResource("Pager.PageLinkTitle"), x.ToString()) })); if (x < totalPages) { links.Append(", "); } } } // Inserts the topic page links into the localized string ([Go to page: {0}]) return(new HtmlString(String.Format(localizationService.GetResource("Forum.Topics.GotoPostPager"), links))); } return(new HtmlString(string.Empty)); }
public static MvcHtmlString ForumTopicSmallPager <TModel>(this HtmlHelper <TModel> html, ForumTopicRowModel model) { var localizer = LocalizationUtilities.Resolve(); var forumTopicId = model.Id; var forumTopicSlug = model.SeName; var totalPages = model.TotalPostPages; if (totalPages > 0) { var links = new StringBuilder(); if (totalPages <= 4) { for (int x = 1; x <= totalPages; x++) { links.Append(html.ActionLink(x.ToString(), "Topic", new { id = forumTopicId, page = (x), slug = forumTopicSlug }, new { title = string.Format(localizer(LocalizableStrings.Pager.PageLinkTitle), x.ToString()) })); if (x < totalPages) { links.Append(", "); } } } else { links.Append(html.ActionLink("1", "Topic", new { id = forumTopicId, page = (1), slug = forumTopicSlug }, new { title = string.Format(localizer(LocalizableStrings.Pager.PageLinkTitle), 1) })); links.Append(" ... "); for (int x = (totalPages - 2); x <= totalPages; x++) { links.Append(html.ActionLink(x.ToString(), "Topic", new { id = forumTopicId, page = (x), slug = forumTopicSlug }, new { title = string.Format(localizer(LocalizableStrings.Pager.PageLinkTitle), x.ToString()) })); if (x < totalPages) { links.Append(", "); } } } // Inserts the topic page links into the localized string ([Go to page: {0}]) return(MvcHtmlString.Create(string.Format(localizer(LocalizableStrings.Topics_GotoPostPager), links.ToString()))); } return(MvcHtmlString.Create(string.Empty)); }