/// <summary> /// Handles the Click event of the btnSubmit control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSubmit_Click(object sender, EventArgs e) { if (Page.IsValid) { using (new UnitOfWorkScope()) { var service = new CommunicationService(); var communication = UpdateCommunication(service); if (communication != null) { string message = string.Empty; var prevStatus = communication.Status; if (CheckApprovalRequired(communication.Recipients.Count) && !IsUserAuthorized("Approve")) { communication.Status = CommunicationStatus.Submitted; message = "Communication has been submitted for approval."; } else { communication.Status = CommunicationStatus.Approved; communication.ReviewedDateTime = DateTime.Now; communication.ReviewerPersonId = CurrentPersonId; message = "Communication has been queued for sending."; // TODO: Send notice to sender that communication was approved } communication.Recipients .Where(r => r.Status == CommunicationRecipientStatus.Cancelled || r.Status == CommunicationRecipientStatus.Failed) .ToList() .ForEach(r => { r.Status = CommunicationRecipientStatus.Pending; r.StatusNote = string.Empty; } ); service.Save(communication, CurrentPersonId); if (communication.Status == CommunicationStatus.Approved) { bool sendNow = false; if (bool.TryParse(GetAttributeValue("SendWhenApproved"), out sendNow) && sendNow) { var transaction = new Rock.Transactions.SendCommunicationTransaction(); transaction.CommunicationId = communication.Id; transaction.PersonId = CurrentPersonId; Rock.Transactions.RockQueue.TransactionQueue.Enqueue(transaction); } } ShowResult(message, communication); } } } }
protected void btnSMSSend_Click(object sender, EventArgs e) { bool sendToParents = cbEmailSendToParents.Checked; string subject = tbSubject.Text; string body = tbBody.Text; if (Page.IsValid) { _rockContext = new RockContext(); var communication = UpdateCommunication(_rockContext); if (communication != null) { AddRecepients(communication, cbSMSSendToParents.Checked); communication.SMSMessage = tbMessage.Text; communication.SMSFromDefinedValueId = DefinedValueCache.Get(CurrentGroup.GetAttributeValue("TextMessageFrom").AsGuid()).Id; communication.Status = CommunicationStatus.Approved; communication.ReviewedDateTime = RockDateTime.Now; communication.ReviewerPersonAliasId = CurrentPersonAliasId; _rockContext.SaveChanges(); var transaction = new Rock.Transactions.SendCommunicationTransaction(); transaction.CommunicationId = communication.Id; transaction.PersonAlias = CurrentPersonAlias; Rock.Transactions.RockQueue.TransactionQueue.Enqueue(transaction); } } cbSMSSendToParents.Checked = false; pnlEmail.Visible = false; pnlSMS.Visible = false; pnlMain.Visible = true; maSent.Show("Your message will be been sent shortly.", ModalAlertType.Information); }
/// <summary> /// Creates a new communication. /// </summary> /// <param name="fromPersonAliasId">From person alias identifier.</param> /// <param name="fromPersonName">Name of from person.</param> /// <param name="toPersonAliasId">To person alias identifier.</param> /// <param name="message">The message to send.</param> /// <param name="transportPhone">The transport phone.</param> /// <param name="responseCode">The reponseCode to use for tracking the conversation.</param> /// <param name="rockContext">A context to use for database calls.</param> private void CreateCommunication(int fromPersonAliasId, string fromPersonName, int toPersonAliasId, string message, string transportPhone, string responseCode, Rock.Data.RockContext rockContext) { // add communication for reply var communication = new Rock.Model.Communication(); communication.IsBulkCommunication = false; communication.Status = CommunicationStatus.Approved; communication.SenderPersonAliasId = fromPersonAliasId; communication.Subject = string.Format("From: {0}", fromPersonName); communication.SetMediumDataValue("Message", message); communication.SetMediumDataValue("FromValue", transportPhone); communication.MediumEntityTypeId = EntityTypeCache.Read("Rock.Communication.Medium.Sms").Id; var recipient = new Rock.Model.CommunicationRecipient(); recipient.Status = CommunicationRecipientStatus.Pending; recipient.PersonAliasId = toPersonAliasId; recipient.ResponseCode = responseCode; communication.Recipients.Add(recipient); var communicationService = new Rock.Model.CommunicationService(rockContext); communicationService.Add(communication); rockContext.SaveChanges(); // queue the sending var transaction = new Rock.Transactions.SendCommunicationTransaction(); transaction.CommunicationId = communication.Id; transaction.PersonAlias = null; Rock.Transactions.RockQueue.TransactionQueue.Enqueue(transaction); }
/// <summary> /// Handles the Click event of the btnSubmit control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSubmit_Click(object sender, EventArgs e) { if (Page.IsValid) { var rockContext = new RockContext(); var communication = UpdateCommunication(rockContext); if (communication != null) { string message = string.Empty; if (CheckApprovalRequired(communication.Recipients.Count) && !IsUserAuthorized("Approve")) { communication.Status = CommunicationStatus.PendingApproval; message = "Communication has been submitted for approval."; } else { communication.Status = CommunicationStatus.Approved; communication.ReviewedDateTime = RockDateTime.Now; communication.ReviewerPersonAliasId = CurrentPersonAliasId; if (communication.FutureSendDateTime.HasValue && communication.FutureSendDateTime > RockDateTime.Now) { message = string.Format("Communication will be sent {0}.", communication.FutureSendDateTime.Value.ToRelativeDateString(0)); } else { message = "Communication has been queued for sending."; } } rockContext.SaveChanges(); if (communication.Status == CommunicationStatus.Approved && (!communication.FutureSendDateTime.HasValue || communication.FutureSendDateTime.Value <= RockDateTime.Now)) { if (GetAttributeValue("SendWhenApproved").AsBoolean()) { var transaction = new Rock.Transactions.SendCommunicationTransaction(); transaction.CommunicationId = communication.Id; transaction.PersonAlias = CurrentPersonAlias; Rock.Transactions.RockQueue.TransactionQueue.Enqueue(transaction); } } ShowResult(message, communication); } } }
private void SendTextMessage(List <Person> smsRecipients, Dictionary <string, object> mergeFields) { var rockContext = new RockContext(); var communicationService = new CommunicationService(rockContext); var communicationRecipientService = new CommunicationRecipientService(rockContext); var communication = new Rock.Model.Communication(); communication.Status = CommunicationStatus.Approved; communication.SenderPersonAliasId = CurrentPerson.PrimaryAliasId; communicationService.Add(communication); communication.EnabledLavaCommands = GetAttributeValue("EnabledLavaCommands"); communication.IsBulkCommunication = false; communication.CommunicationType = CommunicationType.SMS; communication.ListGroup = null; communication.ListGroupId = null; communication.ExcludeDuplicateRecipientAddress = true; communication.CommunicationTemplateId = null; communication.FromName = mergeFields["FromName"].ToString().TrimForMaxLength(communication, "FromName"); communication.FromEmail = mergeFields["FromEmail"].ToString().TrimForMaxLength(communication, "FromEmail"); communication.Subject = GetAttributeValue("Subject"); communication.Message = GetAttributeValue("MessageBody"); communication.SMSFromDefinedValueId = DefinedValueCache.GetId(GetAttributeValue("SMSFromNumber").AsGuid()); communication.SMSMessage = GetAttributeValue("SMSMessageBody"); communication.FutureSendDateTime = null; communicationService.Add(communication); rockContext.SaveChanges(); foreach (var smsPerson in smsRecipients) { communication.Recipients.Add(new CommunicationRecipient() { PersonAliasId = smsPerson.PrimaryAliasId, MediumEntityTypeId = EntityTypeCache.Get(Rock.SystemGuid.EntityType.COMMUNICATION_MEDIUM_SMS.AsGuid()).Id, AdditionalMergeValues = mergeFields }); } rockContext.SaveChanges(); var transaction = new Rock.Transactions.SendCommunicationTransaction(); transaction.CommunicationId = communication.Id; transaction.PersonAlias = CurrentPersonAlias; Rock.Transactions.RockQueue.TransactionQueue.Enqueue(transaction); }
/// <summary> /// Creates the communication to the recipent's mobile device. /// </summary> /// <param name="fromPerson">From person.</param> /// <param name="toPersonAliasId">To person alias identifier.</param> /// <param name="message">The message.</param> /// <param name="fromPhone">From phone.</param> /// <param name="responseCode">The response code.</param> /// <param name="rockContext">The rock context.</param> public static void CreateCommunicationMobile(Person fromPerson, int?toPersonAliasId, string message, DefinedValueCache fromPhone, string responseCode, Rock.Data.RockContext rockContext) { string communicationName = fromPerson != null?string.Format("From: {0}", fromPerson.FullName) : "From: unknown person"; var communicationService = new CommunicationService(rockContext); var communication = communicationService.CreateSMSCommunication(fromPerson, toPersonAliasId, message, fromPhone, responseCode, communicationName); rockContext.SaveChanges(); // queue the sending var transaction = new Rock.Transactions.SendCommunicationTransaction(); transaction.CommunicationId = communication.Id; transaction.PersonAlias = null; Rock.Transactions.RockQueue.TransactionQueue.Enqueue(transaction); }
/// <summary> /// Handles the Click event of the btnSendConfirmed control which sends the actual communication. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnSendConfirmed_Click(object sender, EventArgs e) { if (Page.IsValid && CurrentPerson != null) { SetActionButtons(resetToSend: true); var people = GetMatchingPeople(); // Get new communication record var rockContext = new RockContext(); var communication = GetCommunication(rockContext, people.Select(p => p.Id).ToList()); if (communication != null) { string message = string.Empty; if (CheckApprovalRequired(communication.Recipients.Count) && !IsUserAuthorized("Approve")) { communication.Status = CommunicationStatus.PendingApproval; message = "Communication has been submitted for approval."; } else { communication.Status = CommunicationStatus.Approved; communication.ReviewedDateTime = RockDateTime.Now; communication.ReviewerPersonAliasId = CurrentPersonAliasId; message = "Communication has been queued for sending."; } rockContext.SaveChanges(); if (communication.Status == CommunicationStatus.Approved) { var transaction = new Rock.Transactions.SendCommunicationTransaction(); transaction.CommunicationId = communication.Id; transaction.PersonAlias = CurrentPersonAlias; Rock.Transactions.RockQueue.TransactionQueue.Enqueue(transaction); } pnlSuccess.Visible = true; pnlForm.Visible = false; nbSuccess.Text = message; } } }
protected void btnEmailSend_Click(object sender, EventArgs e) { bool sendToParents = cbEmailSendToParents.Checked; string subject = tbSubject.Text; string body = tbBody.Text; if (Page.IsValid) { _rockContext = new RockContext(); var communication = UpdateCommunication(_rockContext); if (communication != null) { AddRecepients(communication, cbEmailSendToParents.Checked); communication.MediumEntityTypeId = EntityTypeCache.Read("Rock.Communication.Medium.Email").Id; communication.MediumData.Clear(); communication.Subject = tbSubject.Text; communication.MediumData.Add("FromName", CurrentPerson.FullName); communication.MediumData.Add("FromAddress", GetSafeSender(CurrentPerson.Email)); communication.MediumData.Add("ReplyTo", CurrentPerson.Email); communication.MediumData.Add("TextMessage", tbBody.Text); communication.Status = CommunicationStatus.Approved; communication.ReviewedDateTime = RockDateTime.Now; communication.ReviewerPersonAliasId = CurrentPersonAliasId; _rockContext.SaveChanges(); var transaction = new Rock.Transactions.SendCommunicationTransaction(); transaction.CommunicationId = communication.Id; transaction.PersonAlias = CurrentPersonAlias; Rock.Transactions.RockQueue.TransactionQueue.Enqueue(transaction); } } cbEmailSendToParents.Checked = false; pnlEmail.Visible = false; pnlSMS.Visible = false; pnlMain.Visible = true; maSent.Show("Your message will be sent shortly.", ModalAlertType.Information); }
protected void btnEmailSend_Click(object sender, EventArgs e) { bool sendToParents = cbEmailSendToParents.Checked; if (Page.IsValid) { _rockContext = new RockContext(); var communication = UpdateCommunication(_rockContext); if (communication != null) { AddRecipients(communication, cbEmailSendToParents.Checked, EntityTypeCache.Get(new Guid(Rock.SystemGuid.EntityType.COMMUNICATION_MEDIUM_EMAIL)).Id); communication.CommunicationType = CommunicationType.Email; communication.Subject = tbSubject.Text; communication.FromName = CurrentPerson.FullName; communication.FromEmail = CurrentPerson.Email; communication.ReplyToEmail = CurrentPerson.Email; communication.Message = tbBody.Text.Replace("\n", "<br />"); communication.Status = CommunicationStatus.Approved; communication.ReviewedDateTime = RockDateTime.Now; communication.FutureSendDateTime = RockDateTime.Now; communication.ReviewerPersonAliasId = CurrentPersonAliasId; _rockContext.SaveChanges(); var transaction = new Rock.Transactions.SendCommunicationTransaction(); transaction.CommunicationId = communication.Id; transaction.PersonAlias = CurrentPersonAlias; Rock.Transactions.RockQueue.TransactionQueue.Enqueue(transaction); } } cbEmailSendToParents.Checked = false; pnlEmail.Visible = false; pnlSMS.Visible = false; pnlMain.Visible = true; maSent.Show("Your message will be sent shortly.", ModalAlertType.Information); }
/// <summary> /// Handles the Click event of the btnSubmit control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSubmit_Click( object sender, EventArgs e ) { if ( Page.IsValid ) { var rockContext = new RockContext(); var communication = UpdateCommunication( rockContext ); if ( communication != null ) { var mediumControl = GetMediumControl(); if ( mediumControl != null ) { mediumControl.OnCommunicationSave( rockContext ); } if ( _editingApproved && communication.Status == CommunicationStatus.PendingApproval ) { rockContext.SaveChanges(); // Redirect back to same page without the edit param var pageRef = new Rock.Web.PageReference(); pageRef.PageId = CurrentPageReference.PageId; pageRef.RouteId = CurrentPageReference.RouteId; pageRef.Parameters = new Dictionary<string, string>(); pageRef.Parameters.Add( "CommunicationId", communication.Id.ToString() ); Response.Redirect( pageRef.BuildUrl() ); Context.ApplicationInstance.CompleteRequest(); } else { string message = string.Empty; // Save the communication proir to checking recipients. communication.Status = CommunicationStatus.Draft; rockContext.SaveChanges(); if ( CheckApprovalRequired( communication.GetRecipientCount(rockContext) ) && !IsUserAuthorized( "Approve" ) ) { communication.Status = CommunicationStatus.PendingApproval; message = "Communication has been submitted for approval."; } else { communication.Status = CommunicationStatus.Approved; communication.ReviewedDateTime = RockDateTime.Now; communication.ReviewerPersonAliasId = CurrentPersonAliasId; if ( communication.FutureSendDateTime.HasValue && communication.FutureSendDateTime > RockDateTime.Now ) { message = string.Format( "Communication will be sent {0}.", communication.FutureSendDateTime.Value.ToRelativeDateString( 0 ) ); } else { message = "Communication has been queued for sending."; } } rockContext.SaveChanges(); // send approval email if needed (now that we have a communication id) if ( communication.Status == CommunicationStatus.PendingApproval ) { var approvalTransaction = new Rock.Transactions.SendCommunicationApprovalEmail(); approvalTransaction.CommunicationId = communication.Id; approvalTransaction.ApprovalPageUrl = HttpContext.Current.Request.Url.AbsoluteUri; Rock.Transactions.RockQueue.TransactionQueue.Enqueue( approvalTransaction ); } if ( communication.Status == CommunicationStatus.Approved && ( !communication.FutureSendDateTime.HasValue || communication.FutureSendDateTime.Value <= RockDateTime.Now ) ) { if ( GetAttributeValue( "SendWhenApproved" ).AsBoolean() ) { var transaction = new Rock.Transactions.SendCommunicationTransaction(); transaction.CommunicationId = communication.Id; transaction.PersonAlias = CurrentPersonAlias; Rock.Transactions.RockQueue.TransactionQueue.Enqueue( transaction ); } } ShowResult( message, communication ); } } } }
/// <summary> /// Handles the Click event of the btnSubmit control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSubmit_Click( object sender, EventArgs e ) { if ( Page.IsValid ) { var rockContext = new RockContext(); var communication = UpdateCommunication( rockContext ); if ( communication != null ) { string message = string.Empty; if ( CheckApprovalRequired( communication.Recipients.Count ) && !IsUserAuthorized( "Approve" ) ) { communication.Status = CommunicationStatus.PendingApproval; message = "Communication has been submitted for approval."; } else { communication.Status = CommunicationStatus.Approved; communication.ReviewedDateTime = RockDateTime.Now; communication.ReviewerPersonAliasId = CurrentPersonAliasId; if ( communication.FutureSendDateTime.HasValue && communication.FutureSendDateTime > RockDateTime.Now) { message = string.Format( "Communication will be sent {0}.", communication.FutureSendDateTime.Value.ToRelativeDateString( 0 ) ); } else { message = "Communication has been queued for sending."; } } rockContext.SaveChanges(); if ( communication.Status == CommunicationStatus.Approved && (!communication.FutureSendDateTime.HasValue || communication.FutureSendDateTime.Value <= RockDateTime.Now)) { if ( GetAttributeValue( "SendWhenApproved" ).AsBoolean() ) { var transaction = new Rock.Transactions.SendCommunicationTransaction(); transaction.CommunicationId = communication.Id; transaction.PersonAlias = CurrentPersonAlias; Rock.Transactions.RockQueue.TransactionQueue.Enqueue( transaction ); } } ShowResult( message, communication ); } } }
/// <summary> /// Creates a new communication. /// </summary> /// <param name="fromPersonId">Person ID of the sender.</param> /// <param name="fromPersonName">Name of from person.</param> /// <param name="toPersonId">The Person ID of the recipient.</param> /// <param name="message">The message to send.</param> /// <param name="transportPhone">The transport phone.</param> /// <param name="responseCode">The reponseCode to use for tracking the conversation.</param> /// <param name="rockContext">A context to use for database calls.</param> private void CreateCommunication( int fromPersonId, string fromPersonName, int toPersonId, string message, string transportPhone, string responseCode, Rock.Data.RockContext rockContext ) { // add communication for reply var communication = new Rock.Model.Communication(); communication.IsBulkCommunication = false; communication.Status = CommunicationStatus.Approved; communication.SenderPersonId = fromPersonId; communication.Subject = string.Format( "From: {0}", fromPersonName ); communication.SetChannelDataValue( "Message", message ); communication.SetChannelDataValue( "FromValue", transportPhone ); communication.ChannelEntityTypeId = EntityTypeCache.Read( "Rock.Communication.Channel.Sms" ).Id; var recipient = new Rock.Model.CommunicationRecipient(); recipient.Status = CommunicationRecipientStatus.Pending; recipient.PersonId = toPersonId; recipient.ResponseCode = responseCode; communication.Recipients.Add( recipient ); var communicationService = new Rock.Model.CommunicationService( rockContext ); communicationService.Add( communication ); rockContext.SaveChanges(); // queue the sending var transaction = new Rock.Transactions.SendCommunicationTransaction(); transaction.CommunicationId = communication.Id; transaction.PersonAlias = null; Rock.Transactions.RockQueue.TransactionQueue.Enqueue( transaction ); }
/// <summary> /// Handles the Click event of the btnSendConfirmed control which sends the actual communication. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnSendConfirmed_Click( object sender, EventArgs e ) { if ( Page.IsValid && CurrentPerson != null ) { SetActionButtons( resetToSend: true ); var people = GetMatchingPeople(); // Get new communication record var rockContext = new RockContext(); var communication = GetCommunication( rockContext, people.Select( p => p.Id ).ToList() ); if ( communication != null ) { string message = string.Empty; if ( CheckApprovalRequired( communication.Recipients.Count ) && !IsUserAuthorized( "Approve" ) ) { communication.Status = CommunicationStatus.PendingApproval; message = "Communication has been submitted for approval."; } else { communication.Status = CommunicationStatus.Approved; communication.ReviewedDateTime = RockDateTime.Now; communication.ReviewerPersonAliasId = CurrentPersonAliasId; message = "Communication has been queued for sending."; } rockContext.SaveChanges(); if ( communication.Status == CommunicationStatus.Approved ) { var transaction = new Rock.Transactions.SendCommunicationTransaction(); transaction.CommunicationId = communication.Id; transaction.PersonAlias = CurrentPersonAlias; Rock.Transactions.RockQueue.TransactionQueue.Enqueue( transaction ); } pnlSuccess.Visible = true; pnlForm.Visible = false; nbSuccess.Text = message; } } }
private void EnqueRecurringCommuniation(int id) { RockContext rockContext = new RockContext(); CommunicationService communicationService = new CommunicationService(rockContext); RecurringCommunicationService recurringCommunicationService = new RecurringCommunicationService(rockContext); var recurringCommunication = recurringCommunicationService.Get(id); if (recurringCommunication == null) { return; } var communication = new Communication(); communication.SenderPersonAlias = recurringCommunication.CreatedByPersonAlias; communication.Name = recurringCommunication.Name; communication.CommunicationType = recurringCommunication.CommunicationType; communication.FromName = recurringCommunication.FromName; communication.FromEmail = recurringCommunication.FromEmail; communication.Subject = recurringCommunication.Subject; communication.Message = recurringCommunication.EmailBody; communication.SMSFromDefinedValueId = recurringCommunication.PhoneNumberValueId; communication.SMSMessage = recurringCommunication.SMSBody; communication.PushTitle = recurringCommunication.PushTitle; communication.PushSound = recurringCommunication.PushSound; communication.PushMessage = recurringCommunication.PushMessage; communication.Status = CommunicationStatus.Approved; DataTransformComponent transform = null; if (recurringCommunication.TransformationEntityTypeId.HasValue) { transform = DataTransformContainer.GetComponent(recurringCommunication.TransformationEntityType.Name); communication.AdditionalMergeFields = new List <string>() { "AppliesTo" }; } communicationService.Add(communication); var emailMediumEntityType = EntityTypeCache.Get(Rock.SystemGuid.EntityType.COMMUNICATION_MEDIUM_EMAIL.AsGuid()); var smsMediumEntityType = EntityTypeCache.Get(Rock.SystemGuid.EntityType.COMMUNICATION_MEDIUM_SMS.AsGuid()); var pushNotificationMediumEntityType = EntityTypeCache.Get(Rock.SystemGuid.EntityType.COMMUNICATION_MEDIUM_PUSH_NOTIFICATION.AsGuid()); List <string> errorsOut; var dataview = (IQueryable <Person>)recurringCommunication.DataView.GetQuery(null, rockContext, null, out errorsOut); if (transform != null) { var recipients = new List <CommunicationRecipient>(); var personService = new PersonService(rockContext); var paramExpression = personService.ParameterExpression; foreach (Person dvPerson in dataview) { var whereExp = Rock.Reporting.FilterExpressionExtractor.Extract <Rock.Model.Person>(personService.Queryable().Where(p => p.Id == dvPerson.Id), paramExpression, "p"); var transformExp = transform.GetExpression(personService, paramExpression, whereExp); MethodInfo getMethod = personService.GetType().GetMethod("Get", new Type[] { typeof(System.Linq.Expressions.ParameterExpression), typeof(System.Linq.Expressions.Expression) }); if (getMethod != null) { var getResult = getMethod.Invoke(personService, new object[] { paramExpression, transformExp }); var qry = getResult as IQueryable <Person>; foreach (var p in qry.ToList()) { var fieldValues = new Dictionary <string, object>(); fieldValues.Add("AppliesTo", dvPerson); recipients.Add(new CommunicationRecipient() { PersonAlias = p.PrimaryAlias, MediumEntityTypeId = p.CommunicationPreference == CommunicationType.SMS ? smsMediumEntityType.Id : emailMediumEntityType.Id, AdditionalMergeValues = fieldValues }); } } communication.Recipients = recipients; } } else { communication.Recipients = dataview .ToList() .Select(p => new CommunicationRecipient { PersonAlias = p.PrimaryAlias, MediumEntityTypeId = p.CommunicationPreference == CommunicationType.SMS ? smsMediumEntityType.Id : emailMediumEntityType.Id }) .ToList(); } Dictionary <int, CommunicationType?> communicationListGroupMemberCommunicationTypeLookup = new Dictionary <int, CommunicationType?>(); foreach (var recipient in communication.Recipients) { if (communication.CommunicationType == CommunicationType.Email) { recipient.MediumEntityTypeId = emailMediumEntityType.Id; } else if (communication.CommunicationType == CommunicationType.SMS) { recipient.MediumEntityTypeId = smsMediumEntityType.Id; } else if (communication.CommunicationType == CommunicationType.PushNotification) { recipient.MediumEntityTypeId = pushNotificationMediumEntityType.Id; } else if (communication.CommunicationType == CommunicationType.RecipientPreference) { //Do nothing we already defaulted to the recipient's preference } else { throw new Exception("Unexpected CommunicationType: " + communication.CommunicationType.ConvertToString()); } } rockContext.SaveChanges(); var transaction = new Rock.Transactions.SendCommunicationTransaction(); transaction.CommunicationId = communication.Id; transaction.PersonAlias = recurringCommunication.CreatedByPersonAlias; Rock.Transactions.RockQueue.TransactionQueue.Enqueue(transaction); }
/// <summary> /// Handles the Click event of the btnSubmit control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSubmit_Click( object sender, EventArgs e ) { if ( Page.IsValid ) { using ( new UnitOfWorkScope() ) { var service = new CommunicationService(); var communication = UpdateCommunication( service ); if ( communication != null ) { string message = string.Empty; var prevStatus = communication.Status; if ( CheckApprovalRequired( communication.Recipients.Count ) && !IsUserAuthorized( "Approve" ) ) { communication.Status = CommunicationStatus.Submitted; message = "Communication has been submitted for approval."; } else { communication.Status = CommunicationStatus.Approved; communication.ReviewedDateTime = DateTime.Now; communication.ReviewerPersonId = CurrentPersonId; message = "Communication has been queued for sending."; // TODO: Send notice to sender that communication was approved } communication.Recipients .Where( r => r.Status == CommunicationRecipientStatus.Cancelled || r.Status == CommunicationRecipientStatus.Failed ) .ToList() .ForEach( r => { r.Status = CommunicationRecipientStatus.Pending; r.StatusNote = string.Empty; } ); service.Save( communication, CurrentPersonId ); if ( communication.Status == CommunicationStatus.Approved ) { bool sendNow = false; if ( bool.TryParse( GetAttributeValue( "SendWhenApproved" ), out sendNow ) && sendNow ) { var transaction = new Rock.Transactions.SendCommunicationTransaction(); transaction.CommunicationId = communication.Id; transaction.PersonId = CurrentPersonId; Rock.Transactions.RockQueue.TransactionQueue.Enqueue( transaction ); } } ShowResult( message, communication ); } } } }