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"); }
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); } } }
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.SeName = blogPost.GetSeName(blogPost.LanguageId, ensureTwoPublishedLanguages: false); 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.ApprovedCommentCount; model.AddNewComment.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnBlogCommentPage; 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) { commentModel.CustomerAvatarUrl = _pictureService.GetPictureUrl( bc.Customer.GetAttribute<int>(SystemCustomerAttributeNames.AvatarPictureId), _mediaSettings.AvatarPictureSize, _customerSettings.DefaultAvatarEnabled, defaultPictureType: PictureType.Avatar); } model.Comments.Add(commentModel); } } }
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<int>(SystemCustomerAttributeNames.AvatarPictureId), _mediaSettings.AvatarPictureSize, _customerSettings.DefaultAvatarEnabled, defaultPictureType: PictureType.Avatar); } model.Comments.Add(commentModel); } } }