Пример #1
0
        /// <summary>
        /// Update page
        /// </summary>
        /// <param name="page">Page to update</param>
        /// <param name="action">Action to execute</param>
        /// <returns>True on success</returns>
        public bool Update(PageDetail page, string action)
        {
            if (!Security.IsAuthorizedTo(BlogEngine.Core.Rights.CreateNewPages))
                throw new System.UnauthorizedAccessException();

            var corePage = (from p in Page.Pages.ToList() where p.Id == page.Id select p).FirstOrDefault();

            if (action == "publish")
            {
                corePage.IsPublished = true;
                corePage.Save();
                return true;
            }
            if (action == "unpublish")
            {
                corePage.IsPublished = false;
                corePage.Save();
                return true;
            }

            if (corePage != null && Save(corePage, page))
                return true;

            return false;
        }
Пример #2
0
        /// <summary>
        /// Add new page
        /// </summary>
        /// <param name="detail">Page</param>
        /// <returns>Saved page with new ID</returns>
        public PageDetail Add(PageDetail detail)
        {
            if (!Security.IsAuthorizedTo(Rights.CreateNewPages))
                throw new UnauthorizedAccessException();

            var page = new Page();
            if (Save(page, detail))
                return Json.GetPageDetail(page);

            return null;
        }
Пример #3
0
        /// <summary>
        /// Add new page
        /// </summary>
        /// <param name="detail">Page</param>
        /// <returns>Saved page with new ID</returns>
        public PageDetail Add(PageDetail detail)
        {
            if (!Security.IsAuthorizedTo(BlogEngine.Core.Rights.CreateNewPages))
                throw new System.UnauthorizedAccessException();

            var page = new Page();
            if (Save(page, detail))
                return ToJsonDetail(page);

            return null;
        }
Пример #4
0
        static bool Save(Page page, PageDetail detail)
        {
            page.Title = detail.Title;
            page.DateCreated = DateTime.ParseExact(detail.DateCreated, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture);
            page.IsPublished = detail.IsPublished;
            page.ShowInList = detail.ShowInList;
            page.IsDeleted = detail.IsDeleted;
            page.Content = detail.Content;
            page.Description = GetDescription(detail.Description, detail.Content);
            page.Keywords = detail.Keywords;
            page.IsFrontPage = detail.IsFrontPage;
            page.SortOrder = detail.SortOrder;

            // if changing slug, should be unique
            if (page.Slug != detail.Slug)
                page.Slug = GetUniqueSlug(detail.Slug);

            if (detail.Parent.OptionValue == "none")
            {
                page.Parent = Guid.Empty;
            }
            else
            {
                if (detail.Parent != null && detail.Parent.OptionValue != null)
                {
                    try
                    {
                        page.Parent = Guid.Parse(detail.Parent.OptionValue);
                    }
                    catch (Exception)
                    {
                        Utils.Log("Error parsing parent ID while saving page");
                    }
                }
            }

            page.Save();
            return true;
        }
Пример #5
0
 public bool Update(PageDetail page, string action)
 {
     return true;
 }
Пример #6
0
 public PageDetail Add(PageDetail page)
 {
     return new PageDetail() { Id = Guid.NewGuid() };
 }
        static bool Save(Page page, PageDetail detail)
        {
            page.Title = detail.Title;
            page.DateCreated = DateTime.ParseExact(detail.DateCreated, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture);
            page.IsPublished = detail.IsPublished;
            page.ShowInList = detail.ShowInList;
            page.IsDeleted = detail.IsDeleted;
            page.Slug = detail.Slug;
            page.Content = detail.Content;
            page.Description = detail.Description;
            page.Keywords = detail.Keywords;
            page.IsFrontPage = detail.IsFrontPage;

            if (detail.Parent != null)
            {
                try
                {
                    page.Parent = Guid.Parse(detail.Parent.OptionValue);
                }
                catch (Exception)
                {
                    Utils.Log("Error parsing parent ID while adding new page");
                }
            }
            page.Save();
            return true;
        }