Exemple #1
0
        public void ApiDeleteBlogTag( 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.BlogTagService BlogTagService = new Rock.CMS.BlogTagService();
                    Rock.CMS.BlogTag BlogTag = BlogTagService.Get( int.Parse( id ) );
                    if ( BlogTag.Authorized( "Edit", user ) )
                    {
                        BlogTagService.Delete( BlogTag, user.PersonId );
                        BlogTagService.Save( BlogTag, user.PersonId );
                    }
                    else
                        throw new WebFaultException<string>( "Not Authorized to Edit this BlogTag", System.Net.HttpStatusCode.Forbidden );
                }
                else
                    throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
            }
        }
Exemple #2
0
        public void ApiCreateBlogTag( string apiKey, Rock.CMS.DTO.BlogTag BlogTag )
        {
            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.BlogTagService BlogTagService = new Rock.CMS.BlogTagService();
                    Rock.CMS.BlogTag existingBlogTag = new Rock.CMS.BlogTag();
                    BlogTagService.Add( existingBlogTag, user.PersonId );
                    uow.objectContext.Entry(existingBlogTag).CurrentValues.SetValues(BlogTag);

                    if (existingBlogTag.IsValid)
                        BlogTagService.Save( existingBlogTag, user.PersonId );
                    else
                        throw new WebFaultException<string>( existingBlogTag.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest );
                }
                else
                    throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
            }
        }
Exemple #3
0
        public Rock.CMS.DTO.BlogTag 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.BlogTagService BlogTagService = new Rock.CMS.BlogTagService();
                    Rock.CMS.BlogTag BlogTag = BlogTagService.Get( int.Parse( id ) );
                    if ( BlogTag.Authorized( "View", user ) )
                        return BlogTag.DataTransferObject;
                    else
                        throw new WebFaultException<string>( "Not Authorized to View this BlogTag", System.Net.HttpStatusCode.Forbidden );
                }
                else
                    throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
            }
        }
Exemple #4
0
        public void UpdateBlogTag( string id, Rock.CMS.DTO.BlogTag BlogTag )
        {
            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.BlogTagService BlogTagService = new Rock.CMS.BlogTagService();
                Rock.CMS.BlogTag existingBlogTag = BlogTagService.Get( int.Parse( id ) );
                if ( existingBlogTag.Authorized( "Edit", currentUser ) )
                {
                    uow.objectContext.Entry(existingBlogTag).CurrentValues.SetValues(BlogTag);

                    if (existingBlogTag.IsValid)
                        BlogTagService.Save( existingBlogTag, currentUser.PersonId );
                    else
                        throw new WebFaultException<string>( existingBlogTag.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest );
                }
                else
                    throw new WebFaultException<string>( "Not Authorized to Edit this BlogTag", System.Net.HttpStatusCode.Forbidden );
            }
        }
Exemple #5
0
        public Rock.CMS.DTO.BlogTag 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.BlogTagService BlogTagService = new Rock.CMS.BlogTagService();
                Rock.CMS.BlogTag BlogTag = BlogTagService.Get( int.Parse( id ) );
                if ( BlogTag.Authorized( "View", currentUser ) )
                    return BlogTag.DataTransferObject;
                else
                    throw new WebFaultException<string>( "Not Authorized to View this BlogTag", System.Net.HttpStatusCode.Forbidden );
            }
        }
Exemple #6
0
        public void DeleteBlogTag( 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.BlogTagService BlogTagService = new Rock.CMS.BlogTagService();
                Rock.CMS.BlogTag BlogTag = BlogTagService.Get( int.Parse( id ) );
                if ( BlogTag.Authorized( "Edit", currentUser ) )
                {
                    BlogTagService.Delete( BlogTag, currentUser.PersonId );
                    BlogTagService.Save( BlogTag, currentUser.PersonId );
                }
                else
                    throw new WebFaultException<string>( "Not Authorized to Edit this BlogTag", System.Net.HttpStatusCode.Forbidden );
            }
        }