Пример #1
0
        /// <summary>
        /// Loads the drop downs.
        /// </summary>
        private void LoadDropDowns(DataView dataView)
        {
            var entityTypeService = new EntityTypeService();

            ddlTransform.Items.Clear();
            if (dataView.EntityTypeId.HasValue)
            {
                var filteredEntityType = EntityTypeCache.Read(dataView.EntityTypeId.Value);
                foreach (var component in DataTransformContainer.GetComponentsByTransformedEntityName(filteredEntityType.Name).OrderBy(c => c.Title))
                {
                    var      transformEntityType = EntityTypeCache.Read(component.TypeName);
                    ListItem li = new ListItem(component.Title, transformEntityType.Id.ToString());
                    ddlTransform.Items.Add(li);
                }
            }
            ddlTransform.Items.Insert(0, new ListItem(string.Empty, string.Empty));

            // Get all entities
            ddlEntityType.DataSource = entityTypeService.GetEntities()
                                       .OrderBy(e => e.FriendlyName)
                                       .ToList();
            ddlEntityType.DataBind();

            ddlEntityType.Items.Insert(0, new ListItem(string.Empty, string.Empty));
        }
        private void BindTransformationTypes()
        {
            ddlTransformTypes.Items.Clear();

            foreach (var component in DataTransformContainer.GetComponentsByTransformedEntityName(PersonEntityType.Name).OrderBy(c => c.Title))
            {
                if (component.IsAuthorized(Authorization.VIEW, CurrentPerson))
                {
                    var      transformEntityType = EntityTypeCache.Get(component.TypeName);
                    ListItem li = new ListItem(component.Title, transformEntityType.Id.ToString());
                    ddlTransformTypes.Items.Add(li);
                }
            }

            ddlTransformTypes.Items.Insert(0, new ListItem("", ""));
        }
Пример #3
0
        public void BindDataTransformations()
        {
            ddlTransform.Items.Clear();
            int?entityTypeId = ddlEntityType.SelectedValueAsInt();

            if (entityTypeId.HasValue)
            {
                var filteredEntityType = EntityTypeCache.Read(entityTypeId.Value);
                foreach (var component in DataTransformContainer.GetComponentsByTransformedEntityName(filteredEntityType.Name).OrderBy(c => c.Title))
                {
                    var      transformEntityType = EntityTypeCache.Read(component.TypeName);
                    ListItem li = new ListItem(component.Title, transformEntityType.Id.ToString());
                    ddlTransform.Items.Add(li);
                }
            }
            ddlTransform.Items.Insert(0, new ListItem(string.Empty, string.Empty));
        }
Пример #4
0
        /// <summary>
        /// Binds the data transformations.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        public void BindDataTransformations(RockContext rockContext)
        {
            ddlTransform.Items.Clear();
            int?entityTypeId = etpEntityType.SelectedEntityTypeId;

            if (entityTypeId.HasValue)
            {
                var filteredEntityType = EntityTypeCache.Get(entityTypeId.Value);
                foreach (var component in DataTransformContainer.GetComponentsByTransformedEntityName(filteredEntityType.Name).OrderBy(c => c.Title))
                {
                    if (component.IsAuthorized(Authorization.VIEW, this.CurrentPerson))
                    {
                        var      transformEntityType = EntityTypeCache.Get(component.TypeName);
                        ListItem li = new ListItem(component.Title, transformEntityType.Id.ToString());
                        ddlTransform.Items.Add(li);
                    }
                }
            }

            ddlTransform.Items.Insert(0, new ListItem(string.Empty, string.Empty));
        }
Пример #5
0
        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);
        }
        private void DisplayDetails()
        {
            var values = GetAttributeValue(AttributeKey.EnabledCommunicationTypes).SplitDelimitedValues();
            var communicationDictionary = Enum
                                          .GetValues(typeof(CommunicationType))
                                          .Cast <CommunicationType>()
                                          .ToDictionary(t => (( int )t).ToString(), t => t.ToString())
                                          .Where(d => values.Contains(d.Key))
                                          .ToDictionary(k => k.Key, v => v.Value);

            rblCommunicationType.DataSource = communicationDictionary;
            rblCommunicationType.DataBind();

            dvpPhoneNumber.DefinedTypeId = DefinedTypeCache.Get(Rock.SystemGuid.DefinedType.COMMUNICATION_SMS_FROM.AsGuid()).Id;

            BindTransformationTypes();

            RecurringCommunication recurringCommunication = GetRecurringCommunication();

            tbName.Text = recurringCommunication.Name;
            dvpDataview.SetValue(recurringCommunication.DataView);
            if (recurringCommunication.Schedule != null)
            {
                sbScheduleBuilder.iCalendarContent = recurringCommunication.Schedule.iCalendarContent;
                DisplayScheduleDetails();
            }
            rblCommunicationType.SetValue(recurringCommunication.CommunicationType.ConvertToInt());

            if (recurringCommunication.TransformationEntityTypeId.HasValue)
            {
                if (ddlTransformTypes.Items.FindByValue(recurringCommunication.TransformationEntityTypeId.Value.ToString()) != null)
                {
                    ddlTransformTypes.SelectedValue = recurringCommunication.TransformationEntityTypeId.Value.ToString();
                }
                else
                {
                    var transformComponent = DataTransformContainer.GetComponentsByTransformedEntityName(PersonEntityType.Name)
                                             .SingleOrDefault(c => c.Id == recurringCommunication.TransformationEntityTypeId.Value);

                    if (transformComponent != null)
                    {
                        var li = new ListItem(transformComponent.Title, transformComponent.Id.ToString());
                        ddlTransformTypes.Items.Insert(1, li);
                        ddlTransformTypes.SelectedIndex = 1;
                    }
                }
            }

            UpdateCommunicationTypeUI(recurringCommunication.CommunicationType);

            tbFromName.Text  = recurringCommunication.FromName;
            tbFromEmail.Text = recurringCommunication.FromEmail;
            tbSubject.Text   = recurringCommunication.Subject;
            ceEmailBody.Text = recurringCommunication.EmailBody;

            dvpPhoneNumber.SetValue(recurringCommunication.PhoneNumberValueId);
            tbSMSBody.Text = recurringCommunication.SMSBody;

            tbPushNotificationTitle.Text = recurringCommunication.PushTitle;
            tbPushNotificationBody.Text  = recurringCommunication.PushMessage;
            cbPlaySound.Checked          = recurringCommunication.PushSound.IsNotNullOrWhiteSpace();
        }