Esempio n. 1
0
        public async Task <bool> Add(int personId, Relationship relationship)
        {
            var newRelationship = new Relationship
            {
                PersonId         = personId,
                RelatedPersonId  = relationship.RelatedPerson.Id,
                RelationshipType = relationship.RelationshipType
            };

            var reverseRelationshipType = newRelationship.RelationshipType;

            if (reverseRelationshipType == RelationshipType.Parent)
            {
                reverseRelationshipType = RelationshipType.Child;
            }
            else if (reverseRelationshipType == RelationshipType.Child)
            {
                reverseRelationshipType = RelationshipType.Parent;
            }

            var reverseRelationship = new Relationship()
            {
                PersonId         = newRelationship.RelatedPersonId,
                RelatedPersonId  = newRelationship.PersonId,
                RelationshipType = reverseRelationshipType
            };

            _relationshipRepository.Add(newRelationship);
            _relationshipRepository.Add(reverseRelationship);

            return(await _relationshipRepository.SaveChangesAsync());
        }