/// <summary> /// Prepare the profile posts model /// </summary> /// <param name="user">User</param> /// <param name="page">Number of posts page</param> /// <returns>Profile posts model</returns> public virtual ProfilePostsModel PrepareProfilePostsModel(User user, int page) { if (user == null) { throw new ArgumentNullException(nameof(user)); } if (page > 0) { page -= 1; } var pagerModel = new PagerModel { ShowTotalSummary = false, RouteActionName = "UserProfilePaged", UseRouteLinks = true, RouteValues = new RouteValues { pageNumber = page, id = user.Id } }; var model = new ProfilePostsModel { PagerModel = pagerModel, }; return(model); }
public ActionResult Posts(int customerProfileId, int page) { var customer = _customerService.GetCustomerById(customerProfileId); if (customer == null) { return(RedirectToRoute("HomePage")); } if (page > 0) { page -= 1; } var pageSize = _forumSettings.LatestCustomerPostsPageSize; var list = _forumService.GetAllPosts(0, customer.Id, string.Empty, false, page, pageSize); var latestPosts = new List <PostsModel>(); foreach (var forumPost in list) { var posted = string.Empty; if (_forumSettings.RelativeDateTimeFormattingEnabled) { posted = forumPost.CreatedOnUtc.RelativeFormat(true, "f"); } else { posted = _dateTimeHelper.ConvertToUserTime(forumPost.CreatedOnUtc, DateTimeKind.Utc).ToString("f"); } latestPosts.Add(new PostsModel() { ForumTopicId = forumPost.TopicId, ForumTopicTitle = forumPost.ForumTopic.Subject, ForumTopicSlug = forumPost.ForumTopic.GetSeName(), ForumPostText = forumPost.FormatPostText(), Posted = posted }); } // codehint: sm-edit ViewData["PagerRouteValues"] = new RouteValues { page = page, id = customerProfileId }; var model = new ProfilePostsModel(list) { // codehint: sm-delete Posts = latestPosts, }; return(PartialView(model)); }
/// <summary> /// Prepare the profile posts model /// </summary> /// <param name="customer">Customer</param> /// <param name="page">Number of posts page</param> /// <returns>Profile posts model</returns> public virtual ProfilePostsModel PrepareProfilePostsModel(Customer customer, int page) { if (customer == null) { throw new ArgumentNullException(nameof(customer)); } if (page > 0) { page -= 1; } var pageSize = _forumSettings.LatestCustomerPostsPageSize; var list = _forumService.GetAllPosts(0, customer.Id, string.Empty, false, page, pageSize); var latestPosts = new List <PostsModel>(); foreach (var forumPost in list) { var posted = string.Empty; if (_forumSettings.RelativeDateTimeFormattingEnabled) { var languageCode = _workContext.WorkingLanguage.LanguageCulture; var postedAgo = forumPost.CreatedOnUtc.RelativeFormat(languageCode); posted = string.Format(_localizationService.GetResource("Common.RelativeDateTime.Past"), postedAgo); } else { posted = _dateTimeHelper.ConvertToUserTime(forumPost.CreatedOnUtc, DateTimeKind.Utc).ToString("f"); } latestPosts.Add(new PostsModel { ForumTopicId = forumPost.TopicId, ForumTopicTitle = forumPost.ForumTopic.Subject, ForumTopicSlug = _forumService.GetTopicSeName(forumPost.ForumTopic), ForumPostText = _forumService.FormatPostText(forumPost), Posted = posted }); } var pagerModel = new PagerModel { PageSize = list.PageSize, TotalRecords = list.TotalCount, PageIndex = list.PageIndex, ShowTotalSummary = false, RouteActionName = "CustomerProfilePaged", UseRouteLinks = true, RouteValues = new RouteValues { pageNumber = page, id = customer.Id } }; var model = new ProfilePostsModel { PagerModel = pagerModel, Posts = latestPosts, }; return(model); }
public async Task <IViewComponentResult> InvokeAsync(string customerProfileId, int pageNumber) { var customer = await _customerService.GetCustomerById(customerProfileId); if (customer == null) { return(Content("")); } if (pageNumber > 0) { pageNumber -= 1; } var pageSize = _forumSettings.LatestCustomerPostsPageSize; var list = await _forumService.GetAllPosts("", customer.Id, string.Empty, false, pageNumber, pageSize); var latestPosts = new List <PostsModel>(); foreach (var forumPost in list) { var posted = string.Empty; if (_forumSettings.RelativeDateTimeFormattingEnabled) { posted = forumPost.CreatedOnUtc.ToString("f"); } else { posted = _dateTimeHelper.ConvertToUserTime(forumPost.CreatedOnUtc, DateTimeKind.Utc).ToString("f"); } var forumtopic = await _forumService.GetTopicById(forumPost.TopicId); if (forumtopic != null) { latestPosts.Add(new PostsModel { ForumTopicId = forumPost.TopicId, ForumTopicTitle = forumtopic.Subject, ForumTopicSlug = forumtopic.GetSeName(), ForumPostText = forumPost.FormatPostText(), Posted = posted }); } } var pagerModel = new PagerModel(_localizationService) { PageSize = list.PageSize, TotalRecords = list.TotalCount, PageIndex = list.PageIndex, ShowTotalSummary = false, RouteActionName = "CustomerProfilePaged", UseRouteLinks = true, RouteValues = new RouteValues { pageNumber = pageNumber, id = customerProfileId } }; var model = new ProfilePostsModel { PagerModel = pagerModel, Posts = latestPosts, }; return(View(model)); }
public ActionResult Posts(int customerProfileId, int page) { var customer = _customerService.GetCustomerById(customerProfileId); if (customer == null) { return(RedirectToRoute("HomePage")); } if (page > 0) { page -= 1; } var pageSize = _forumSettings.LatestCustomerPostsPageSize; var list = _forumService.GetAllPosts(0, customer.Id, string.Empty, false, page, pageSize); var latestPosts = new List <PostsModel>(); foreach (var forumPost in list) { var posted = string.Empty; if (_forumSettings.RelativeDateTimeFormattingEnabled) { posted = forumPost.CreatedOnUtc.RelativeFormat(true, "f"); } else { posted = _dateTimeHelper.ConvertToUserTime(forumPost.CreatedOnUtc, DateTimeKind.Utc).ToString("f"); } var forumtopic = _forumService.GetTopicById(forumPost.TopicId); latestPosts.Add(new PostsModel { ForumTopicId = forumPost.TopicId, ForumTopicTitle = forumtopic.Subject, ForumTopicSlug = forumtopic.GetSeName(), ForumPostText = forumPost.FormatPostText(), Posted = posted }); } var pagerModel = new PagerModel { PageSize = list.PageSize, TotalRecords = list.TotalCount, PageIndex = list.PageIndex, ShowTotalSummary = false, RouteActionName = "CustomerProfilePaged", UseRouteLinks = true, RouteValues = new RouteValues { page = page, id = customerProfileId } }; var model = new ProfilePostsModel { PagerModel = pagerModel, Posts = latestPosts, }; return(PartialView(model)); }