public void FindMatchesTest()
        {
            const int groupTypeId = 19;
            DateTime  start       = DateTime.Now;
            DateTime  end         = DateTime.Now.AddMonths(4);

            var participant = new GroupParticipantDTO();

            _groupService.Setup(mocked => mocked.GetSearchResults(groupTypeId)).Returns(It.IsAny <List <MpGroupSearchResult> >());
            _attributeService.Setup(mocked => mocked.GetAttributes(null)).Returns(It.IsAny <List <MpAttribute> >());

            //var result =  _fixture.FindMatches(groupTypeId, participant);
        }
        public void ShouldCallServiceUpdateParticipant()
        {
            var participant = new GroupParticipantDTO()
            {
                GroupParticipantId = 1,
                GroupRoleId        = 22,
                GroupRoleTitle     = "Group Leader"
            };

            _groupServiceMock.Setup(x => x.UpdateGroupParticipantRole(It.IsAny <GroupParticipantDTO>()));
            _fixture.UpdateParticipant(participant);
            _groupServiceMock.Verify();
        }
        public IEnumerable <GroupDTO> FindMatches(int groupTypeId, GroupParticipantDTO participant)
        {
            // Load all groups for potential match
            var mpGroups     = _mpGroupService.GetSearchResults(groupTypeId);
            var mpAttributes = _attributeService.GetAttributes(null);

            var mpFilteredGroups = FilterSearchResults(participant, mpGroups);

            mpFilteredGroups = mpFilteredGroups.Take(MaxGroupSearchResults);

            var groups = ConvertToGroupDto(mpFilteredGroups, mpAttributes);

            return(groups);
        }
Exemplo n.º 4
0
 public IHttpActionResult GetSearchMatches(int groupTypeId, [FromBody] GroupParticipantDTO participant)
 {
     return(Authorized(token =>
     {
         try
         {
             var matches = _groupSearchService.FindMatches(groupTypeId, participant);
             return Ok(matches);
         }
         catch (Exception ex)
         {
             var apiError = new ApiErrorDto("Error searching for matching groups for group type ID " + groupTypeId, ex);
             throw new HttpResponseException(apiError.HttpResponseMessage);
         }
     }));
 }
Exemplo n.º 5
0
 public IHttpActionResult UpdateParticipant([FromBody] GroupParticipantDTO participant)
 {
     return(Authorized(token =>
     {
         try
         {
             _groupService.UpdateGroupParticipantRole(participant);
             return Ok();
         }
         catch (InvalidOperationException)
         {
             return NotFound();
         }
         catch (Exception ex)
         {
             var apiError = new ApiErrorDto("Error updating participant for participant ID " + participant.ParticipantId, ex);
             throw new HttpResponseException(apiError.HttpResponseMessage);
         }
     }));
 }
