public IList <CommentDto> GetCommentForSpecificItem(int commentsId, CommentQueryFilter filters) { if (commentsId < 1) { throw new ArgumentException("The comments id must be greater than 0", "commentsId"); } ItemComments result = this.Session.Load <ItemComments>(commentsId); List <Comment> commentsToMaps = new List <Comment>(); if (filters.CommentStatus == CommentStatus.Pending) { commentsToMaps = result.Pending; } if (filters.CommentStatus == CommentStatus.IsApproved) { commentsToMaps = result.Approved; } if (filters.CommentStatus == CommentStatus.IsSpam) { commentsToMaps = result.Spam; } return(commentsToMaps.MapTo <CommentDto>()); }
public void AddComment(CommentDto comment, int itemId, CommentStatus status) { Item item = this.Session.Load <Item>(itemId); if (item == null) { throw new DexterItemNotFoundException(itemId); } ItemComments itemComments = this.Session.Load <ItemComments>(itemId) ?? new ItemComments(); Comment domainComment = comment.MapTo <Comment>(); itemComments.AddComment(domainComment, status); this.Session.Store(itemComments); }
public void Delete(int id) { Page page = this.Session .Include <Page>(x => x.CommentsId) .Include <Page>(x => x.TrackbacksId) .Load <Page>(id); ItemComments comments = this.Session.Load <ItemComments>(page.CommentsId); ItemTrackbacks trackbacks = this.Session.Load <ItemTrackbacks>(page.TrackbacksId); if (page == null) { throw new DexterPageNotFoundException(id); } this.Session.Delete(page); this.Session.Delete(comments); this.Session.Delete(trackbacks); }
public void Delete(int id) { Post post = this.Session .Include <Post>(x => x.CommentsId) .Include <Post>(x => x.TrackbacksId) .Load <Post>(id); ItemComments comments = this.Session.Load <ItemComments>(post.CommentsId); ItemTrackbacks trackbacks = this.Session.Load <ItemTrackbacks>(post.TrackbacksId); if (post == null) { throw new DexterPostNotFoundException(id); } this.Session.Delete(post); this.Session.Delete(comments); this.Session.Delete(trackbacks); }
public void SavePost_ChangingSlug_ShouldUpdateDenormalizedData() { Post post; ItemComments comments; using (IDocumentSession testSession = this.DocumentStore.OpenSession()) { post = PostHelper.GetPosts(1)[0]; post.Status = ItemStatus.Published; post.PublishAt = DateTime.Today; testSession.Store(post); comments = new ItemComments(); comments.Approved = new List <Comment>(); comments.Item = new ItemReference { Id = post.Id, Status = post.Status, ItemPublishedAt = post.PublishAt }; testSession.Store(comments); post.CommentsId = comments.Id; testSession.SaveChanges(); } post.PublishAt = DateTime.Today.AddDays(5); PostDto postDto = post.MapTo <PostDto>(); this.sut.SaveOrUpdate(postDto); this.sut.Session.SaveChanges(); ItemComments retrievedComments = this.sut.Session.Load <ItemComments>(comments.Id); retrievedComments.Should().Not.Be.Null(); retrievedComments.Item.Should().Not.Be.Null(); retrievedComments.Item.ItemPublishedAt.Should().Be.EqualTo(post.PublishAt); }
public IList <CommentDto> GetRecentApprovedComments(int maxNumberOfComments, ItemQueryFilter filters) { IRavenQueryable <PostCommentsCreationDateIndex.ReduceResult> query = this.Session.Query <PostCommentsCreationDateIndex.ReduceResult, PostCommentsCreationDateIndex>(); if (filters != null && filters.Status.HasValue) { query.Where(x => x.Status == filters.Status); } if (filters != null && filters.MinPublishAt.HasValue) { query.Where(x => x.ItemPublishedAt > filters.MaxPublishAt); } if (filters != null && filters.MaxPublishAt.HasValue) { query.Where(x => x.ItemPublishedAt < filters.MaxPublishAt); } List <PostCommentsCreationDateIndex.ReduceResult> data = query.ThenByDescending(x => x.CreatedAt) .AsProjection <PostCommentsCreationDateIndex.ReduceResult>() .Take(maxNumberOfComments) .ToList(); IList <CommentDto> list = new List <CommentDto>(); foreach (PostCommentsCreationDateIndex.ReduceResult commentIdentifier in data) { ItemComments comments = this.Session.Load <ItemComments>(commentIdentifier.PostCommentsId); Comment comment = comments.Approved.FirstOrDefault(x => x.Id == commentIdentifier.CommentId); Item item = this.Session.Load <Post>(commentIdentifier.ItemId); CommentDto c = comment.MapTo <CommentDto>(); c.ItemInfo = item.MapTo <ItemBaseInfo>(); list.Add(c); } return(list); }
public void SavePost_WithValidData_ShouldSaveThePostAndTheItemComments() { PostDto post = PostHelper.GetPostsDto(1)[0]; this.sut.SaveOrUpdate(post); this.sut.Session.SaveChanges(); post.Id.Should().Be.GreaterThan(0); Post postEntity = this.sut.Session .Include <Post>(x => x.CommentsId) .Load <Post>(post.Id); postEntity.Should().Not.Be.Null(); postEntity.Title.Should().Be.EqualTo(post.Title); post.Slug.Should().Not.Be.Null(); ItemComments itemComments = this.sut.Session.Load <ItemComments>(postEntity.CommentsId); itemComments.Should().Not.Be.Null(); }
public void SaveOrUpdate(PageDto item) { if (item == null) { throw new ArgumentNullException("item", "The post must be contains a valid instance"); } Page page = this.Session.Load <Page>(item.Id) ?? new Page { CreatedAt = DateTimeOffset.Now }; if (string.IsNullOrEmpty(item.Author)) { item.Author = Thread.CurrentPrincipal.Identity.Name; } item.MapPropertiesToInstance(page); if (string.IsNullOrEmpty(page.Excerpt)) { page.Excerpt = AbstractHelper.GenerateAbstract(page.Content); } if (string.IsNullOrEmpty(page.Slug)) { page.Slug = SlugHelper.GenerateSlug(page.Title, page.Id, this.GetPostBySlugInternal); } if (page.IsTransient) { ItemComments comments = new ItemComments { Item = new ItemReference { Id = page.Id, Status = page.Status, ItemPublishedAt = page.PublishAt } }; this.Session.Store(comments); page.CommentsId = comments.Id; ItemTrackbacks trackbacks = new ItemTrackbacks { Item = new ItemReference { Id = page.Id, Status = page.Status, ItemPublishedAt = page.PublishAt } }; this.Session.Store(trackbacks); page.TrackbacksId = trackbacks.Id; } this.Session.Store(page); UpdateDenormalizedItemIndex.UpdateIndexes(this.store, this.Session, page); item.Id = RavenIdHelper.Resolve(page.Id); }
public void SavePost_ChangingSlug_ShouldUpdateDenormalizedData() { Post post; ItemComments comments; using (IDocumentSession testSession = this.DocumentStore.OpenSession()) { post = PostHelper.GetPosts(1)[0]; post.Status = ItemStatus.Published; post.PublishAt = DateTime.Today; testSession.Store(post); comments = new ItemComments(); comments.Approved = new List<Comment>(); comments.Item = new ItemReference { Id = post.Id, Status = post.Status, ItemPublishedAt = post.PublishAt }; testSession.Store(comments); post.CommentsId = comments.Id; testSession.SaveChanges(); } post.PublishAt = DateTime.Today.AddDays(5); PostDto postDto = post.MapTo<PostDto>(); this.sut.SaveOrUpdate(postDto); this.sut.Session.SaveChanges(); ItemComments retrievedComments = this.sut.Session.Load<ItemComments>(comments.Id); retrievedComments.Should().Not.Be.Null(); retrievedComments.Item.Should().Not.Be.Null(); retrievedComments.Item.ItemPublishedAt.Should().Be.EqualTo(post.PublishAt); }
public void SaveOrUpdate(PageDto item) { if (item == null) { throw new ArgumentNullException("item", "The post must be contains a valid instance"); } Page page = this.Session.Load<Page>(item.Id) ?? new Page { CreatedAt = DateTimeOffset.Now }; if (string.IsNullOrEmpty(item.Author)) { item.Author = Thread.CurrentPrincipal.Identity.Name; } item.MapPropertiesToInstance(page); if (string.IsNullOrEmpty(page.Excerpt)) { page.Excerpt = AbstractHelper.GenerateAbstract(page.Content); } if (string.IsNullOrEmpty(page.Slug)) { page.Slug = SlugHelper.GenerateSlug(page.Title, page.Id, this.GetPostBySlugInternal); } if (page.IsTransient) { ItemComments comments = new ItemComments { Item = new ItemReference { Id = page.Id, Status = page.Status, ItemPublishedAt = page.PublishAt } }; this.Session.Store(comments); page.CommentsId = comments.Id; ItemTrackbacks trackbacks = new ItemTrackbacks { Item = new ItemReference { Id = page.Id, Status = page.Status, ItemPublishedAt = page.PublishAt } }; this.Session.Store(trackbacks); page.TrackbacksId = trackbacks.Id; } this.Session.Store(page); UpdateDenormalizedItemIndex.UpdateIndexes(this.store, this.Session, page); item.Id = RavenIdHelper.Resolve(page.Id); }