Ejemplo n.º 1
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            var          systemEmailService = new SystemEmailService(new RockContext());
            SortProperty sortProperty       = gEmailTemplates.SortProperty;

            var systemEmails = systemEmailService.Queryable("Category");

            int?categoryId = rFilter.GetUserPreference("Category").AsIntegerOrNull();

            if (categoryId.HasValue)
            {
                systemEmails = systemEmails.Where(a => a.CategoryId.HasValue && a.CategoryId.Value == categoryId.Value);
            }

            if (sortProperty != null)
            {
                gEmailTemplates.DataSource = systemEmails.Sort(sortProperty).ToList();
            }
            else
            {
                gEmailTemplates.DataSource = systemEmails.OrderBy(a => a.Category.Name).ThenBy(a => a.Title).ToList();
            }

            gEmailTemplates.EntityTypeId = EntityTypeCache.Get <Rock.Model.SystemEmail>().Id;
            gEmailTemplates.DataBind();
        }
        private void BindData()
        {
            RockContext rockContext = new RockContext();

            dvpRefundReason.DefinedTypeId = DefinedTypeCache.Get(Rock.SystemGuid.DefinedType.FINANCIAL_TRANSACTION_REFUND_REASON.AsGuid(), rockContext).Id;

            if (!ddlSystemEmail.SelectedValueAsInt().HasValue)
            {
                SystemEmailService systemEmailService = new SystemEmailService(rockContext);
                var systemEmails = systemEmailService.Queryable().Select(e => new { Title = e.Category.Name + " - " + e.Title, e.Id }).OrderBy(e => e.Title).ToList();
                systemEmails.Insert(0, new { Title = "", Id = 0 });
                ddlSystemEmail.DataSource     = systemEmails;
                ddlSystemEmail.DataValueField = "Id";
                ddlSystemEmail.DataTextField  = "Title";
                ddlSystemEmail.DataBind();
            }

            List <int> registrationTemplateIds = rtpRegistrationTemplate.ItemIds.AsIntegerList();

            registrationTemplateIds.RemoveAll(i => i.Equals(0));

            if (registrationTemplateIds.Count > 0)
            {
                RegistrationTemplateService registrationTemplateService = new RegistrationTemplateService(rockContext);
                var templates = registrationTemplateService.GetByIds(rtpRegistrationTemplate.ItemIds.AsIntegerList());
                var instances = templates.SelectMany(t => t.Instances);
                if (ddlRegistrationInstance.SelectedValueAsId().HasValue&& ddlRegistrationInstance.SelectedValueAsId() > 0)
                {
                    var instanceId = ddlRegistrationInstance.SelectedValueAsId();
                    instances = instances.Where(i => i.Id == instanceId);
                }
                int registrationCount = instances.SelectMany(i => i.Registrations).Count();
                var totalPayments     = instances.SelectMany(i => i.Registrations).ToList().SelectMany(r => r.Payments).Sum(p => p.Transaction.TotalAmount);
                lAlert.Text = registrationCount + " Registrations - " + totalPayments.FormatAsCurrency() + " Total";

                if (!ddlRegistrationInstance.SelectedValueAsInt().HasValue)
                {
                    var instanceList = templates.SelectMany(t => t.Instances).OrderBy(i => i.Name).Select(i => new { i.Id, i.Name }).ToList();
                    instanceList.Insert(0, new { Id = 0, Name = "" });
                    ddlRegistrationInstance.DataSource     = instanceList;
                    ddlRegistrationInstance.DataValueField = "Id";
                    ddlRegistrationInstance.DataTextField  = "Name";
                    ddlRegistrationInstance.DataBind();
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Binds the filter.
        /// </summary>
        private void BindFilter()
        {
            ddlCategoryFilter.Items.Clear();
            ddlCategoryFilter.Items.Add(new ListItem(All.Text, All.Id.ToString()));

            SystemEmailService emailTemplateService = new SystemEmailService(new RockContext());
            var items = emailTemplateService.Queryable().
                        Where(a => a.Category.Trim() != "" && a.Category != null).
                        OrderBy(a => a.Category).
                        Select(a => a.Category.Trim()).
                        Distinct().ToList();

            foreach (var item in items)
            {
                ListItem li = new ListItem(item);
                li.Selected = (!Page.IsPostBack && rFilter.GetUserPreference("Category") == item);
                ddlCategoryFilter.Items.Add(li);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            SystemEmailService emailTemplateService = new SystemEmailService(new RockContext());
            SortProperty       sortProperty         = gEmailTemplates.SortProperty;

            var emailTemplates = emailTemplateService.Queryable();

            if (ddlCategoryFilter.SelectedValue != All.Id.ToString())
            {
                emailTemplates = emailTemplates.Where(a => a.Category.Trim() == ddlCategoryFilter.SelectedValue);
            }

            if (sortProperty != null)
            {
                gEmailTemplates.DataSource = emailTemplates.Sort(sortProperty).ToList();
            }
            else
            {
                gEmailTemplates.DataSource = emailTemplates.OrderBy(a => a.Category).ThenBy(a => a.Title).ToList();
            }

            gEmailTemplates.DataBind();
        }
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            SystemEmailService emailTemplateService = new SystemEmailService( new RockContext() );
            SortProperty sortProperty = gEmailTemplates.SortProperty;

            var emailTemplates = emailTemplateService.Queryable();

            if ( ddlCategoryFilter.SelectedValue != All.Id.ToString() )
            {
                emailTemplates = emailTemplates.Where( a => a.Category.Trim() == ddlCategoryFilter.SelectedValue );
            }

            if ( sortProperty != null )
            {
                gEmailTemplates.DataSource = emailTemplates.Sort( sortProperty ).ToList();
            }
            else
            {
                gEmailTemplates.DataSource = emailTemplates.OrderBy( a => a.Category ).ThenBy( a => a.Title ).ToList();
            }

            gEmailTemplates.DataBind();
        }
        /// <summary>
        /// Binds the filter.
        /// </summary>
        private void BindFilter()
        {
            ddlCategoryFilter.Items.Clear();
            ddlCategoryFilter.Items.Add( new ListItem(All.Text, All.Id.ToString()) );

            SystemEmailService emailTemplateService = new SystemEmailService( new RockContext() );
            var items = emailTemplateService.Queryable().
                Where( a => a.Category.Trim() != "" && a.Category != null ).
                OrderBy( a => a.Category ).
                Select( a => a.Category.Trim() ).
                Distinct().ToList();

            foreach ( var item in items )
            {
                ListItem li = new ListItem( item );
                li.Selected = ( !Page.IsPostBack && rFilter.GetUserPreference( "Category" ) == item );
                ddlCategoryFilter.Items.Add( li );
            }
        }
        /// <summary>
        /// Checks SystemEmail model for legacy lava and outputs SQL to correct it.
        /// Fields evaluated: Title From To Cc Bcc Subject Body
        /// </summary>
        public void CheckSystemEmail()
        {
            try
            {
                RockContext        rockContext        = new RockContext();
                SystemEmailService systemEmailService = new SystemEmailService(rockContext);

                foreach (SystemEmail systemEmail in systemEmailService.Queryable().ToList())
                {
                    // don't change if modified
                    if (systemEmail.ModifiedDateTime != null)
                    {
                        continue;
                    }

                    bool isUpdated = false;

                    systemEmail.Title = ReplaceUnformatted(systemEmail.Title, ref isUpdated);
                    systemEmail.Title = ReplaceUrl(systemEmail.Title, ref isUpdated);
                    systemEmail.Title = ReplaceGlobal(systemEmail.Title, ref isUpdated);
                    systemEmail.Title = ReplaceDotNotation(systemEmail.Title, ref isUpdated);

                    systemEmail.From = ReplaceUnformatted(systemEmail.From, ref isUpdated);
                    systemEmail.From = ReplaceUrl(systemEmail.From, ref isUpdated);
                    systemEmail.From = ReplaceGlobal(systemEmail.From, ref isUpdated);
                    systemEmail.From = ReplaceDotNotation(systemEmail.From, ref isUpdated);

                    systemEmail.To = ReplaceUnformatted(systemEmail.To, ref isUpdated);
                    systemEmail.To = ReplaceUrl(systemEmail.To, ref isUpdated);
                    systemEmail.To = ReplaceGlobal(systemEmail.To, ref isUpdated);
                    systemEmail.To = ReplaceDotNotation(systemEmail.To, ref isUpdated);

                    systemEmail.Cc = ReplaceUnformatted(systemEmail.Cc, ref isUpdated);
                    systemEmail.Cc = ReplaceUrl(systemEmail.Cc, ref isUpdated);
                    systemEmail.Cc = ReplaceGlobal(systemEmail.Cc, ref isUpdated);
                    systemEmail.Cc = ReplaceDotNotation(systemEmail.Cc, ref isUpdated);

                    systemEmail.Bcc = ReplaceUnformatted(systemEmail.Bcc, ref isUpdated);
                    systemEmail.Bcc = ReplaceUrl(systemEmail.Bcc, ref isUpdated);
                    systemEmail.Bcc = ReplaceGlobal(systemEmail.Bcc, ref isUpdated);
                    systemEmail.Bcc = ReplaceDotNotation(systemEmail.Bcc, ref isUpdated);

                    systemEmail.Subject = ReplaceUnformatted(systemEmail.Subject, ref isUpdated);
                    systemEmail.Subject = ReplaceUrl(systemEmail.Subject, ref isUpdated);
                    systemEmail.Subject = ReplaceGlobal(systemEmail.Subject, ref isUpdated);
                    systemEmail.Subject = ReplaceDotNotation(systemEmail.Subject, ref isUpdated);

                    systemEmail.Body = ReplaceUnformatted(systemEmail.Body, ref isUpdated);
                    systemEmail.Body = ReplaceUrl(systemEmail.Body, ref isUpdated);
                    systemEmail.Body = ReplaceGlobal(systemEmail.Body, ref isUpdated);
                    systemEmail.Body = ReplaceDotNotation(systemEmail.Body, ref isUpdated);

                    if (isUpdated)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.AppendLine("UPDATE[SystemEmail]");
                        if (systemEmail.Title != null)
                        {
                            sb.AppendLine($"SET [Title] = '{systemEmail.Title.Replace( "'", "''" )}', ");
                        }

                        if (systemEmail.From != null)
                        {
                            sb.AppendLine($"[From] = '{systemEmail.From.Replace( "'", "''" )}', ");
                        }

                        if (systemEmail.To != null)
                        {
                            sb.AppendLine($"[To] = '{systemEmail.To.Replace( "'", "''" )}', ");
                        }

                        if (systemEmail.Cc != null)
                        {
                            sb.AppendLine($"[Cc] = '{systemEmail.Cc.Replace( "'", "''" )}', ");
                        }

                        if (systemEmail.Bcc != null)
                        {
                            sb.AppendLine($"[Bcc] = '{systemEmail.Bcc.Replace( "'", "''" )}', ");
                        }

                        if (systemEmail.Subject != null)
                        {
                            sb.AppendLine($"[Subject] = '{systemEmail.Subject.Replace( "'", "''" )}' , ");
                        }

                        if (systemEmail.Body != null)
                        {
                            sb.AppendLine($"[Body] = '{systemEmail.Body.Replace( "'", "''" )}' ");
                        }

                        sb.AppendLine($"WHERE [Guid] = '{systemEmail.Guid}';");

                        _sqlUpdateScripts.Add(sb.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionLogService.LogException(ex, null);
                throw;
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            var systemEmailService = new SystemEmailService( new RockContext() );
            SortProperty sortProperty = gEmailTemplates.SortProperty;

            var systemEmails = systemEmailService.Queryable( "Category" );

            int? categoryId = rFilter.GetUserPreference( "Category" ).AsIntegerOrNull();
            if ( categoryId.HasValue )
            {
                systemEmails = systemEmails.Where( a => a.CategoryId.HasValue && a.CategoryId.Value == categoryId.Value  );
            }

            if ( sortProperty != null )
            {
                gEmailTemplates.DataSource = systemEmails.Sort( sortProperty ).ToList();
            }
            else
            {
                gEmailTemplates.DataSource = systemEmails.OrderBy( a => a.Category.Name ).ThenBy( a => a.Title ).ToList();
            }

            gEmailTemplates.EntityTypeId = EntityTypeCache.Read<Rock.Model.SystemEmail>().Id;
            gEmailTemplates.DataBind();
        }