Пример #1
0
        private SaveResult CreateBlog( BlogPostModel model, ContentManagementDb db )
        {
            try
            {
                Blog blog = new Blog();
                blog.Initialise();

                AutoMap.Map( model, blog );

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

                BlogContent blogContent = new BlogContent();

                AutoMap.Map( model, blogContent );
                blog.BlogContent.Add( blogContent );

                blogContent.Initialize();

                blogContent.LastEditedByUserId = blog.CreatedByUserId;

                SetPublishStatus( blog, blogContent, model.Publish );

                db.Blogs.Add( blog );

                db.SaveChanges();

                return SaveResult.Success;
            }
            catch
            {
                return SaveResult.Fail;
            }
        }
Пример #2
0
        public SaveResult SaveBlogPost( BlogPostModel model )
        {
            ContentManagementDb db = new ContentManagementDb();

            Blog blog = db.Blogs.Find( model.PageId );

            if ( blog == null )
            {
                return CreateBlog( model, db );
            }

            return UpdateBlog( blog, model, db );
        }
Пример #3
0
        private SaveResult UpdateBlog( Blog blog, BlogPostModel model, ContentManagementDb db )
        {
            if ( UserSession.Current.IsAdministrator == false ) return SaveResult.AccessDenied;

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

            try
            {
                BlogContent pageContent = blog.BlogContent.FirstOrDefault( s => s.PublishStatus == PublishStatus.Draft );

                if ( pageContent == null )
                {
                    pageContent = new BlogContent();
                    blog.BlogContent.Add( pageContent );
                }

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

                SetPublishStatus( blog, pageContent, model.Publish );

                db.SaveChanges();

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