Пример #1
0
        public void UpdateAttribute(string id, Rock.Core.DTO.Attribute Attribute)
        {
            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.Core.AttributeService AttributeService  = new Rock.Core.AttributeService();
                Rock.Core.Attribute        existingAttribute = AttributeService.Get(int.Parse(id));
                if (existingAttribute.Authorized("Edit", currentUser))
                {
                    uow.objectContext.Entry(existingAttribute).CurrentValues.SetValues(Attribute);

                    if (existingAttribute.IsValid)
                    {
                        AttributeService.Save(existingAttribute, currentUser.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>(existingAttribute.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to Edit this Attribute", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Returns Attribute object from cache.  If attribute does not already exist in cache, it
        /// will be read and added to cache
        /// </summary>
        /// <param name="id">The id of the Attribute to read</param>
        /// <returns></returns>
        public static Attribute Read(int id)
        {
            string cacheKey = Attribute.CacheKey(id);

            ObjectCache cache     = MemoryCache.Default;
            Attribute   attribute = cache[cacheKey] as Attribute;

            if (attribute != null)
            {
                return(attribute);
            }
            else
            {
                Rock.Core.AttributeService attributeService = new Rock.Core.AttributeService();
                Rock.Core.Attribute        attributeModel   = attributeService.Get(id);
                if (attributeModel != null)
                {
                    attribute = Attribute.CopyModel(attributeModel);

                    cache.Set(cacheKey, attribute, new CacheItemPolicy());

                    return(attribute);
                }
                else
                {
                    return(null);
                }
            }
        }
Пример #3
0
        public Rock.Core.DTO.Attribute 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.Core.AttributeService AttributeService = new Rock.Core.AttributeService();
                    Rock.Core.Attribute        Attribute        = AttributeService.Get(int.Parse(id));
                    if (Attribute.Authorized("View", user))
                    {
                        return(Attribute.DataTransferObject);
                    }
                    else
                    {
                        throw new WebFaultException <string>("Not Authorized to View this Attribute", System.Net.HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Пример #4
0
        public void DeleteAttribute(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.Core.AttributeService AttributeService = new Rock.Core.AttributeService();
                Rock.Core.Attribute        Attribute        = AttributeService.Get(int.Parse(id));
                if (Attribute.Authorized("Edit", currentUser))
                {
                    AttributeService.Delete(Attribute, currentUser.PersonId);
                    AttributeService.Save(Attribute, currentUser.PersonId);
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to Edit this Attribute", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Пример #5
0
        public void ApiDeleteAttribute( 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.Core.AttributeService AttributeService = new Rock.Core.AttributeService();
                    Rock.Core.Attribute Attribute = AttributeService.Get( int.Parse( id ) );
                    if ( Attribute.Authorized( "Edit", user ) )
                    {
                        AttributeService.Delete( Attribute, user.PersonId );
                        AttributeService.Save( Attribute, user.PersonId );
                    }
                    else
                        throw new WebFaultException<string>( "Not Authorized to Edit this Attribute", System.Net.HttpStatusCode.Forbidden );
                }
                else
                    throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
            }
        }
Пример #6
0
        public Rock.Core.DTO.Attribute 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.Core.AttributeService AttributeService = new Rock.Core.AttributeService();
                Rock.Core.Attribute        Attribute        = AttributeService.Get(int.Parse(id));
                if (Attribute.Authorized("View", currentUser))
                {
                    return(Attribute.DataTransferObject);
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to View this Attribute", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Пример #7
0
        public void ApiUpdateAttribute(string id, string apiKey, Rock.Core.DTO.Attribute Attribute)
        {
            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.Core.AttributeService AttributeService  = new Rock.Core.AttributeService();
                    Rock.Core.Attribute        existingAttribute = AttributeService.Get(int.Parse(id));
                    if (existingAttribute.Authorized("Edit", user))
                    {
                        uow.objectContext.Entry(existingAttribute).CurrentValues.SetValues(Attribute);

                        if (existingAttribute.IsValid)
                        {
                            AttributeService.Save(existingAttribute, user.PersonId);
                        }
                        else
                        {
                            throw new WebFaultException <string>(existingAttribute.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                        }
                    }
                    else
                    {
                        throw new WebFaultException <string>("Not Authorized to Edit this Attribute", System.Net.HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Пример #8
0
        public void UpdateAttribute( string id, Rock.Core.DTO.Attribute Attribute )
        {
            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.Core.AttributeService AttributeService = new Rock.Core.AttributeService();
                Rock.Core.Attribute existingAttribute = AttributeService.Get( int.Parse( id ) );
                if ( existingAttribute.Authorized( "Edit", currentUser ) )
                {
                    uow.objectContext.Entry(existingAttribute).CurrentValues.SetValues(Attribute);

                    if (existingAttribute.IsValid)
                        AttributeService.Save( existingAttribute, currentUser.PersonId );
                    else
                        throw new WebFaultException<string>( existingAttribute.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest );
                }
                else
                    throw new WebFaultException<string>( "Not Authorized to Edit this Attribute", System.Net.HttpStatusCode.Forbidden );
            }
        }
Пример #9
0
        public Rock.Core.DTO.Attribute 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.Core.AttributeService AttributeService = new Rock.Core.AttributeService();
                Rock.Core.Attribute Attribute = AttributeService.Get( int.Parse( id ) );
                if ( Attribute.Authorized( "View", currentUser ) )
                    return Attribute.DataTransferObject;
                else
                    throw new WebFaultException<string>( "Not Authorized to View this Attribute", System.Net.HttpStatusCode.Forbidden );
            }
        }
Пример #10
0
        public void DeleteAttribute( 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.Core.AttributeService AttributeService = new Rock.Core.AttributeService();
                Rock.Core.Attribute Attribute = AttributeService.Get( int.Parse( id ) );
                if ( Attribute.Authorized( "Edit", currentUser ) )
                {
                    AttributeService.Delete( Attribute, currentUser.PersonId );
                    AttributeService.Save( Attribute, currentUser.PersonId );
                }
                else
                    throw new WebFaultException<string>( "Not Authorized to Edit this Attribute", System.Net.HttpStatusCode.Forbidden );
            }
        }
Пример #11
0
        public void ApiUpdateAttribute( string id, string apiKey, Rock.Core.DTO.Attribute Attribute )
        {
            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.Core.AttributeService AttributeService = new Rock.Core.AttributeService();
                    Rock.Core.Attribute existingAttribute = AttributeService.Get( int.Parse( id ) );
                    if ( existingAttribute.Authorized( "Edit", user ) )
                    {
                        uow.objectContext.Entry(existingAttribute).CurrentValues.SetValues(Attribute);

                        if (existingAttribute.IsValid)
                            AttributeService.Save( existingAttribute, user.PersonId );
                        else
                            throw new WebFaultException<string>( existingAttribute.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest );
                    }
                    else
                        throw new WebFaultException<string>( "Not Authorized to Edit this Attribute", System.Net.HttpStatusCode.Forbidden );
                }
                else
                    throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
            }
        }
Пример #12
0
        /// <summary>
        /// Returns Attribute object from cache.  If attribute does not already exist in cache, it
        /// will be read and added to cache
        /// </summary>
        /// <param name="id">The id of the Attribute to read</param>
        /// <returns></returns>
        public static Attribute Read( int id )
        {
            string cacheKey = Attribute.CacheKey( id );

            ObjectCache cache = MemoryCache.Default;
            Attribute attribute = cache[cacheKey] as Attribute;

            if ( attribute != null )
                return attribute;
            else
            {
                Rock.Core.AttributeService attributeService = new Rock.Core.AttributeService();
                Rock.Core.Attribute attributeModel = attributeService.Get( id );
                if ( attributeModel != null )
                {
                    attribute = Attribute.CopyModel( attributeModel );

                    cache.Set( cacheKey, attribute, new CacheItemPolicy() );

                    return attribute;
                }
                else
                    return null;

            }
        }