protected void btnDelete_Click(object sender, EventArgs e) { LinkButton btn = ( LinkButton )sender; GridViewRow gvr = ( GridViewRow )btn.NamingContainer; var hfPublishGroupId = ( HiddenField )gvr.FindControl("hfPublishGroupId"); var publishGroupId = hfPublishGroupId.Value.AsInteger(); using (RockContext rockContext = new RockContext()) { PublishGroupService publishGroupService = new PublishGroupService(rockContext); var publishGroup = publishGroupService.Get(publishGroupId); if (publishGroup != null) { if (this.IsUserAuthorized(Rock.Security.Authorization.EDIT) || publishGroup.ContactPersonAlias.Person.Id == CurrentPersonId || publishGroup.CreatedByPersonId == CurrentPersonId) { publishGroupService.Delete(publishGroup); rockContext.SaveChanges(); } else { maAlert.Show("We are sorry, you are not permitted to delete this publish group.", ModalAlertType.Alert); } } } BindGrid(); }
/// <summary>Gets the publish group.</summary> /// <param name="rockContext">The rock context.</param> /// <param name="publishGroupService">The publish group service.</param> /// <returns></returns> private PublishGroup GetPublishGroup(RockContext rockContext = null, PublishGroupService publishGroupService = null) { rockContext = rockContext ?? new RockContext(); publishGroupService = publishGroupService ?? new PublishGroupService(rockContext); if (PageParameter(PageParameterKeys.PublishGroupId).IsNotNullOrWhiteSpace()) { var publishGroup = publishGroupService.Get(PageParameter(PageParameterKeys.PublishGroupId).AsInteger()); if (publishGroup != null) { return(publishGroup); } } if (PageParameter(PageParameterKeys.GroupId).IsNotNullOrWhiteSpace()) { int groupId = PageParameter(PageParameterKeys.GroupId).AsInteger(); GroupService groupService = new GroupService(rockContext); var group = groupService.Get(groupId); if (group != null) { var publishGroup = publishGroupService.Queryable() .Where(pg => pg.GroupId == groupId) .ToList() .LastOrDefault(); if (publishGroup != null) { return(publishGroup); } publishGroup = new PublishGroup { PublishGroupStatus = PublishGroupStatus.PendingApproval, RegistrationRequirement = RegistrationRequirement.NoRegistration, ChildcareOptions = ChildcareOptions.NoChildcare, Group = group, RequestorAliasId = CurrentPersonAliasId.Value, ConfirmationBody = GetAttributeValue(AttributeKeys.DefaultEmail), RegistrationDescription = GetAttributeValue(AttributeKeys.RegistrationDetails), ChildcareRegistrationDescription = GetAttributeValue(AttributeKeys.ChildcareRegistrationDetails) }; if (group.Schedule != null) { publishGroup.WeeklyDayOfWeek = group.Schedule.WeeklyDayOfWeek; publishGroup.WeeklyTimeOfDay = group.Schedule.WeeklyTimeOfDay; } if (group.GroupLocations.Any()) { publishGroup.MeetingLocation = group.GroupLocations.FirstOrDefault().Location.Name; } return(publishGroup); } } return(null); }
private PublishGroup GetPublishGroup(RockContext rockContext = null, PublishGroupService publishGroupService = null) { rockContext = rockContext ?? new RockContext(); publishGroupService = publishGroupService ?? new PublishGroupService(rockContext); if (PageParameter("PublishGroupId").IsNotNullOrWhiteSpace()) { var publishGroup = publishGroupService.Get(PageParameter("PublishGroupId").AsInteger()); if (publishGroup != null) { return(publishGroup); } } if (PageParameter("GroupId").IsNotNullOrWhiteSpace()) { int groupId = PageParameter("GroupId").AsInteger(); GroupService groupService = new GroupService(rockContext); var group = groupService.Get(groupId); if (group != null) { var publishGroup = publishGroupService.Queryable() .Where(pg => pg.GroupId == groupId) .ToList() .LastOrDefault(); if (publishGroup != null) { return(publishGroup); } publishGroup = new PublishGroup { PublishGroupStatus = PublishGroupStatus.Pending, Group = group, RequestorAliasId = CurrentPersonAliasId.Value }; if (group.Schedule != null) { publishGroup.WeeklyDayOfWeek = group.Schedule.WeeklyDayOfWeek; publishGroup.WeeklyTimeOfDay = group.Schedule.WeeklyTimeOfDay; } if (group.GroupLocations.Any()) { publishGroup.MeetingLocation = group.GroupLocations.FirstOrDefault().Location.Name; } return(publishGroup); } } return(null); }
/// <summary> /// Checks the settings. If false is returned, it's expected that the caller will make /// the nbNotice visible to inform the user of the "settings" error. /// </summary> /// <returns>true if settings are valid; false otherwise</returns> private bool CheckSettings() { _rockContext = _rockContext ?? new RockContext(); _autoFill = GetAttributeValue("AutoFillForm").AsBoolean(); string registerButtonText = GetAttributeValue("RegisterButtonAltText"); if (string.IsNullOrWhiteSpace(registerButtonText)) { registerButtonText = "Register"; } btnRegister.Text = registerButtonText; var publishGroupService = new PublishGroupService(_rockContext); if (_publishGroup == null) { var publishGroupGuid = PageParameter("PublishGroup").AsGuidOrNull(); if (publishGroupGuid.HasValue) { _publishGroup = publishGroupService.Get(publishGroupGuid.Value); } else { var slug = PageParameter("PublishGroup").ToLower(); _publishGroup = publishGroupService.Queryable().Where(pg => pg.Slug == slug).FirstOrDefault(); } } if (_publishGroup == null || _publishGroup.PublishGroupStatus != PublishGroupStatus.Approved) { nbNotice.Heading = "Unknown Group"; nbNotice.Text = "<p>This page requires a valid group identifying parameter and there was not one provided.</p>"; nbNotice.Visible = true; return(false); } if (_publishGroup.RegistrationLink.IsNotNullOrWhiteSpace()) { Response.Redirect(_publishGroup.RegistrationLink, false); Context.ApplicationInstance.CompleteRequest(); return(false); } _showSpouse = _publishGroup.AllowSpouseRegistration; _defaultGroupRole = _publishGroup.Group.GroupType.DefaultGroupRole; _dvcConnectionStatus = DefinedValueCache.Get(GetAttributeValue("ConnectionStatus").AsGuid()); if (_dvcConnectionStatus == null) { nbNotice.Heading = "Invalid Connection Status"; nbNotice.Text = "<p>The selected Connection Status setting does not exist.</p>"; return(false); } _dvcRecordStatus = DefinedValueCache.Get(GetAttributeValue("RecordStatus").AsGuid()); if (_dvcRecordStatus == null) { nbNotice.Heading = "Invalid Record Status"; nbNotice.Text = "<p>The selected Record Status setting does not exist.</p>"; return(false); } _married = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSON_MARITAL_STATUS_MARRIED.AsGuid()); _homeAddressType = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME.AsGuid()); _familyType = GroupTypeCache.Get(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid()); _adultRole = _familyType.Roles.FirstOrDefault(r => r.Guid.Equals(Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid())); if (_married == null || _homeAddressType == null || _familyType == null || _adultRole == null) { nbNotice.Heading = "Missing System Value"; nbNotice.Text = "<p>There is a missing or invalid system value. Check the settings for Marital Status of 'Married', Location Type of 'Home', Group Type of 'Family', and Family Group Role of 'Adult'.</p>"; return(false); } return(true); }
/// <summary> /// Sends the email. /// </summary> private bool SendEmail() { 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; var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(this.RockPage, this.CurrentPerson); List <RecipientData> recipients = new List <RecipientData>(); // get person from url if (PageParameter("PersonGuid").IsNotNullOrWhiteSpace()) { Guid?personGuid = this.PageParameter("PersonGuid").AsGuidOrNull(); if (personGuid.HasValue) { var personAlias = personAliasService.Get(personGuid.Value); if (personAlias != null) { recipients.Add(new RecipientData(new CommunicationRecipient { PersonAlias = personAlias }, mergeFields)); } } } // 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) { recipients.Add(new RecipientData(new CommunicationRecipient { PersonAlias = leader.PrimaryAlias }, mergeFields)); } } } // 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) { recipients.Add(new RecipientData(publishGroup.ContactEmail, mergeFields)); } } } if (!recipients.Any()) { Guid defaultRecipient = this.GetAttributeValue("DefaultRecipient").AsGuid(); var defaultPerson = personAliasService.Get(defaultRecipient); if (defaultPerson != null) { recipients.Add(new RecipientData(new CommunicationRecipient { PersonAlias = defaultPerson }, mergeFields)); } } if (!recipients.Any()) { Guid defaultGroupGuid = GetAttributeValue("LeaderGroup").AsGuid(); var defaultGroup = groupService.Get(defaultGroupGuid); var leaders = GetGroupLeaders(defaultGroup); foreach (var leader in leaders) { recipients.Add(new RecipientData(new CommunicationRecipient { PersonAlias = leader.PrimaryAlias }, mergeFields)); } } 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); var message = new RockEmailMessage(); message.EnabledLavaCommands = GetAttributeValue("EnabledLavaCommands"); // send email foreach (var recipient in recipients) { message.AddRecipient(recipient); } 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> /// 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); } }