/// <summary> /// Shows the view. /// </summary> /// <param name = "groupId" > The group identifier.</param> protected void ShowView(int?groupId, int?groupMemberId, Guid?groupGuid) { var rockContext = new RockContext(); Group group = null; GroupMember groupMember = null; int fundraisingOpportunityTypeId = GroupTypeCache.Get(Rock.SystemGuid.GroupType.GROUPTYPE_FUNDRAISINGOPPORTUNITY).Id; pnlView.Visible = true; hfGroupId.Value = groupId.ToStringSafe(); hfGroupMemberId.Value = groupMemberId.ToStringSafe(); hfGroupGuid.Value = groupGuid.ToStringSafe(); if (groupId.HasValue) { group = new GroupService(rockContext).Get(groupId.Value); } else if (groupGuid.HasValue) { group = new GroupService(rockContext).Get(groupGuid.Value); } else { groupMember = new GroupMemberService(rockContext).Get(groupMemberId ?? 0); group = groupMember.Group; } if (group == null || (group.GroupTypeId != fundraisingOpportunityTypeId && group.GroupType.InheritedGroupTypeId != fundraisingOpportunityTypeId)) { pnlView.Visible = false; return; } lTitle.Text = group.Name.FormatAsHtmlTitle(); BindGroupMembersProgressGrid(group, groupMember, rockContext); }
/// <summary> /// Gets the properties and attributes for the entity /// </summary> /// <param name="groupTypeId">The group type identifier.</param> /// <returns></returns> private List <EntityField> GetGroupAttributes(int?groupTypeId) { List <EntityField> entityAttributeFields = new List <EntityField>(); if (groupTypeId.HasValue) { var fakeGroup = new Rock.Model.Group { GroupTypeId = groupTypeId.Value }; Rock.Attribute.Helper.LoadAttributes(fakeGroup); foreach (var attribute in fakeGroup.Attributes.Select(a => a.Value)) { EntityHelper.AddEntityFieldForAttribute(entityAttributeFields, attribute); } } int index = 0; var sortedFields = new List <EntityField>(); foreach (var entityProperty in entityAttributeFields.OrderBy(p => p.TitleWithoutQualifier).ThenBy(p => p.Name)) { entityProperty.Index = index; index++; sortedFields.Add(entityProperty); } return(sortedFields); }
public List <Person> GetGroupLeaders(Group group) { if (group != null) { return(group.Members .Where(gm => gm.GroupMemberStatus == GroupMemberStatus.Active && gm.GroupRole.IsLeader == true) .Select(gm => gm.Person) .ToList()); } return(new List <Person>()); }
private Rock.Model.Group GetMembershipGroup(CheckInPerson person, Rock.Model.Group group) { group.LoadAttributes(); var membershipGroupGuid = group.GetAttributeValue("Group"); if (membershipGroupGuid == null) { return(null); } var membershipGroup = new GroupService(_rockContext).Get(membershipGroupGuid.AsGuid()); return(membershipGroup); }
private List <Note> GetGroupMemberNotes(CheckInPerson person, Rock.Model.Group group) { List <Note> notes = new List <Note>(); Rock.Model.Group membershipGroup = GetMembershipGroup(person, group); if (membershipGroup == null) { return(notes); } var groupMember = new GroupMemberService(_rockContext).Queryable().Where(gm => gm.PersonId == person.Person.Id && gm.GroupId == membershipGroup.Id).FirstOrDefault(); if (groupMember == null) { return(notes); } if (!string.IsNullOrWhiteSpace(groupMember.Note)) { Note note = new Note(); note.Text = groupMember.Note; note.IsAlert = true; notes.Add(note); } //This line is commented out because sports and fitnes has complained that they //are seeing notes they did not add //notes.AddRange( new NoteService( _rockContext ).Get( _noteTypeId, groupMember.Id ).ToList() ); switch (GroupMembershipExpired(groupMember)) { case GroupMembershipStatus.Expired: Note eNote = new Note(); eNote.Text = "Card expired or no longer church member."; eNote.IsAlert = true; notes.Add(eNote); break; case GroupMembershipStatus.NearExpired: Note neNote = new Note(); neNote.Text = "Card will expire soon."; neNote.IsAlert = false; notes.Add(neNote); break; } return(notes); }
/// <summary> /// Gets the properties and attributes for the entity /// </summary> /// <param name="groupTypeId">The group type identifier.</param> /// <returns></returns> private List<EntityField> GetGroupAttributes( int? groupTypeId ) { List<EntityField> entityAttributeFields = new List<EntityField>(); if ( groupTypeId.HasValue ) { var fakeGroup = new Rock.Model.Group { GroupTypeId = groupTypeId.Value }; Rock.Attribute.Helper.LoadAttributes( fakeGroup ); foreach ( var attribute in fakeGroup.Attributes.Select( a => a.Value ) ) { EntityHelper.AddEntityFieldForAttribute( entityAttributeFields, attribute ); } } int index = 0; var sortedFields = new List<EntityField>(); foreach ( var entityProperty in entityAttributeFields.OrderBy( p => p.Title ).ThenBy( p => p.Name ) ) { entityProperty.Index = index; index++; sortedFields.Add( entityProperty ); } return sortedFields; }
/// <summary> /// Binds the group members progress repeater. /// </summary> protected void BindGroupMembersProgressGrid(Group group, GroupMember gMember, RockContext rockContext) { IQueryable <GroupMember> groupMembersQuery; if (gMember != null) { groupMembersQuery = new GroupMemberService(rockContext).Queryable().Where(a => a.Id == gMember.Id); pnlHeader.Visible = false; } else { groupMembersQuery = new GroupMemberService(rockContext).Queryable().Where(a => a.GroupId == group.Id); } group.LoadAttributes(rockContext); var defaultIndividualFundRaisingGoal = group.GetAttributeValue("IndividualFundraisingGoal").AsDecimalOrNull(); groupMembersQuery = groupMembersQuery.Sort(new SortProperty { Property = "Person.LastName, Person.NickName" }); var entityTypeIdGroupMember = EntityTypeCache.GetId <Rock.Model.GroupMember>(); var groupMemberList = groupMembersQuery.ToList().Select(a => { var groupMember = a; groupMember.LoadAttributes(rockContext); var contributionTotal = new FinancialTransactionDetailService(rockContext).Queryable() .Where(d => d.EntityTypeId == entityTypeIdGroupMember && d.EntityId == groupMember.Id) .Sum(d => ( decimal? )d.Amount) ?? 0; var individualFundraisingGoal = groupMember.GetAttributeValue("IndividualFundraisingGoal").AsDecimalOrNull(); bool disablePublicContributionRequests = groupMember.GetAttributeValue("DisablePublicContributionRequests").AsBoolean(); if (!individualFundraisingGoal.HasValue) { individualFundraisingGoal = group.GetAttributeValue("IndividualFundraisingGoal").AsDecimalOrNull(); } decimal percentageAchieved = 0; if (individualFundraisingGoal != null) { percentageAchieved = individualFundraisingGoal == 0 ? 100 : contributionTotal / (0.01M * individualFundraisingGoal.Value); } var progressBarWidth = percentageAchieved; if (percentageAchieved >= 100) { progressBarWidth = 100; } if (!individualFundraisingGoal.HasValue) { individualFundraisingGoal = 0; } return(new { groupMember.Person.FullName, groupMember.Person.NickName, groupMember.Person.LastName, GroupName = group.Name, IndividualFundraisingGoal = (individualFundraisingGoal ?? 0.00M).ToString("0.##"), ContributionTotal = contributionTotal.ToString("0.##"), Percentage = percentageAchieved.ToString("0.##"), CssClass = GetProgressCssClass(percentageAchieved), ProgressBarWidth = progressBarWidth }); }).ToList(); Session["IndividualData"] = groupMemberList; this.GroupIndividualFundraisingGoal = groupMemberList.Sum(a => decimal.Parse(a.IndividualFundraisingGoal)); this.GroupContributionTotal = groupMemberList.Sum(a => decimal.Parse(a.ContributionTotal)); this.PercentComplete = decimal.Round(this.GroupIndividualFundraisingGoal == 0 ? 100 : this.GroupContributionTotal / (this.GroupIndividualFundraisingGoal * 0.01M), 2); this.ProgressCssClass = GetProgressCssClass(this.PercentComplete); rptFundingProgress.DataSource = groupMemberList; rptFundingProgress.DataBind(); }
/// <summary> /// Sends the email. /// </summary> private bool SendEmail() { var rockContext = new RockContext(); var personAliasService = new PersonAliasService(rockContext); var groupService = new GroupService(rockContext); Group group = null; List <Person> recipients = new List <Person>(); // get person from url if (PageParameter("PersonGuid").IsNotNullOrWhiteSpace()) { Guid?personGuid = this.PageParameter("PersonGuid").AsGuidOrNull(); if (personGuid.HasValue) { var person = personAliasService.Get(personGuid.Value); if (person != null) { recipients.Add(person.Person); } } } // get group members from url if (PageParameter("GroupGuid").IsNotNullOrWhiteSpace()) { Guid?groupGuid = PageParameter("GroupGuid").AsGuidOrNull(); if (groupGuid.HasValue) { group = groupService.Get(groupGuid.Value); recipients.AddRange(GetGroupLeaders(group)); } } if (!recipients.Any()) { Guid defaultRecipient = this.GetAttributeValue("DefaultRecipient").AsGuid(); var defaultPerson = personAliasService.Get(defaultRecipient); if (defaultPerson != null) { recipients.Add(defaultPerson.Person); } } if (!recipients.Any()) { Guid defaultGroupGuid = GetAttributeValue("LeaderGroup").AsGuid(); var defaultGroup = groupService.Get(defaultGroupGuid); recipients.AddRange(GetGroupLeaders(defaultGroup)); } if (!cpCaptcha.IsAvailable || cpCaptcha.IsResponseValid()) { var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(this.RockPage, this.CurrentPerson); mergeFields.Add("NickName", tbFirstName.Text); mergeFields.Add("LastName", tbLastName.Text); mergeFields.Add("Email", tbEmail.Text); mergeFields.Add("Group", group); mergeFields.Add("Message", tbMessage.Text); mergeFields.Add("FromEmail", tbEmail.Text); mergeFields.Add("FromName", tbFirstName.Text + " " + tbLastName.Text); var message = new RockEmailMessage(); message.EnabledLavaCommands = GetAttributeValue("EnabledLavaCommands"); // send email foreach (var recipient in recipients) { message.AddRecipient(new RecipientData(new CommunicationRecipient { PersonAlias = recipient.PrimaryAlias }, mergeFields)); } message.FromEmail = tbEmail.Text; message.FromName = tbFirstName.Text + " " + tbLastName.Text; message.Subject = GetAttributeValue("Subject"); message.Message = GetAttributeValue("MessageBody"); message.AppRoot = ResolveRockUrl("~/"); message.ThemeRoot = ResolveRockUrl("~~/"); message.CreateCommunicationRecord = GetAttributeValue("SaveCommunicationHistory").AsBoolean(); message.Send(); // set response // display response message lResponse.Visible = true; pnlContactGroupLeaders.Visible = false; lResponse.Text = GetAttributeValue("ResponseMessage").ResolveMergeFields(mergeFields, GetAttributeValue("EnabledLavaCommands")); return(true); } else { lResponse.Visible = true; pnlContactGroupLeaders.Visible = true; lResponse.Text = "<div class='alert alert-danger'>You appear to be a computer. Check the box above and then click Submit.</div>"; return(false); } }
/// <summary> /// Adds the new family address. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="family">The family.</param> /// <param name="locationTypeGuid">The location type unique identifier.</param> /// <param name="location">The location.</param> /// <param name="moveExistingToPrevious">if set to <c>true</c> [move existing to previous].</param> public static void AddNewFamilyAddress(RockContext rockContext, Group family, string locationTypeGuid, Location location, bool moveExistingToPrevious = false) { if (location != null) { var locationType = Rock.Web.Cache.DefinedValueCache.Read(locationTypeGuid.AsGuid()); if (locationType != null) { var groupLocationService = new GroupLocationService(rockContext); if (!groupLocationService.Queryable() .Where(gl => gl.GroupId == family.Id && gl.GroupLocationTypeValueId == locationType.Id && gl.LocationId == location.Id) .Any()) { var familyChanges = new List <string>(); if (moveExistingToPrevious) { var prevLocationType = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_PREVIOUS); if (prevLocationType != null) { foreach (var prevLoc in groupLocationService.Queryable("Location,GroupLocationTypeValue") .Where(gl => gl.GroupId == family.Id && gl.GroupLocationTypeValueId == locationType.Id)) { History.EvaluateChange(familyChanges, prevLoc.Location.ToString(), prevLoc.GroupLocationTypeValue.Value, prevLocationType.Value); prevLoc.GroupLocationTypeValueId = prevLocationType.Id; prevLoc.IsMailingLocation = false; prevLoc.IsMappedLocation = false; } } } string addressChangeField = locationType.Value; var groupLocation = groupLocationService.Queryable() .Where(gl => gl.GroupId == family.Id && gl.LocationId == location.Id) .FirstOrDefault(); if (groupLocation == null) { groupLocation = new GroupLocation(); groupLocation.Location = location; groupLocation.IsMailingLocation = true; groupLocation.IsMappedLocation = true; family.GroupLocations.Add(groupLocation); } groupLocation.GroupLocationTypeValueId = locationType.Id; History.EvaluateChange(familyChanges, addressChangeField, string.Empty, groupLocation.Location.ToString()); History.EvaluateChange(familyChanges, addressChangeField + " Is Mailing", string.Empty, groupLocation.IsMailingLocation.ToString()); History.EvaluateChange(familyChanges, addressChangeField + " Is Map Location", string.Empty, groupLocation.IsMappedLocation.ToString()); rockContext.SaveChanges(); foreach (var fm in family.Members) { HistoryService.SaveChanges(rockContext, typeof(Person), Rock.SystemGuid.Category.HISTORY_PERSON_FAMILY_CHANGES.AsGuid(), fm.PersonId, familyChanges, family.Name, typeof(Group), family.Id); } } } } }
/// <summary> /// Saves the new family. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="familyMembers">The family members.</param> /// <param name="campusId">The campus identifier.</param> /// <param name="savePersonAttributes">if set to <c>true</c> [save person attributes].</param> /// <returns></returns> public static Group SaveNewFamily(RockContext rockContext, List <GroupMember> familyMembers, int?campusId, bool savePersonAttributes) { var familyGroupType = GroupTypeCache.GetFamilyGroupType(); var familyChanges = new List <string>(); var familyMemberChanges = new Dictionary <Guid, List <string> >(); var familyDemographicChanges = new Dictionary <Guid, List <string> >(); if (familyGroupType != null) { var groupService = new GroupService(rockContext); var familyGroup = new Group(); familyGroup.GroupTypeId = familyGroupType.Id; familyGroup.Name = familyMembers.FirstOrDefault().Person.LastName + " Family"; History.EvaluateChange(familyChanges, "Family", string.Empty, familyGroup.Name); if (campusId.HasValue) { History.EvaluateChange(familyChanges, "Campus", string.Empty, CampusCache.Read(campusId.Value).Name); } familyGroup.CampusId = campusId; int?childRoleId = null; var childRole = new GroupTypeRoleService(rockContext).Get(new Guid(Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_CHILD)); if (childRole != null) { childRoleId = childRole.Id; } foreach (var familyMember in familyMembers) { var person = familyMember.Person; if (person != null) { familyGroup.Members.Add(familyMember); var demographicChanges = new List <string>(); demographicChanges.Add("Created"); History.EvaluateChange(demographicChanges, "Record Type", string.Empty, person.RecordTypeValueId.HasValue ? DefinedValueCache.GetName(person.RecordTypeValueId.Value) : string.Empty); History.EvaluateChange(demographicChanges, "Record Status", string.Empty, person.RecordStatusValueId.HasValue ? DefinedValueCache.GetName(person.RecordStatusValueId.Value) : string.Empty); History.EvaluateChange(demographicChanges, "Record Status Reason", string.Empty, person.RecordStatusReasonValueId.HasValue ? DefinedValueCache.GetName(person.RecordStatusReasonValueId.Value) : string.Empty); History.EvaluateChange(demographicChanges, "Connection Status", string.Empty, person.ConnectionStatusValueId.HasValue ? DefinedValueCache.GetName(person.ConnectionStatusValueId) : string.Empty); History.EvaluateChange(demographicChanges, "Deceased", false.ToString(), (person.IsDeceased).ToString()); History.EvaluateChange(demographicChanges, "Title", string.Empty, person.TitleValueId.HasValue ? DefinedValueCache.GetName(person.TitleValueId) : string.Empty); History.EvaluateChange(demographicChanges, "First Name", string.Empty, person.FirstName); History.EvaluateChange(demographicChanges, "Nick Name", string.Empty, person.NickName); History.EvaluateChange(demographicChanges, "Middle Name", string.Empty, person.MiddleName); History.EvaluateChange(demographicChanges, "Last Name", string.Empty, person.LastName); History.EvaluateChange(demographicChanges, "Suffix", string.Empty, person.SuffixValueId.HasValue ? DefinedValueCache.GetName(person.SuffixValueId) : string.Empty); History.EvaluateChange(demographicChanges, "Birth Date", null, person.BirthDate); History.EvaluateChange(demographicChanges, "Gender", null, person.Gender); History.EvaluateChange(demographicChanges, "Marital Status", string.Empty, person.MaritalStatusValueId.HasValue ? DefinedValueCache.GetName(person.MaritalStatusValueId) : string.Empty); History.EvaluateChange(demographicChanges, "Anniversary Date", null, person.AnniversaryDate); History.EvaluateChange(demographicChanges, "Graduation Year", null, person.GraduationYear); History.EvaluateChange(demographicChanges, "Email", string.Empty, person.Email); History.EvaluateChange(demographicChanges, "Email Active", false.ToString(), person.IsEmailActive.ToString()); History.EvaluateChange(demographicChanges, "Email Note", string.Empty, person.EmailNote); History.EvaluateChange(demographicChanges, "Email Preference", null, person.EmailPreference); History.EvaluateChange(demographicChanges, "Inactive Reason Note", string.Empty, person.InactiveReasonNote); History.EvaluateChange(demographicChanges, "System Note", string.Empty, person.SystemNote); familyDemographicChanges.Add(person.Guid, demographicChanges); var memberChanges = new List <string>(); string roleName = familyGroupType.Roles .Where(r => r.Id == familyMember.GroupRoleId) .Select(r => r.Name) .FirstOrDefault(); History.EvaluateChange(memberChanges, "Role", string.Empty, roleName); familyMemberChanges.Add(person.Guid, memberChanges); } } groupService.Add(familyGroup); rockContext.SaveChanges(); var personService = new PersonService(rockContext); foreach (var groupMember in familyMembers) { var person = groupMember.Person; if (savePersonAttributes) { var newValues = person.AttributeValues; person.LoadAttributes(); foreach (var attributeCache in person.Attributes.Select(a => a.Value)) { string oldValue = person.GetAttributeValue(attributeCache.Key) ?? string.Empty; string newValue = string.Empty; if (newValues != null && newValues.ContainsKey(attributeCache.Key) && newValues[attributeCache.Key] != null) { newValue = newValues[attributeCache.Key].Value ?? string.Empty; } if (!oldValue.Equals(newValue)) { History.EvaluateChange(familyDemographicChanges[person.Guid], attributeCache.Name, attributeCache.FieldType.Field.FormatValue(null, oldValue, attributeCache.QualifierValues, false), attributeCache.FieldType.Field.FormatValue(null, newValue, attributeCache.QualifierValues, false)); Rock.Attribute.Helper.SaveAttributeValue(person, attributeCache, newValue); } } } person = personService.Get(groupMember.PersonId); if (person != null) { bool updateRequired = false; var changes = familyDemographicChanges[person.Guid]; if (groupMember.GroupRoleId != childRoleId) { person.GivingGroupId = familyGroup.Id; updateRequired = true; History.EvaluateChange(changes, "Giving Group", string.Empty, familyGroup.Name); } if (updateRequired) { rockContext.SaveChanges(); } HistoryService.SaveChanges(rockContext, typeof(Person), Rock.SystemGuid.Category.HISTORY_PERSON_DEMOGRAPHIC_CHANGES.AsGuid(), person.Id, changes); HistoryService.SaveChanges(rockContext, typeof(Person), Rock.SystemGuid.Category.HISTORY_PERSON_FAMILY_CHANGES.AsGuid(), person.Id, familyMemberChanges[person.Guid], familyGroup.Name, typeof(Group), familyGroup.Id); HistoryService.SaveChanges(rockContext, typeof(Person), Rock.SystemGuid.Category.HISTORY_PERSON_FAMILY_CHANGES.AsGuid(), person.Id, familyChanges, familyGroup.Name, typeof(Group), familyGroup.Id); } } return(familyGroup); } return(null); }
/// <summary> /// Gets the properties and attributes for the entity /// </summary> /// <param name="groupTypeId">The group type identifier.</param> /// <returns></returns> private List<EntityField> GetGroupAttributes( int? groupTypeId ) { List<EntityField> entityAttributeFields = new List<EntityField>(); if ( groupTypeId.HasValue ) { var fakeGroup = new Rock.Model.Group { GroupTypeId = groupTypeId.Value }; Rock.Attribute.Helper.LoadAttributes( fakeGroup ); foreach ( var attribute in fakeGroup.Attributes.Select( a => a.Value ) ) { EntityHelper.AddEntityFieldForAttribute( entityAttributeFields, attribute ); } } // start at 2 since the first two controls will be grouptype and property selection int index = 2; var sortedFields = new List<EntityField>(); foreach ( var entityProperty in entityAttributeFields.OrderBy( p => p.Title ).ThenBy( p => p.Name ) ) { entityProperty.Index = index; index += entityProperty.ControlCount; sortedFields.Add( entityProperty ); } return sortedFields; }
/// <summary> /// Returns a <see cref="System.String" /> that represents this instance. /// </summary> /// <returns> /// A <see cref="System.String" /> that represents this instance. /// </returns> public override string ToString() { return(Group.ToStringSafe() + " at " + Location.ToStringSafe()); }
/// <summary> /// Sends the email. /// </summary> private bool SendMessage() { var rockContext = new RockContext(); var personAliasService = new PersonAliasService(rockContext); var groupService = new GroupService(rockContext); var publishGroupService = new PublishGroupService(rockContext); Group group = null; PublishGroup publishGroup = null; bool allowSMS = GetAttributeValue("EnableSMS").AsBoolean(); var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(this.RockPage, this.CurrentPerson); List <Person> emailRecipients = new List <Person>(); List <Person> smsRecipients = new List <Person>(); // get person from url if (PageParameter("PersonGuid").IsNotNullOrWhiteSpace()) { Guid?personGuid = this.PageParameter("PersonGuid").AsGuidOrNull(); if (personGuid.HasValue) { var person = personAliasService.Queryable() .Where(pa => pa.Guid == personGuid.Value) .Select(pa => pa.Person) .FirstOrDefault(); var phoneNumber = person.PhoneNumbers.GetFirstSmsNumber(); if (person != null && allowSMS && person.CommunicationPreference == CommunicationType.SMS && phoneNumber.IsNotNullOrWhiteSpace()) { smsRecipients.Add(person); } else { emailRecipients.Add(person); } } } // get group members from url if (PageParameter("GroupGuid").IsNotNullOrWhiteSpace()) { Guid?groupGuid = PageParameter("GroupGuid").AsGuidOrNull(); if (groupGuid.HasValue) { group = groupService.Get(groupGuid.Value); var leaders = GetGroupLeaders(group); foreach (var leader in leaders) { var phonenumber = leader.PhoneNumbers.GetFirstSmsNumber(); if (allowSMS && leader.CommunicationPreference == CommunicationType.SMS && phonenumber.IsNotNullOrWhiteSpace()) { smsRecipients.Add(leader); } else { emailRecipients.Add(leader); } } } } // get group members from url if (PageParameter("PublishGroupGuid").IsNotNullOrWhiteSpace()) { Guid?publishGroupGuid = PageParameter("PublishGroupGuid").AsGuidOrNull(); if (publishGroupGuid.HasValue) { publishGroup = publishGroupService.Get(publishGroupGuid.Value); if (publishGroup != null) { var person = new Person { Email = publishGroup.ContactEmail }; emailRecipients.Add(person); } } } if (!emailRecipients.Any() && !smsRecipients.Any()) { Guid defaultRecipient = this.GetAttributeValue("DefaultRecipient").AsGuid(); var defaultPerson = personAliasService.Queryable() .Where(pa => pa.Guid == defaultRecipient) .Select(pa => pa.Person) .FirstOrDefault(); if (defaultPerson != null) { var phonenumber = defaultPerson.PhoneNumbers.GetFirstSmsNumber(); if (allowSMS && defaultPerson.CommunicationPreference == CommunicationType.SMS && phonenumber.IsNotNullOrWhiteSpace()) { smsRecipients.Add(defaultPerson); } else { emailRecipients.Add(defaultPerson); } } } if (!emailRecipients.Any() && !smsRecipients.Any()) { Guid defaultGroupGuid = GetAttributeValue("LeaderGroup").AsGuid(); var defaultGroup = groupService.Get(defaultGroupGuid); var leaders = GetGroupLeaders(defaultGroup); foreach (var leader in leaders) { var phonenumber = leader.PhoneNumbers.GetFirstSmsNumber(); if (allowSMS && leader.CommunicationPreference == CommunicationType.SMS && phonenumber.IsNotNullOrWhiteSpace()) { smsRecipients.Add(leader); } else { emailRecipients.Add(leader); } } } if (!cpCaptcha.IsAvailable || cpCaptcha.IsResponseValid()) { mergeFields.Add("NickName", tbFirstName.Text); mergeFields.Add("LastName", tbLastName.Text); mergeFields.Add("Email", tbEmail.Text); mergeFields.Add("PublishGroup", publishGroup); mergeFields.Add("Group", group); mergeFields.Add("Message", tbMessage.Text); mergeFields.Add("FromEmail", tbEmail.Text); mergeFields.Add("FromName", tbFirstName.Text + " " + tbLastName.Text); if (emailRecipients.Any()) { SendEmail(emailRecipients, mergeFields); } if (smsRecipients.Any()) { SendTextMessage(smsRecipients, mergeFields); } // display response message lResponse.Visible = true; pnlContactGroupLeaders.Visible = false; lResponse.Text = GetAttributeValue("ResponseMessage").ResolveMergeFields(mergeFields, GetAttributeValue("EnabledLavaCommands")); return(true); } else { lResponse.Visible = true; pnlContactGroupLeaders.Visible = true; lResponse.Text = "<div class='alert alert-danger'>You appear to be a computer. Check the box above and then click Submit.</div>"; return(false); } }