private async Task PrepareBlogPostModel(BlogPostModel model, BlogPost blogPost) { if (blogPost == null) { throw new ArgumentNullException("blogPost"); } if (model == null) { throw new ArgumentNullException("model"); } model.Id = blogPost.Id; model.MetaTitle = blogPost.GetLocalized(x => x.MetaTitle, _workContext.WorkingLanguage.Id); model.MetaDescription = blogPost.GetLocalized(x => x.MetaDescription, _workContext.WorkingLanguage.Id); model.MetaKeywords = blogPost.GetLocalized(x => x.MetaKeywords, _workContext.WorkingLanguage.Id); model.SeName = blogPost.GetSeName(_workContext.WorkingLanguage.Id); model.Title = blogPost.GetLocalized(x => x.Title, _workContext.WorkingLanguage.Id); model.Body = blogPost.GetLocalized(x => x.Body, _workContext.WorkingLanguage.Id); model.BodyOverview = blogPost.GetLocalized(x => x.BodyOverview, _workContext.WorkingLanguage.Id); model.AllowComments = blogPost.AllowComments; model.CreatedOn = _dateTimeHelper.ConvertToUserTime(blogPost.StartDateUtc ?? blogPost.CreatedOnUtc, DateTimeKind.Utc); model.Tags = blogPost.ParseTags().ToList(); model.NumberOfComments = blogPost.CommentCount; model.GenericAttributes = blogPost.GenericAttributes; //prepare picture model await PrepareBlogPostPictureModel(model, blogPost); }
public void PrepareBlogPostModel(BlogPostModel model, BlogPost blogPost, bool prepareComments) { if (blogPost == null) { throw new ArgumentNullException("blogPost"); } if (model == null) { throw new ArgumentNullException("model"); } model.Id = blogPost.Id; model.MetaTitle = blogPost.GetLocalized(x => x.MetaTitle); model.MetaDescription = blogPost.GetLocalized(x => x.MetaDescription); model.MetaKeywords = blogPost.GetLocalized(x => x.MetaKeywords); model.SeName = blogPost.GetSeName(); model.Title = blogPost.GetLocalized(x => x.Title); model.Body = blogPost.GetLocalized(x => x.Body); model.BodyOverview = blogPost.GetLocalized(x => x.BodyOverview); model.AllowComments = blogPost.AllowComments; model.CreatedOn = _dateTimeHelper.ConvertToUserTime(blogPost.StartDateUtc ?? blogPost.CreatedOnUtc, DateTimeKind.Utc); model.Tags = blogPost.ParseTags().ToList(); model.NumberOfComments = blogPost.CommentCount; model.AddNewComment.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnBlogCommentPage; if (prepareComments) { var blogComments = _blogService.GetBlogCommentsByBlogPostId(blogPost.Id); foreach (var bc in blogComments) { var commentModel = PrepareBlogPostCommentModel(bc); model.Comments.Add(commentModel); } } }
/// <summary> /// Prepare blog post model /// </summary> /// <param name="model">Blog post model</param> /// <param name="blogPost">Blog post entity</param> /// <param name="prepareComments">Whether to prepare blog comments</param> public virtual void PrepareBlogPostModel(BlogPostModel model, BlogPost blogPost, bool prepareComments) { if (model == null) { throw new ArgumentNullException("model"); } if (blogPost == null) { throw new ArgumentNullException("blogPost"); } model.Id = blogPost.Id; model.Title = blogPost.Title; model.Body = blogPost.Body; model.BodyOverview = blogPost.BodyOverview; model.AllowComments = blogPost.AllowComments; model.CreatedOn = ConvertToUserTime(blogPost.StartDateUtc ?? blogPost.CreatedOnUtc, DateTimeKind.Utc); model.Tags = blogPost.ParseTags().ToList(); //number of blog comments model.NumberOfComments = _blogService.GetBlogCommentsCount(blogPost, true); if (prepareComments) { var blogComments = blogPost.BlogComments.Where(comment => comment.IsApproved); foreach (var bc in blogComments.OrderBy(comment => comment.CreatedOnUtc)) { var commentModel = PrepareBlogPostCommentModel(bc); model.Comments.Add(commentModel); } } }
public async Task PrepareBlogPostModel(BlogPostModel model, BlogPost blogPost, bool prepareComments) { if (blogPost == null) { throw new ArgumentNullException("blogPost"); } if (model == null) { throw new ArgumentNullException("model"); } model.Id = blogPost.Id; model.MetaTitle = blogPost.GetLocalized(x => x.MetaTitle, _workContext.WorkingLanguage.Id); model.MetaDescription = blogPost.GetLocalized(x => x.MetaDescription, _workContext.WorkingLanguage.Id); model.MetaKeywords = blogPost.GetLocalized(x => x.MetaKeywords, _workContext.WorkingLanguage.Id); model.SeName = blogPost.GetSeName(_workContext.WorkingLanguage.Id); model.Title = blogPost.GetLocalized(x => x.Title, _workContext.WorkingLanguage.Id); model.Body = blogPost.GetLocalized(x => x.Body, _workContext.WorkingLanguage.Id); model.BodyOverview = blogPost.GetLocalized(x => x.BodyOverview, _workContext.WorkingLanguage.Id); model.AllowComments = blogPost.AllowComments; model.CreatedOn = _dateTimeHelper.ConvertToUserTime(blogPost.StartDateUtc ?? blogPost.CreatedOnUtc, DateTimeKind.Utc); model.Tags = blogPost.ParseTags().ToList(); model.NumberOfComments = blogPost.CommentCount; model.AddNewComment.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnBlogCommentPage; model.GenericAttributes = blogPost.GenericAttributes; if (prepareComments) { var blogComments = await _blogService.GetBlogCommentsByBlogPostId(blogPost.Id); foreach (var bc in blogComments) { var commentModel = await PrepareBlogPostCommentModel(bc); model.Comments.Add(commentModel); } } //prepare picture model if (!string.IsNullOrEmpty(blogPost.PictureId)) { int pictureSize = _mediaSettings.BlogThumbPictureSize; var categoryPictureCacheKey = string.Format(ModelCacheEventConsumer.BLOG_PICTURE_MODEL_KEY, blogPost.Id, pictureSize, true, _workContext.WorkingLanguage.Id, _webHelper.IsCurrentConnectionSecured(), _storeContext.CurrentStore.Id); model.PictureModel = await _cacheManager.GetAsync(categoryPictureCacheKey, async() => { var picture = await _pictureService.GetPictureById(blogPost.PictureId); var pictureModel = new PictureModel { Id = blogPost.PictureId, FullSizeImageUrl = await _pictureService.GetPictureUrl(picture), ImageUrl = await _pictureService.GetPictureUrl(picture, pictureSize), Title = string.Format(_localizationService.GetResource("Media.Blog.ImageLinkTitleFormat"), blogPost.Title), AlternateText = string.Format(_localizationService.GetResource("Media.Blog.ImageAlternateTextFormat"), blogPost.Title) }; return(pictureModel); }); } }
protected void PrepareBlogPostModel(BlogPostModel model, BlogPost blogPost, bool prepareComments) { if (blogPost == null) { throw new ArgumentNullException("blogPost"); } if (model == null) { throw new ArgumentNullException("model"); } model.Id = blogPost.Id; model.MetaTitle = blogPost.MetaTitle; model.MetaDescription = blogPost.MetaDescription; model.MetaKeywords = blogPost.MetaKeywords; model.SeName = blogPost.GetSeName(blogPost.LanguageId, ensureTwoPublishedLanguages: false); model.Title = blogPost.Title; model.Body = blogPost.Body; model.AllowComments = blogPost.AllowComments; model.AvatarPictureSize = _mediaSettings.AvatarPictureSize; // codehint: sm-add model.CreatedOn = _dateTimeHelper.ConvertToUserTime(blogPost.CreatedOnUtc, DateTimeKind.Utc); model.Tags = blogPost.ParseTags().ToList(); model.NumberOfComments = blogPost.ApprovedCommentCount; model.AddNewComment.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnBlogCommentPage; model.AllowCustomersToUploadAvatars = _customerSettings.AllowCustomersToUploadAvatars; if (prepareComments) { var blogComments = blogPost.BlogComments.Where(pr => pr.IsApproved).OrderBy(pr => pr.CreatedOnUtc); foreach (var bc in blogComments) { var commentModel = new BlogCommentModel() { Id = bc.Id, CustomerId = bc.CustomerId, CustomerName = bc.Customer.FormatUserName(), CommentText = bc.CommentText, CreatedOn = _dateTimeHelper.ConvertToUserTime(bc.CreatedOnUtc, DateTimeKind.Utc), AllowViewingProfiles = _customerSettings.AllowViewingProfiles && bc.Customer != null && !bc.Customer.IsGuest() }; if (_customerSettings.AllowCustomersToUploadAvatars) { var customer = bc.Customer; string avatarUrl = _pictureService.GetPictureUrl(customer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId), _mediaSettings.AvatarPictureSize, false); if (String.IsNullOrEmpty(avatarUrl) && _customerSettings.DefaultAvatarEnabled) { avatarUrl = _pictureService.GetDefaultPictureUrl(_mediaSettings.AvatarPictureSize, PictureType.Avatar); } commentModel.CustomerAvatarUrl = avatarUrl; } model.Comments.Add(commentModel); } } }
protected void PrepareBlogPostModel(BlogPostModel model, BlogPost blogPost, bool prepareComments) { Guard.NotNull(blogPost, nameof(blogPost)); Guard.NotNull(model, nameof(model)); model.Id = blogPost.Id; model.MetaTitle = blogPost.MetaTitle; model.MetaDescription = blogPost.MetaDescription; model.MetaKeywords = blogPost.MetaKeywords; model.SeName = blogPost.GetSeName(blogPost.LanguageId, ensureTwoPublishedLanguages: false); model.Title = blogPost.Title; model.Body = blogPost.Body; model.CreatedOn = _dateTimeHelper.ConvertToUserTime(blogPost.CreatedOnUtc, DateTimeKind.Utc); model.AddNewComment.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnBlogCommentPage; model.Comments.AllowComments = blogPost.AllowComments; model.Comments.NumberOfComments = blogPost.ApprovedCommentCount; model.Comments.AllowCustomersToUploadAvatars = _customerSettings.AllowCustomersToUploadAvatars; model.Tags = blogPost.ParseTags().Select(x => new BlogPostTagModel { Name = x, SeName = SeoHelper.GetSeName(x, _seoSettings.ConvertNonWesternChars, _seoSettings.AllowUnicodeCharsInUrls, true, _seoSettings.SeoNameCharConversion) }).ToList(); if (prepareComments) { var blogComments = blogPost.BlogComments.Where(pr => pr.IsApproved).OrderBy(pr => pr.CreatedOnUtc); foreach (var bc in blogComments) { var isGuest = bc.Customer.IsGuest(); var commentModel = new CommentModel(model.Comments) { Id = bc.Id, CustomerId = bc.CustomerId, CustomerName = bc.Customer.FormatUserName(_customerSettings, T, false), CommentText = bc.CommentText, CreatedOn = _dateTimeHelper.ConvertToUserTime(bc.CreatedOnUtc, DateTimeKind.Utc), CreatedOnPretty = bc.CreatedOnUtc.RelativeFormat(true, "f"), AllowViewingProfiles = _customerSettings.AllowViewingProfiles && !isGuest }; commentModel.Avatar = bc.Customer.ToAvatarModel(_genericAttributeService, _pictureService, _customerSettings, _mediaSettings, Url, commentModel.CustomerName); model.Comments.Comments.Add(commentModel); } } Services.DisplayControl.Announce(blogPost); }
protected virtual void PrepareBlogPostModel(BlogPostModel model, BlogPost blogPost, bool prepareComments) { if (blogPost == null) { throw new ArgumentNullException("blogPost"); } if (model == null) { throw new ArgumentNullException("model"); } model.Id = blogPost.Id; model.MetaTitle = blogPost.MetaTitle; model.MetaDescription = blogPost.MetaDescription; model.MetaKeywords = blogPost.MetaKeywords; model.SeName = blogPost.GetSeName(blogPost.LanguageId, ensureTwoPublishedLanguages: false); model.Title = blogPost.Title; model.Body = blogPost.Body; model.BodyOverview = blogPost.BodyOverview; model.AllowComments = blogPost.AllowComments; model.CreatedOn = _dateTimeHelper.ConvertToUserTime(blogPost.StartDateUtc ?? blogPost.CreatedOnUtc, DateTimeKind.Utc); model.Tags = blogPost.ParseTags().ToList(); model.NumberOfComments = blogPost.CommentCount; model.AddNewComment.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnBlogCommentPage; if (prepareComments) { var blogComments = _blogService.GetBlogCommentsByBlogPostId(blogPost.Id); foreach (var bc in blogComments) { var customer = EngineContext.Current.Resolve <ICustomerService>().GetCustomerById(bc.CustomerId); var commentModel = new BlogCommentModel { Id = bc.Id, CustomerId = bc.CustomerId, CustomerName = customer.FormatUserName(), CommentText = bc.CommentText, CreatedOn = _dateTimeHelper.ConvertToUserTime(bc.CreatedOnUtc, DateTimeKind.Utc), AllowViewingProfiles = _customerSettings.AllowViewingProfiles && customer != null && !customer.IsGuest(), }; if (_customerSettings.AllowCustomersToUploadAvatars) { commentModel.CustomerAvatarUrl = _pictureService.GetPictureUrl( customer.GetAttribute <string>(SystemCustomerAttributeNames.AvatarPictureId), _mediaSettings.AvatarPictureSize, _customerSettings.DefaultAvatarEnabled, defaultPictureType: PictureType.Avatar); } model.Comments.Add(commentModel); } } }
public void Can_parse_tags() { var blogPost = new BlogPost() { Tags = "tag1, tag2, tag 3 4, " }; var tags = blogPost.ParseTags(); tags.Length.ShouldEqual(3); tags[0].ShouldEqual("tag1"); tags[1].ShouldEqual("tag2"); tags[2].ShouldEqual("tag 3 4"); }
public void can_parse_tags() { BlogPost blogPost = new BlogPost { Tags = "tag1, tag2, tag 3 4, t,a,g,23,2" }; string[] expected = { "tag1", "tag2", "tag 3 4", "t", "a", "g", "23", "2" }; string[] actual = blogPost.ParseTags(); for (int a = 0; a < expected.Length; ++a) { Assert.AreEqual(expected[a], actual[a]); } }
private void PrepareBlogPostModel(BlogPostModel model, BlogPost blogPost, bool prepareComments) { if (blogPost == null) { throw new ArgumentNullException("blogPost"); } if (model == null) { throw new ArgumentNullException("model"); } model.Id = blogPost.Id; model.SeName = blogPost.GetSeName(); model.Title = blogPost.Title; model.Body = blogPost.Body; model.AllowComments = blogPost.AllowComments; model.CreatedOn = _dateTimeHelper.ConvertToUserTime(blogPost.CreatedOnUtc, DateTimeKind.Utc); model.Tags = blogPost.ParseTags().ToList(); model.NumberOfComments = blogPost.BlogComments.Count; if (prepareComments) { var blogComments = blogPost.BlogComments.Where(pr => pr.IsApproved).OrderBy(pr => pr.CreatedOnUtc); foreach (var bc in blogComments) { var commentModel = new BlogCommentModel() { Id = bc.Id, CustomerId = bc.CustomerId, CustomerName = bc.Customer.FormatUserName(), CommentText = bc.CommentText, CreatedOn = _dateTimeHelper.ConvertToUserTime(bc.CreatedOnUtc, DateTimeKind.Utc), AllowViewingProfiles = _customerSettings.AllowViewingProfiles && bc.Customer != null && !bc.Customer.IsGuest(), }; if (_customerSettings.AllowCustomersToUploadAvatars) { var customer = bc.Customer; string avatarUrl = _pictureService.GetPictureUrl(customer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId), _mediaSettings.AvatarPictureSize, false); if (string.IsNullOrEmpty(avatarUrl) && _customerSettings.DefaultAvatarEnabled) { avatarUrl = _pictureService.GetDefaultPictureUrl(_mediaSettings.AvatarPictureSize, PictureType.Avatar); } commentModel.CustomerAvatarUrl = avatarUrl; } model.Comments.Add(commentModel); } } }
public virtual void PrepareBlogPostModel(BlogPostModel model, BlogPost blogPost, bool prepareComments) { if (model == null) { throw new ArgumentNullException("model"); } if (blogPost == null) { throw new ArgumentNullException("blogPost"); } model.Id = blogPost.Id; model.MetaTitle = blogPost.MetaTitle; model.MetaDescription = blogPost.MetaDescription; model.MetaKeywords = blogPost.MetaKeywords; model.SeName = blogPost.GetSeName(blogPost.LanguageId, ensureTwoPublishedLanguages: false); model.Title = blogPost.Title; model.Body = blogPost.Body; model.BodyOverview = blogPost.BodyOverview; model.AllowComments = blogPost.AllowComments; model.CreatedOn = _dateTimeHelper.ConvertToUserTime(blogPost.StartDateUtc ?? blogPost.CreatedOnUtc, DateTimeKind.Utc); model.Tags = blogPost.ParseTags().ToList(); model.AddNewComment.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnBlogCommentPage; //number of blog comments var storeId = _blogSettings.ShowBlogCommentsPerStore ? _storeContext.CurrentStore.Id : 0; var cacheKey = string.Format(ModelCacheEventConsumer.BLOG_COMMENTS_NUMBER_KEY, blogPost.Id, storeId, true); model.NumberOfComments = _cacheManager.Get(cacheKey, () => _blogService.GetBlogCommentsCount(blogPost, storeId, true)); if (prepareComments) { var blogComments = blogPost.BlogComments.Where(comment => comment.IsApproved); if (_blogSettings.ShowBlogCommentsPerStore) { blogComments = blogComments.Where(comment => comment.StoreId == _storeContext.CurrentStore.Id); } foreach (var bc in blogComments.OrderBy(comment => comment.CreatedOnUtc)) { var commentModel = PrepareBlogPostCommentModel(bc); model.Comments.Add(commentModel); } } }
protected void PrepareBlogPostModel(BlogPostModel model, BlogPost blogPost, bool prepareComments) { Guard.NotNull(blogPost, nameof(blogPost)); Guard.NotNull(model, nameof(model)); MiniMapper.Map(blogPost, model); model.SeName = blogPost.GetSeName(blogPost.LanguageId, ensureTwoPublishedLanguages: false); model.CreatedOn = _dateTimeHelper.ConvertToUserTime(blogPost.CreatedOnUtc, DateTimeKind.Utc); model.AddNewComment.DisplayCaptcha = _captchaSettings.CanDisplayCaptcha && _captchaSettings.ShowOnBlogCommentPage; model.Comments.AllowComments = blogPost.AllowComments; model.Comments.NumberOfComments = blogPost.ApprovedCommentCount; model.Comments.AllowCustomersToUploadAvatars = _customerSettings.AllowCustomersToUploadAvatars; model.DisplayAdminLink = _services.Permissions.Authorize(Permissions.System.AccessBackend, _services.WorkContext.CurrentCustomer); model.HasBgImage = blogPost.PreviewDisplayType == PreviewDisplayType.DefaultSectionBg || blogPost.PreviewDisplayType == PreviewDisplayType.PreviewSectionBg; model.PictureModel = PrepareBlogPostPictureModel(blogPost, blogPost.MediaFileId); if (blogPost.PreviewDisplayType == PreviewDisplayType.Default || blogPost.PreviewDisplayType == PreviewDisplayType.DefaultSectionBg) { model.PreviewPictureModel = PrepareBlogPostPictureModel(blogPost, blogPost.MediaFileId); } else if (blogPost.PreviewDisplayType == PreviewDisplayType.Preview || blogPost.PreviewDisplayType == PreviewDisplayType.PreviewSectionBg) { model.PreviewPictureModel = PrepareBlogPostPictureModel(blogPost, blogPost.PreviewMediaFileId); } if (blogPost.PreviewDisplayType == PreviewDisplayType.Preview || blogPost.PreviewDisplayType == PreviewDisplayType.Default || blogPost.PreviewDisplayType == PreviewDisplayType.Bare) { model.SectionBg = string.Empty; } // tags model.Tags = blogPost.ParseTags().Select(x => new BlogPostTagModel { Name = x, SeName = SeoHelper.GetSeName(x, _seoSettings.ConvertNonWesternChars, _seoSettings.AllowUnicodeCharsInUrls, true, _seoSettings.SeoNameCharConversion) }).ToList(); if (prepareComments) { var blogComments = blogPost.BlogComments.Where(pr => pr.IsApproved).OrderBy(pr => pr.CreatedOnUtc); foreach (var bc in blogComments) { var isGuest = bc.Customer.IsGuest(); var commentModel = new CommentModel(model.Comments) { Id = bc.Id, CustomerId = bc.CustomerId, CustomerName = bc.Customer.FormatUserName(_customerSettings, T, false), CommentText = bc.CommentText, CreatedOn = _dateTimeHelper.ConvertToUserTime(bc.CreatedOnUtc, DateTimeKind.Utc), CreatedOnPretty = bc.CreatedOnUtc.RelativeFormat(true, "f"), AllowViewingProfiles = _customerSettings.AllowViewingProfiles && !isGuest }; commentModel.Avatar = bc.Customer.ToAvatarModel(_genericAttributeService, _mediaService, _customerSettings, _mediaSettings, Url, commentModel.CustomerName); model.Comments.Comments.Add(commentModel); } } Services.DisplayControl.Announce(blogPost); }
/// <summary> /// Prepare blog post model /// </summary> /// <param name="model">Blog post model</param> /// <param name="blogPost">Blog post entity</param> /// <param name="prepareComments">Whether to prepare blog comments</param> public virtual void PrepareBlogPostModel(BlogPostModel model, BlogPost blogPost, bool prepareComments) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (blogPost == null) { throw new ArgumentNullException(nameof(blogPost)); } model.Id = blogPost.Id; model.MetaTitle = blogPost.MetaTitle; model.MetaDescription = blogPost.MetaDescription; model.MetaKeywords = blogPost.MetaKeywords; model.SeName = blogPost.GetSeName(blogPost.LanguageId, ensureTwoPublishedLanguages: false); model.Title = blogPost.Title; model.Body = blogPost.Body; model.BodyOverview = blogPost.BodyOverview; model.AllowComments = blogPost.AllowComments; model.CreatedOn = _dateTimeHelper.ConvertToUserTime(blogPost.StartDateUtc ?? blogPost.CreatedOnUtc, DateTimeKind.Utc); model.Tags = blogPost.ParseTags().ToList(); model.AddNewComment.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnBlogCommentPage; var pictureSize = _mediaSettings.CategoryThumbPictureSize; //prepare picture model var blogPictureCacheKey = string.Format(ModelCacheEventConsumer.BLOG_PICTURE_MODEL_KEY, model.Id, pictureSize, true, _workContext.WorkingLanguage.Id, _webHelper.IsCurrentConnectionSecured(), _storeContext.CurrentStore.Id); model.Picture = _cacheManager.Get(blogPictureCacheKey, () => { var picture = _pictureService.GetPictureById(blogPost.PictureId); var pictureModel = new PictureModel { FullSizeImageUrl = _pictureService.GetPictureUrl(picture), ImageUrl = _pictureService.GetPictureUrl(picture, pictureSize), Title = string.Format(_localizationService.GetResource("Media.Category.ImageLinkTitleFormat"), model.SeName), AlternateText = string.Format(_localizationService.GetResource("Media.Category.ImageAlternateTextFormat"), model.SeName) }; return(pictureModel); }); //number of blog comments var storeId = _blogSettings.ShowBlogCommentsPerStore ? _storeContext.CurrentStore.Id : 0; var cacheKey = string.Format(ModelCacheEventConsumer.BLOG_COMMENTS_NUMBER_KEY, blogPost.Id, storeId, true); model.NumberOfComments = _cacheManager.Get(cacheKey, () => _blogService.GetBlogCommentsCount(blogPost, storeId, true)); if (prepareComments) { var blogComments = blogPost.BlogComments.Where(comment => comment.IsApproved); if (_blogSettings.ShowBlogCommentsPerStore) { blogComments = blogComments.Where(comment => comment.StoreId == _storeContext.CurrentStore.Id); } foreach (var bc in blogComments.OrderBy(comment => comment.CreatedOnUtc)) { var commentModel = PrepareBlogPostCommentModel(bc); model.Comments.Add(commentModel); } } }