public PageListItemModel( Page page )
        {
            PageContent pageContent = page.PageContent.OrderByDescending( s => s.UTCDateUpdated ).First();

            PageId = page.PageId;
            Title = pageContent.Title;

            LastEditedByName = pageContent.LastEditedByUser.UserName;
            DateUpdated = pageContent.UTCDateUpdated.ToLocalTime();

            bool isPublished = page.PageContent.Count( (Func<PageContent, bool>)(s => s.PublishStatus == PublishStatus.Published) ) > 0;
            bool hasDraft = page.PageContent.Count( (Func<PageContent, bool>)(s => s.PublishStatus == PublishStatus.Draft) ) > 0;

            if ( isPublished && hasDraft )
            {
                PageStatus = "Published / Draft Pending";
            }
            else if ( isPublished )
            {
                PageStatus = "Published";
            }
            else if ( hasDraft )
            {
                PageStatus = "Draft Pending";
            }
            else
            {
                PageStatus = "Not Published, No Draft";
            }
        }
Example #2
0
        private SaveResult CreatePage( PageModel model, ContentManagementDb db )
        {
            try
            {
                Page page = new Page();
                page.Initialise();

                AutoMap.Map( model, page );

                page.CreatedByUserId = UserSession.Current.UserId;
                page.DomainId = UserSession.Current.DomainId;

                PageContent pageContent = new PageContent();

                AutoMap.Map( model, pageContent );
                page.PageContent.Add( pageContent );

                pageContent.Initialize();

                pageContent.LastEditedByUserId = page.CreatedByUserId;

                SetPublishStatus( page, pageContent, model.Publish );

                db.Pages.Add( page );

                db.SaveChanges();

                return SaveResult.Success;
            }
            catch
            {
                return SaveResult.Fail;
            }
        }
Example #3
0
 private void SetPublishStatus( Page page, PageContent pageContent, bool publish )
 {
     if ( publish )
     {
         page.PageContent.Where( s => s.PageContentId != pageContent.PageContentId && ( s.PublishStatus == PublishStatus.Draft || s.PublishStatus == PublishStatus.Published ) ).ToList().ForEach( s => s.PublishStatus = PublishStatus.OutOfDate );
         pageContent.PublishStatus = PublishStatus.Published;
     }
     else
     {
         page.PageContent.Where( s => s.PageContentId != pageContent.PageContentId && s.PublishStatus == PublishStatus.Draft ).ToList().ForEach( s => s.PublishStatus = PublishStatus.Deleted );
         pageContent.PublishStatus = PublishStatus.Draft;
     }
 }
Example #4
0
 public BlogPostModel( Page page )
 {
     PageContent pageContent = page.PageContent.OrderByDescending( s => s.UTCDateUpdated ).First();
     AutoMap.Map( pageContent, this );
 }
Example #5
0
        private SaveResult UpdatePage( Page page, PageModel model, ContentManagementDb db )
        {
            if ( UserSession.Current.IsAdministrator == false ) return SaveResult.AccessDenied;

            if ( UserSession.Current.CurrentDomain( db ).CanAccess( page ) == false ) return SaveResult.IncorrectDomain;

            try
            {
                PageContent pageContent = page.PageContent.FirstOrDefault( s => s.PublishStatus == PublishStatus.Draft );

                if ( pageContent == null )
                {
                    pageContent = new PageContent();
                    page.PageContent.Add( pageContent );
                }

                AutoMap.Map( model, pageContent );
                page.UpdateTimeStamp();
                pageContent.UpdateTimeStamp();
                pageContent.LastEditedByUserId = UserSession.Current.UserId;

                SetPublishStatus( page, pageContent, model.Publish );

                db.SaveChanges();

                return SaveResult.Success;
            }
            catch
            {
                return SaveResult.Fail;
            }
        }