Esempio n. 1
0
        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 SaveTrackback(TrackBackDto trackBack, int itemId)
        {
            if (trackBack == null)
            {
                throw new ArgumentNullException("trackBack", "The trackBack must be contains a valid instance");
            }

            if (itemId < 1)
            {
                throw new ArgumentException("The Id must be greater than 0", "itemId");
            }

            Post post = this.Session
                        .Include <Post>(x => x.TrackbacksId)
                        .Load <Post>(itemId);

            if (post == null)
            {
                throw new DexterPostNotFoundException(itemId);
            }

            ItemTrackbacks trackbacks = this.Session.Load <ItemTrackbacks>(post.TrackbacksId)
                                        ?? new ItemTrackbacks
            {
                Item = new ItemReference
                {
                    Id              = post.Id,
                    Status          = post.Status,
                    ItemPublishedAt = post.PublishAt
                }
            };

            trackbacks.AddTrackback(trackBack.MapTo <Trackback>(), trackBack.Status);

            this.Session.Store(trackbacks);
            post.TrackbacksId = trackbacks.Id;

            this.Session.Store(post);
        }
Esempio n. 4
0
        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 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);
        }