Пример #1
0
        public void SaveOrUpdate(PageDto item)
        {
            if (item == null)
            {
                throw new DexterPageNotFoundException();
            }

            CancelEventArgsWithOneParameterWithoutResult<PageDto> e = new CancelEventArgsWithOneParameterWithoutResult<PageDto>(item);

            this.PageSaving.Raise(this, e);

            if (e.Cancel)
            {
                return;
            }

            if (item.Id > 0)
            {
                var post = this.pageDataService.GetPageByKey(item.Id);

                if (post == null)
                {
                    throw new DexterPostNotFoundException(item.Id);
                }

                if (!this.userContext.IsInRole(Constants.AdministratorRole) && post.Author != this.userContext.Username)
                {
                    throw new DexterSecurityException(string.Format("Only the Administrator or the Author can edit the post (item Key '{0}').", post.Id));
                }
            }

            this.pageDataService.SaveOrUpdate(item);

            this.PageSaved.Raise(this, new CancelEventArgsWithoutParameterWithResult<PageDto>(item));
        }
        private Page GetMetaweblogPage(PageDto p, IEnumerable<WpAuthor> authors)
        {
            string authorId = this.GetAuthorId(p, authors);

            return new Page
                       {
                           dateCreated = p.CreatedAt.DateTime.ToUniversalTime(),
                           user_id = authorId,
                           page_id = p.Id,
                           page_status = p.Status.ToString(),
                           description = p.Content,
                           title = p.Title,
                           link = this.urlBuilder.Page.Permalink(p),
                           permalink = this.urlBuilder.Page.Permalink(p),
                           categories = null,
                           excerpt = p.Excerpt,
                           text_more = string.Empty,
                           mt_allow_comments = p.AllowComments
                                                   ? 1
                                                   : 2,
                           mt_allow_pings = 0,
                           wp_slug = p.Slug,
                           wp_password = string.Empty,
                           wp_author = p.Author,

                           //wp_page_parent_id = p.Parent != null
                           //						? p.Parent.Id.ToString()
                           //						: string.Empty,
                           //wp_page_parent_title = p.Parent != null
                           //						? p.Parent.Title
                           //						: string.Empty,
                           //wp_page_order = p.SortOrder.ToString(),
                           wp_author_id = authorId,
                           wp_author_display_name = p.Author,
                           date_created_gmt = p.PublishAt.DateTime.ToUniversalTime(),
                           wp_page_template = string.Empty
                       };
        }
        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);
        }