Exemplo n.º 1
0
        /// <summary>
        /// Saves any attribute edits made using an Attribute Editor control
        /// </summary>
        /// <param name="edtAttribute">The edt attribute.</param>
        /// <param name="entityTypeId">The entity type identifier.</param>
        /// <param name="entityTypeQualifierColumn">The entity type qualifier column.</param>
        /// <param name="entityTypeQualifierValue">The entity type qualifier value.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <returns></returns>
        /// <remarks>
        /// If a rockContext value is included, this method will save any previous changes made to the context
        /// </remarks>
        public static Rock.Model.Attribute SaveAttributeEdits(AttributeEditor edtAttribute, int?entityTypeId, string entityTypeQualifierColumn, string entityTypeQualifierValue, RockContext rockContext = null)
        {
            // Create and update a new attribute object with new values
            var newAttribute = new Rock.Model.Attribute();

            edtAttribute.GetAttributeProperties(newAttribute);

            rockContext = rockContext ?? new RockContext();
            var internalAttributeService = new AttributeService(rockContext);

            Rock.Model.Attribute attribute = null;

            if (newAttribute.Id > 0)
            {
                attribute = internalAttributeService.Get(newAttribute.Id);
            }

            if (attribute == null)
            {
                newAttribute.Order = internalAttributeService.Queryable().Max(a => a.Order) + 1;
            }
            else
            {
                newAttribute.Order = attribute.Order;
            }

            return(SaveAttributeEdits(newAttribute, entityTypeId, entityTypeQualifierColumn, entityTypeQualifierValue, rockContext));
        }
Exemplo n.º 2
0
        private Rock.Model.Attribute SaveChangesToStateCollection(AttributeEditor editor, List <Rock.Model.Attribute> attributeStateCollection)
        {
            // Load the editor values into a new Attribute instance.
            Rock.Model.Attribute attribute = new Rock.Model.Attribute();

            editor.GetAttributeProperties(attribute);

            // Get the stored state of the Attribute, and copy the values of the non-editable properties.
            var attributeState = attributeStateCollection.Where(a => a.Guid.Equals(attribute.Guid)).FirstOrDefault();

            if (attributeState != null)
            {
                attribute.Order                  = attributeState.Order;
                attribute.CreatedDateTime        = attributeState.CreatedDateTime;
                attribute.CreatedByPersonAliasId = attributeState.CreatedByPersonAliasId;
                attribute.ForeignGuid            = attributeState.ForeignGuid;
                attribute.ForeignId              = attributeState.ForeignId;
                attribute.ForeignKey             = attributeState.ForeignKey;

                attributeStateCollection.RemoveEntity(attribute.Guid);
            }
            else
            {
                // Set the Order of the new entry as the last item in the collection.
                attribute.Order = attributeStateCollection.Any() ? attributeStateCollection.Max(a => a.Order) + 1 : 0;
            }

            attributeStateCollection.Add(attribute);

            return(attribute);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Saves any attribute edits made using an Attribute Editor control
        /// </summary>
        /// <param name="edtAttribute">The edt attribute.</param>
        /// <param name="attributeService">The attribute service.</param>
        /// <param name="attributeQualifierService">The attribute qualifier service.</param>
        /// <param name="categoryService">The category service.</param>
        /// <param name="entityTypeId">The entity type identifier.</param>
        /// <param name="entityTypeQualifierColumn">The entity type qualifier column.</param>
        /// <param name="entityTypeQualifierValue">The entity type qualifier value.</param>
        /// <param name="currentPersonId">The current person identifier.</param>
        /// <returns></returns>
        public static Rock.Model.Attribute SaveAttributeEdits(AttributeEditor edtAttribute, AttributeService attributeService, AttributeQualifierService attributeQualifierService, CategoryService categoryService,
                                                              int?entityTypeId, string entityTypeQualifierColumn, string entityTypeQualifierValue, int?currentPersonId)
        {
            // Create and update a new attribute object with new values
            var newAttribute = new Rock.Model.Attribute();

            edtAttribute.GetAttributeProperties(newAttribute);

            return(SaveAttributeEdits(newAttribute, attributeService, attributeQualifierService, categoryService,
                                      entityTypeId, entityTypeQualifierColumn, entityTypeQualifierValue, currentPersonId));
        }