Ejemplo n.º 1
0
        public void AddRelationship()
        {
            const int childId = 4384766;
            const int myId    = 2186211;


            MpRelationship r = new MpRelationship
            {
                RelationshipID   = 43,
                EndDate          = null,
                StartDate        = DateTime.Now,
                RelatedContactID = childId
            };

            var dict = new Dictionary <string, object>
            {
                { "Relationship_ID", r.RelationshipID },
                { "Related_Contact_ID", r.RelatedContactID },
                { "Start_Date", r.StartDate },
                { "End_Date", r.EndDate }
            };


            _ministryPlatformService.Setup(mocked =>
                                           mocked.CreateSubRecord(CONTACT_RELATIONSHIP_PAGE,
                                                                  myId,
                                                                  dict,
                                                                  It.IsAny <string>(),
                                                                  true)).Returns(1);

            var id = _fixture.AddRelationship(r, myId);

            Assert.AreEqual(1, id);
            _ministryPlatformService.VerifyAll();
        }
Ejemplo n.º 2
0
        private void CreateRelationship(Registration registration, int contactId)
        {
            var relationship = new MpRelationship
            {
                RelationshipID   = _configurationWrapper.GetConfigIntValue("MarriedTo"),
                RelatedContactID = contactId,
                StartDate        = DateTime.Today
            };

            _contactRelationshipService.AddRelationship(relationship, registration.Self.ContactId);
        }
Ejemplo n.º 3
0
        private void UpdateChildSponsorship(TripApplicationDto dto)
        {
            if (!RequireSponsoredChild(dto.PageFive))
            {
                return;
            }
            var childId = GetChildId(dto,
                                     (child) =>
            {
                try
                {
                    return(_contactService.CreateContactForSponsoredChild(child.FirstName, child.LastName, child.Town, child.IdNumber));
                }
                catch (ApplicationException e)
                {
                    _logger.Error("Unable to create the sponsored child: " + e.Message);
                    return(-1);
                }
            });

            if (childId == -1)
            {
                return;
            }

            // Check if relationship exists...
            var myRelationships = _contactRelationshipService.GetMyCurrentRelationships(dto.ContactId);
            var rel             = myRelationships.Where(r => r.RelationshipID == _configurationWrapper.GetConfigIntValue("SponsoredChild") && r.RelatedContactID == childId);

            if (rel.Any())
            {
                return;
            }
            // Update the relationship
            var relationship = new MpRelationship
            {
                RelationshipID   = _configurationWrapper.GetConfigIntValue("SponsoredChild"),
                RelatedContactID = childId,
                StartDate        = DateTime.Today
            };

            _contactRelationshipService.AddRelationship(relationship, dto.ContactId);
        }
Ejemplo n.º 4
0
 public int AddRelationship(MpRelationship relationship, int toContact)
 {
     try
     {
         var dict = new Dictionary <string, object>
         {
             { "Relationship_ID", relationship.RelationshipID },
             { "Related_Contact_ID", relationship.RelatedContactID },
             { "Start_Date", relationship.StartDate },
             { "End_Date", relationship.EndDate }
         };
         return(_ministryPlatformService.CreateSubRecord(_configurationWrapper.GetConfigIntValue("ContactRelationships"),
                                                         toContact,
                                                         dict,
                                                         ApiLogin(),
                                                         true));
     }
     catch (Exception e)
     {
         return(-1);
     }
 }