示例#1
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 );
            }
        }
示例#2
0
        public void CreateBlogTag( 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 = new Rock.CMS.BlogTag();
                BlogTagService.Add( existingBlogTag, currentUser.PersonId );
                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 );
            }
        }