Example #1
0
        private bool IsToManyRelationshipBeingCleared(HasManyAttribute hasManyRelationship, TResource leftResource, object valueToAssign)
        {
            ICollection <IIdentifiable> newRightResourceIds = _collectionConverter.ExtractResources(valueToAssign);

            object existingRightValue = hasManyRelationship.GetValue(leftResource);

            HashSet <IIdentifiable> existingRightResourceIds =
                _collectionConverter.ExtractResources(existingRightValue).ToHashSet(IdentifiableComparer.Instance);

            existingRightResourceIds.ExceptWith(newRightResourceIds);

            return(existingRightResourceIds.Any());
        }
Example #2
0
        /// <summary>
        /// Builds the <see cref="ResourceIdentifierObject"/>s for a HasMany relationship
        /// </summary>
        private List <ResourceIdentifierObject> GetRelatedResourceLinkage(HasManyAttribute relationship, IIdentifiable entity)
        {
            var relatedEntities = (IEnumerable)relationship.GetValue(entity);
            var manyData        = new List <ResourceIdentifierObject>();

            if (relatedEntities != null)
            {
                foreach (IIdentifiable relatedEntity in relatedEntities)
                {
                    manyData.Add(GetResourceIdentifier(relatedEntity));
                }
            }

            return(manyData);
        }
Example #3
0
        /// <summary>
        /// Builds the <see cref="ResourceIdentifierObject"/>s for a HasMany relationship.
        /// </summary>
        private IList <ResourceIdentifierObject> GetRelatedResourceLinkageForHasMany(HasManyAttribute relationship, IIdentifiable resource)
        {
            var value            = relationship.GetValue(resource);
            var relatedResources = TypeHelper.ExtractResources(value);

            var manyData = new List <ResourceIdentifierObject>();

            if (relatedResources != null)
            {
                foreach (var relatedResource in relatedResources)
                {
                    manyData.Add(GetResourceIdentifier(relatedResource));
                }
            }

            return(manyData);
        }