Ejemplo n.º 1
0
        /// <summary>
        /// Unlinks a contact
        /// </summary>
        /// <param name="link"></param>
        public void UnlinkContact(Contact link)
        {
            var refLink = new MongoDBRef(link.GetCollection().Name, link.Id);
            var refThis = new MongoDBRef(this.GetCollection().Name, this.Id);

            foreach (var reference in this.LinkedContacts)
                Contact.UnlinkContact(reference.Id, refLink);

            foreach (var reference in link.LinkedContacts)
                Contact.UnlinkContact(reference.Id, refThis);

            //if (this.LinkedContacts.All(reference => !MongoDBRef.ReferenceEquals(refLink, reference))
            UnlinkContact(refLink);
            link.UnlinkContact(refThis);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Links a contact
        /// </summary>
        /// <param name="link"></param>
        public void LinkContact(Contact link)
        {
            var refLink = new MongoDBRef(link.GetCollection().Name, link.Id);
            var refThis = new MongoDBRef(this.GetCollection().Name, this.Id);

            // Add link to all this references
            foreach (var reference in this.LinkedContacts)
            {
                if (reference.Id == link.Id)
                    continue;

                Contact.LinkContact(reference.Id, refLink);
                link.LinkContact(reference);
            }

            // Add this to all link references
            foreach (var reference in link.LinkedContacts)
            {
                Contact.LinkContact(reference.Id, refThis);
            }

            //
            // Add link to this
            LinkContact(refLink);

            // Add this to link
            link.LinkContact(refThis);
        }