public void UpdateAttributeValue(string id, Rock.Core.DTO.AttributeValue AttributeValue)
        {
            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.AttributeValueService AttributeValueService  = new Rock.Core.AttributeValueService();
                Rock.Core.AttributeValue        existingAttributeValue = AttributeValueService.Get(int.Parse(id));
                if (existingAttributeValue.Authorized("Edit", currentUser))
                {
                    uow.objectContext.Entry(existingAttributeValue).CurrentValues.SetValues(AttributeValue);

                    if (existingAttributeValue.IsValid)
                    {
                        AttributeValueService.Save(existingAttributeValue, currentUser.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>(existingAttributeValue.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to Edit this AttributeValue", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
        public void ApiCreateAttributeValue(string apiKey, Rock.Core.DTO.AttributeValue AttributeValue)
        {
            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.AttributeValueService AttributeValueService  = new Rock.Core.AttributeValueService();
                    Rock.Core.AttributeValue        existingAttributeValue = new Rock.Core.AttributeValue();
                    AttributeValueService.Add(existingAttributeValue, user.PersonId);
                    uow.objectContext.Entry(existingAttributeValue).CurrentValues.SetValues(AttributeValue);

                    if (existingAttributeValue.IsValid)
                    {
                        AttributeValueService.Save(existingAttributeValue, user.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>(existingAttributeValue.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
        public Rock.Core.DTO.AttributeValue 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.AttributeValueService AttributeValueService = new Rock.Core.AttributeValueService();
                    Rock.Core.AttributeValue        AttributeValue        = AttributeValueService.Get(int.Parse(id));
                    if (AttributeValue.Authorized("View", user))
                    {
                        return(AttributeValue.DataTransferObject);
                    }
                    else
                    {
                        throw new WebFaultException <string>("Not Authorized to View this AttributeValue", System.Net.HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
        public void DeleteAttributeValue(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.AttributeValueService AttributeValueService = new Rock.Core.AttributeValueService();
                Rock.Core.AttributeValue        AttributeValue        = AttributeValueService.Get(int.Parse(id));
                if (AttributeValue.Authorized("Edit", currentUser))
                {
                    AttributeValueService.Delete(AttributeValue, currentUser.PersonId);
                    AttributeValueService.Save(AttributeValue, currentUser.PersonId);
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to Edit this AttributeValue", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Returns Global Attributes from cache.  If they are not already in cache, they
        /// will be read and added to cache
        /// </summary>
        /// <returns></returns>
        public static GlobalAttributes Read()
        {
            string cacheKey = GlobalAttributes.CacheKey();

            ObjectCache cache = MemoryCache.Default;
            GlobalAttributes globalAttributes = cache[cacheKey] as GlobalAttributes;

            if ( globalAttributes != null )
                return globalAttributes;
            else
            {
                globalAttributes = new GlobalAttributes();
                globalAttributes.AttributeValues = new Dictionary<string, KeyValuePair<string, string>>();

                var attributeService = new Rock.Core.AttributeService();
                var attributeValueService = new Rock.Core.AttributeValueService();

                foreach ( Rock.Core.Attribute attribute in attributeService.Queryable().
                    Where( a => a.Entity == "" &&
                        ( a.EntityQualifierColumn ?? string.Empty ) == "" &&
                        ( a.EntityQualifierValue ?? string.Empty ) == "" ) )
                {
                    // TODO: Need to add support for multiple values
                    var attributeValue = attributeValueService.GetByAttributeIdAndEntityId( attribute.Id, null ).FirstOrDefault();
                    globalAttributes.AttributeValues.Add( attribute.Key, new KeyValuePair<string, string>( attribute.Name, (attributeValue != null && !string.IsNullOrEmpty(attributeValue.Value)) ? attributeValue.Value : attribute.DefaultValue ) );
                }

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

                return globalAttributes;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Returns Global Attributes from cache.  If they are not already in cache, they
        /// will be read and added to cache
        /// </summary>
        /// <returns></returns>
        public static GlobalAttributes Read()
        {
            string cacheKey = GlobalAttributes.CacheKey();

            ObjectCache      cache            = MemoryCache.Default;
            GlobalAttributes globalAttributes = cache[cacheKey] as GlobalAttributes;

            if (globalAttributes != null)
            {
                return(globalAttributes);
            }
            else
            {
                globalAttributes = new GlobalAttributes();
                globalAttributes.AttributeValues = new Dictionary <string, KeyValuePair <string, string> >();

                var attributeService      = new Rock.Core.AttributeService();
                var attributeValueService = new Rock.Core.AttributeValueService();

                foreach (Rock.Core.Attribute attribute in attributeService.Queryable().
                         Where(a => a.Entity == "" &&
                               (a.EntityQualifierColumn ?? string.Empty) == "" &&
                               (a.EntityQualifierValue ?? string.Empty) == ""))
                {
                    // TODO: Need to add support for multiple values
                    var attributeValue = attributeValueService.GetByAttributeIdAndEntityId(attribute.Id, null).FirstOrDefault();
                    globalAttributes.AttributeValues.Add(attribute.Key, new KeyValuePair <string, string>(attribute.Name, (attributeValue != null && !string.IsNullOrEmpty(attributeValue.Value)) ? attributeValue.Value : attribute.DefaultValue));
                }

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

                return(globalAttributes);
            }
        }
        public Rock.Core.DTO.AttributeValue 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.AttributeValueService AttributeValueService = new Rock.Core.AttributeValueService();
                Rock.Core.AttributeValue        AttributeValue        = AttributeValueService.Get(int.Parse(id));
                if (AttributeValue.Authorized("View", currentUser))
                {
                    return(AttributeValue.DataTransferObject);
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to View this AttributeValue", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Esempio n. 8
0
        public void ApiDeleteAttributeValue( 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.AttributeValueService AttributeValueService = new Rock.Core.AttributeValueService();
                    Rock.Core.AttributeValue AttributeValue = AttributeValueService.Get( int.Parse( id ) );
                    if ( AttributeValue.Authorized( "Edit", user ) )
                    {
                        AttributeValueService.Delete( AttributeValue, user.PersonId );
                        AttributeValueService.Save( AttributeValue, user.PersonId );
                    }
                    else
                        throw new WebFaultException<string>( "Not Authorized to Edit this AttributeValue", System.Net.HttpStatusCode.Forbidden );
                }
                else
                    throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
            }
        }
Esempio n. 9
0
        public void ApiCreateAttributeValue( string apiKey, Rock.Core.DTO.AttributeValue AttributeValue )
        {
            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.AttributeValueService AttributeValueService = new Rock.Core.AttributeValueService();
                    Rock.Core.AttributeValue existingAttributeValue = new Rock.Core.AttributeValue();
                    AttributeValueService.Add( existingAttributeValue, user.PersonId );
                    uow.objectContext.Entry(existingAttributeValue).CurrentValues.SetValues(AttributeValue);

                    if (existingAttributeValue.IsValid)
                        AttributeValueService.Save( existingAttributeValue, user.PersonId );
                    else
                        throw new WebFaultException<string>( existingAttributeValue.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest );
                }
                else
                    throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
            }
        }
Esempio n. 10
0
        public void UpdateAttributeValue( string id, Rock.Core.DTO.AttributeValue AttributeValue )
        {
            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.AttributeValueService AttributeValueService = new Rock.Core.AttributeValueService();
                Rock.Core.AttributeValue existingAttributeValue = AttributeValueService.Get( int.Parse( id ) );
                if ( existingAttributeValue.Authorized( "Edit", currentUser ) )
                {
                    uow.objectContext.Entry(existingAttributeValue).CurrentValues.SetValues(AttributeValue);

                    if (existingAttributeValue.IsValid)
                        AttributeValueService.Save( existingAttributeValue, currentUser.PersonId );
                    else
                        throw new WebFaultException<string>( existingAttributeValue.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest );
                }
                else
                    throw new WebFaultException<string>( "Not Authorized to Edit this AttributeValue", System.Net.HttpStatusCode.Forbidden );
            }
        }
Esempio n. 11
0
        public Rock.Core.DTO.AttributeValue 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.AttributeValueService AttributeValueService = new Rock.Core.AttributeValueService();
                Rock.Core.AttributeValue AttributeValue = AttributeValueService.Get( int.Parse( id ) );
                if ( AttributeValue.Authorized( "View", currentUser ) )
                    return AttributeValue.DataTransferObject;
                else
                    throw new WebFaultException<string>( "Not Authorized to View this AttributeValue", System.Net.HttpStatusCode.Forbidden );
            }
        }
Esempio n. 12
0
        public void DeleteAttributeValue( 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.AttributeValueService AttributeValueService = new Rock.Core.AttributeValueService();
                Rock.Core.AttributeValue AttributeValue = AttributeValueService.Get( int.Parse( id ) );
                if ( AttributeValue.Authorized( "Edit", currentUser ) )
                {
                    AttributeValueService.Delete( AttributeValue, currentUser.PersonId );
                    AttributeValueService.Save( AttributeValue, currentUser.PersonId );
                }
                else
                    throw new WebFaultException<string>( "Not Authorized to Edit this AttributeValue", System.Net.HttpStatusCode.Forbidden );
            }
        }