Exemplo n.º 6
0
 public void UpdateGroupParticipantRole(GroupParticipantDTO participant)
 {
     try
     {
         var apiToken      = _apiUserService.GetToken();
         var mpParticipant = Mapper.Map <MpGroupParticipant>(participant);
         List <MpGroupParticipant> part = new List <MpGroupParticipant>();
         part.Add(mpParticipant);
         _mpGroupRepository.UpdateGroupParticipant(part);
         if (participant.GroupRoleId == _groupRoleLeader)
         {
             if (_mpGroupRepository.ParticipantGroupHasStudents(apiToken, mpParticipant.ParticipantId, mpParticipant.GroupParticipantId))
             {
                 _mpGroupRepository.SendNewStudentMinistryGroupAlertEmail(part);
             }
         }
     }
     catch (Exception e)
     {
         var message = String.Format("Could not update group participant {0}", participant.ParticipantId);
         _logger.Error(message, e);
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Sends a participant and email based off of a template ID and any merge data you need for that template.
        /// </summary>
        /// <param name="participant"></param>
        /// <param name="templateId"></param>
        /// <param name="mergeData"></param>
        public int SendSingleGroupParticipantEmail(GroupParticipantDTO participant, int templateId, Dictionary <string, object> mergeData)
        {
            var emailTemplate = _communicationRepository.GetTemplate(templateId);

            var domainId = Convert.ToInt32(_domainId);
            var from     = new MpContact
            {
                ContactId    = emailTemplate.FromContactId,
                EmailAddress = emailTemplate.FromEmailAddress
            };

            var to = new List <MpContact>
            {
                new MpContact
                {
                    ContactId    = participant.ContactId,
                    EmailAddress = participant.Email
                }
            };

            var message = new MpCommunication
            {
                EmailBody      = emailTemplate.Body,
                EmailSubject   = emailTemplate.Subject,
                AuthorUserId   = 5,
                DomainId       = domainId,
                FromContact    = from,
                MergeData      = mergeData,
                ReplyToContact = from,
                TemplateId     = templateId,
                ToContacts     = to,
                StartDate      = DateTime.Now
            };

            // ReSharper disable once RedundantArgumentDefaultValue
            return(_communicationRepository.SendMessage(message, false));
        }
        private IEnumerable <MpGroupSearchResult> FilterSearchResults(GroupParticipantDTO participant, IEnumerable <MpGroupSearchResult> mpGroups)
        {
            ObjectSingleAttributeDTO participantGoal;
            ObjectSingleAttributeDTO gender;
            ObjectSingleAttributeDTO maritalStatus;
            ObjectAttributeTypeDTO   weekdayTimes;
            ObjectAttributeTypeDTO   weekendTimes;

            // Single-Attributes
            participant.SingleAttributes.TryGetValue(ParticipantGoalAttributeTypeId, out participantGoal);
            participant.SingleAttributes.TryGetValue(GenderTypeAttributeTypeId, out gender);
            participant.SingleAttributes.TryGetValue(MaritalStatusTypeAttributeTypeId, out maritalStatus);

            // Attributes
            participant.AttributeTypes.TryGetValue(WeekdayTimesAttributeTypeId, out weekdayTimes);
            participant.AttributeTypes.TryGetValue(WeekendTimesAttributeTypeId, out weekendTimes);

            return(mpGroups.Where(mpGroup =>
                                  CheckCapacity(maritalStatus, mpGroup.RemainingCapacity) &&
                                  InMarket(mpGroup.Address.Postal_Code) &&
                                  MatchDayTime(weekdayTimes, weekendTimes, mpGroup.SearchAttributes.MeetingRangeId) &&
                                  MatchGroupType(gender, maritalStatus, mpGroup.SearchAttributes.TypeId))
                   .OrderByDescending(mpGroup => SortGoal(participantGoal, mpGroup.SearchAttributes.GoalId)));
        }
Exemplo n.º 9
0
        public void SendGroupParticipantEmail(int groupId,
                                              GroupDTO group,
                                              int emailTemplateId,
                                              MpParticipant toParticipant,
                                              string subjectTemplateContentBlockTitle = null,
                                              string emailTemplateContentBlockTitle   = null,
                                              string message = null,
                                              MpParticipant fromParticipant = null)
        {
            var participant = new GroupParticipantDTO
            {
                ContactId     = toParticipant.ContactId,
                Email         = toParticipant.EmailAddress,
                NickName      = toParticipant.PreferredName,
                ParticipantId = toParticipant.ParticipantId
            };

            var emailTemplate = _communicationRepository.GetTemplate(emailTemplateId);

            var fromContact = new MpContact
            {
                ContactId    = emailTemplate.FromContactId,
                EmailAddress = emailTemplate.FromEmailAddress
            };

            var replyTo = new MpContact
            {
                ContactId    = fromParticipant?.ContactId ?? emailTemplate.ReplyToContactId,
                EmailAddress = fromParticipant == null ? emailTemplate.ReplyToEmailAddress : fromParticipant.EmailAddress
            };

            var leader = _contactRepository.GetContactById(replyTo.ContactId);

            var to = new List <MpContact>
            {
                new MpContact
                {
                    ContactId    = participant.ContactId,
                    EmailAddress = participant.Email
                }
            };

            var subjectTemplateText = string.IsNullOrWhiteSpace(subjectTemplateContentBlockTitle)
                ? string.Empty
                : _contentBlockService[subjectTemplateContentBlockTitle].Content ?? string.Empty;

            var emailTemplateText = string.IsNullOrWhiteSpace(emailTemplateContentBlockTitle) ? string.Empty : _contentBlockService[emailTemplateContentBlockTitle].Content;

            var mergeData = getDictionary(participant);

            mergeData["Email_Custom_Message"] = string.IsNullOrWhiteSpace(message) ? string.Empty : message;
            mergeData["Group_Name"]           = group.GroupName;
            mergeData["Group_Description"]    = group.GroupDescription;
            mergeData["Leader_Name"]          = leader.Nickname != null && leader.Last_Name != null ? leader.Nickname + " " + leader.Last_Name : replyTo.EmailAddress;
            mergeData["City"]  = group.Address.City;
            mergeData["State"] = group.Address.State;
            if (fromParticipant != null)
            {
                mergeData["From_Display_Name"]   = fromParticipant.DisplayName;
                mergeData["From_Preferred_Name"] = fromParticipant.PreferredName;
            }

            // Since the templates are coming from content blocks, they may have replacement tokens in them as well.
            // These will not get replaced with merge data in _communicationRepository.SendMessage(), (it doesn't doubly
            // replace) so we'll parse them here before adding them to the merge data.
            mergeData["Subject_Template_Text"] = _communicationRepository.ParseTemplateBody(Regex.Replace(subjectTemplateText, "<.*?>", string.Empty), mergeData);
            mergeData["Email_Template_Text"]   = _communicationRepository.ParseTemplateBody(emailTemplateText, mergeData);

            var email = new MpCommunication
            {
                EmailBody      = emailTemplate.Body,
                EmailSubject   = emailTemplate.Subject,
                AuthorUserId   = _emailAuthorId,
                DomainId       = _domainId,
                FromContact    = fromContact,
                ReplyToContact = replyTo,
                TemplateId     = emailTemplateId,
                ToContacts     = to,
                MergeData      = mergeData
            };

            _communicationRepository.SendMessage(email);
        }