Esempio n. 1
0
        protected void Page_Init( object sender, EventArgs e )
        {
            // get block settings
            string heading = AttributeValue( "Heading" );

            // create string to hold output
            StringBuilder output = new StringBuilder();

            // get blog id to load
            int blogId = -1;
            try
            {
                blogId = Convert.ToInt32( PageParameter( "BlogId" ) );
            }
            catch
            {
                lCategories.Text = "<p class=\"block-warning\">The ID of this blog could not be found in the address of this page</p>";
            }

            if ( blogId != -1 )
            {
                Rock.CMS.BlogService blogService = new Rock.CMS.BlogService();

                // try loading the blog object from the page cache
                Rock.CMS.Blog blog = PageInstance.GetSharedItem( "blog" ) as Rock.CMS.Blog;

                if ( blog == null )
                {
                    blog = blogService.Get( blogId );
                    PageInstance.SaveSharedItem( "blog", blog );
                }

                if ( heading != string.Empty )
                    output.Append( "<h1>" + heading + "</h1>\n\n" );

                // print categories as an un-ordered list
                output.Append( "<ul>" );

                foreach ( Rock.CMS.BlogCategory category in blog.BlogCategories.OrderBy( c => c.Name ) )
                {
                    output.Append( "<li><a href=\"" + HttpContext.Current.Request.Url.LocalPath + "?Category=" + category.Id.ToString() + "\">" + category.Name + "</a></li>" );
                }

                output.Append( "</ul>" );

                lCategories.Text = output.ToString();
            }
        }
Esempio n. 2
0
        public void ApiDeleteBlog( string id, string apiKey )
        {
            using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() )
            {
                Rock.CMS.UserService userService = new Rock.CMS.UserService();
                Rock.CMS.User user = userService.Queryable().Where( u => u.ApiKey == apiKey ).FirstOrDefault();

                if (user != null)
                {
                    uow.objectContext.Configuration.ProxyCreationEnabled = false;
                    Rock.CMS.BlogService BlogService = new Rock.CMS.BlogService();
                    Rock.CMS.Blog Blog = BlogService.Get( int.Parse( id ) );
                    if ( Blog.Authorized( "Edit", user ) )
                    {
                        BlogService.Delete( Blog, user.PersonId );
                        BlogService.Save( Blog, user.PersonId );
                    }
                    else
                        throw new WebFaultException<string>( "Not Authorized to Edit this Blog", System.Net.HttpStatusCode.Forbidden );
                }
                else
                    throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
            }
        }
Esempio n. 3
0
        public void ApiCreateBlog( string apiKey, Rock.CMS.DTO.Blog Blog )
        {
            using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() )
            {
                Rock.CMS.UserService userService = new Rock.CMS.UserService();
                Rock.CMS.User user = userService.Queryable().Where( u => u.ApiKey == apiKey ).FirstOrDefault();

                if (user != null)
                {
                    uow.objectContext.Configuration.ProxyCreationEnabled = false;
                    Rock.CMS.BlogService BlogService = new Rock.CMS.BlogService();
                    Rock.CMS.Blog existingBlog = new Rock.CMS.Blog();
                    BlogService.Add( existingBlog, user.PersonId );
                    uow.objectContext.Entry(existingBlog).CurrentValues.SetValues(Blog);

                    if (existingBlog.IsValid)
                        BlogService.Save( existingBlog, user.PersonId );
                    else
                        throw new WebFaultException<string>( existingBlog.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest );
                }
                else
                    throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
            }
        }
Esempio n. 4
0
        public Rock.CMS.DTO.Blog ApiGet( string id, string apiKey )
        {
            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                Rock.CMS.UserService userService = new Rock.CMS.UserService();
                Rock.CMS.User user = userService.Queryable().Where( u => u.ApiKey == apiKey ).FirstOrDefault();

                if (user != null)
                {
                    uow.objectContext.Configuration.ProxyCreationEnabled = false;
                    Rock.CMS.BlogService BlogService = new Rock.CMS.BlogService();
                    Rock.CMS.Blog Blog = BlogService.Get( int.Parse( id ) );
                    if ( Blog.Authorized( "View", user ) )
                        return Blog.DataTransferObject;
                    else
                        throw new WebFaultException<string>( "Not Authorized to View this Blog", System.Net.HttpStatusCode.Forbidden );
                }
                else
                    throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
            }
        }
Esempio n. 5
0
        public void UpdateBlog( string id, Rock.CMS.DTO.Blog Blog )
        {
            var currentUser = Rock.CMS.UserService.GetCurrentUser();
            if ( currentUser == null )
                throw new WebFaultException<string>("Must be logged in", System.Net.HttpStatusCode.Forbidden );

            using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() )
            {
                uow.objectContext.Configuration.ProxyCreationEnabled = false;
                Rock.CMS.BlogService BlogService = new Rock.CMS.BlogService();
                Rock.CMS.Blog existingBlog = BlogService.Get( int.Parse( id ) );
                if ( existingBlog.Authorized( "Edit", currentUser ) )
                {
                    uow.objectContext.Entry(existingBlog).CurrentValues.SetValues(Blog);

                    if (existingBlog.IsValid)
                        BlogService.Save( existingBlog, currentUser.PersonId );
                    else
                        throw new WebFaultException<string>( existingBlog.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest );
                }
                else
                    throw new WebFaultException<string>( "Not Authorized to Edit this Blog", System.Net.HttpStatusCode.Forbidden );
            }
        }
Esempio n. 6
0
        public Rock.CMS.DTO.Blog Get( string id )
        {
            var currentUser = Rock.CMS.UserService.GetCurrentUser();
            if ( currentUser == null )
                throw new WebFaultException<string>("Must be logged in", System.Net.HttpStatusCode.Forbidden );

            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                uow.objectContext.Configuration.ProxyCreationEnabled = false;
                Rock.CMS.BlogService BlogService = new Rock.CMS.BlogService();
                Rock.CMS.Blog Blog = BlogService.Get( int.Parse( id ) );
                if ( Blog.Authorized( "View", currentUser ) )
                    return Blog.DataTransferObject;
                else
                    throw new WebFaultException<string>( "Not Authorized to View this Blog", System.Net.HttpStatusCode.Forbidden );
            }
        }
Esempio n. 7
0
        public void DeleteBlog( string id )
        {
            var currentUser = Rock.CMS.UserService.GetCurrentUser();
            if ( currentUser == null )
                throw new WebFaultException<string>("Must be logged in", System.Net.HttpStatusCode.Forbidden );

            using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() )
            {
                uow.objectContext.Configuration.ProxyCreationEnabled = false;
                Rock.CMS.BlogService BlogService = new Rock.CMS.BlogService();
                Rock.CMS.Blog Blog = BlogService.Get( int.Parse( id ) );
                if ( Blog.Authorized( "Edit", currentUser ) )
                {
                    BlogService.Delete( Blog, currentUser.PersonId );
                    BlogService.Save( Blog, currentUser.PersonId );
                }
                else
                    throw new WebFaultException<string>( "Not Authorized to Edit this Blog", System.Net.HttpStatusCode.Forbidden );
            }
        }