public void Can_save_and_load_blogPost_with_blogComments() { var blogPost = new BlogPost { Title = "Title 1", Body = "Body 1", AllowComments = true, CreatedOnUtc = new DateTime(2010, 01, 01), Language = new Language() { Name = "English", LanguageCulture = "en-Us", } }; blogPost.BlogComments.Add ( new BlogComment { CreatedOnUtc = new DateTime(2010, 01, 03), Customer = GetTestCustomer() } ); var fromDb = SaveAndLoadEntity(blogPost); fromDb.ShouldNotBeNull(); fromDb.BlogComments.ShouldNotBeNull(); (fromDb.BlogComments.Count == 1).ShouldBeTrue(); }
/// <summary> /// Deletes a blog post /// </summary> /// <param name="blogPost">Blog post</param> public virtual void DeleteBlogPost(BlogPost blogPost) { if (blogPost == null) throw new ArgumentNullException("blogPost"); _blogPostRepository.Delete(blogPost); //event notification _eventPublisher.EntityDeleted(blogPost); }
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_save_and_load_blogPost() { var blogPost = new BlogPost { Title = "Title 1", Body = "Body 1", AllowComments = true, CommentCount = 1, Tags = "Tags 1", StartDateUtc = new DateTime(2010, 01, 01), EndDateUtc = new DateTime(2010, 01, 02), CreatedOnUtc = new DateTime(2010, 01, 03), MetaTitle = "MetaTitle 1", MetaDescription = "MetaDescription 1", MetaKeywords = "MetaKeywords 1", LimitedToStores = true, Language = new Language() { Name = "English", LanguageCulture = "en-Us", } }; var fromDb = SaveAndLoadEntity(blogPost); fromDb.ShouldNotBeNull(); fromDb.Title.ShouldEqual("Title 1"); fromDb.Body.ShouldEqual("Body 1"); fromDb.AllowComments.ShouldEqual(true); fromDb.CommentCount.ShouldEqual(1); fromDb.Tags.ShouldEqual("Tags 1"); fromDb.StartDateUtc.ShouldEqual(new DateTime(2010, 01, 01)); fromDb.EndDateUtc.ShouldEqual(new DateTime(2010, 01, 02)); fromDb.CreatedOnUtc.ShouldEqual(new DateTime(2010, 01, 03)); fromDb.MetaTitle.ShouldEqual("MetaTitle 1"); fromDb.MetaDescription.ShouldEqual("MetaDescription 1"); fromDb.MetaKeywords.ShouldEqual("MetaKeywords 1"); fromDb.LimitedToStores.ShouldEqual(true); fromDb.Language.ShouldNotBeNull(); fromDb.Language.Name.ShouldEqual("English"); }
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.CreatedOn = _dateTimeHelper.ConvertToUserTime(blogPost.CreatedOnUtc, DateTimeKind.Utc); model.Tags = blogPost.ParseTags().ToList(); model.NumberOfComments = blogPost.CommentCount; model.AddNewComment.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnBlogCommentPage; if (prepareComments) { var blogComments = blogPost.BlogComments.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); } } }
public static BlogPost ToEntity(this BlogPostModel model, BlogPost destination) { return Mapper.Map(model, destination); }
private void PrepareStoresMappingModel(BlogPostModel model, BlogPost blogPost, bool excludeProperties) { if (model == null) throw new ArgumentNullException("model"); model.AvailableStores = _storeService .GetAllStores() .Select(s => s.ToModel()) .ToList(); if (!excludeProperties) { if (blogPost != null) { model.SelectedStoreIds = _storeMappingService.GetStoresIdsWithAccess(blogPost); } else { model.SelectedStoreIds = new int[0]; } } }
protected void SaveStoreMappings(BlogPost blogPost, BlogPostModel model) { var existingStoreMappings = _storeMappingService.GetStoreMappings(blogPost); var allStores = _storeService.GetAllStores(); foreach (var store in allStores) { if (model.SelectedStoreIds != null && model.SelectedStoreIds.Contains(store.Id)) { //new role if (existingStoreMappings.Count(sm => sm.StoreId == store.Id) == 0) _storeMappingService.InsertStoreMapping(blogPost, store.Id); } else { //removed role var storeMappingToDelete = existingStoreMappings.FirstOrDefault(sm => sm.StoreId == store.Id); if (storeMappingToDelete != null) _storeMappingService.DeleteStoreMapping(storeMappingToDelete); } } }