private void BindData() { RockContext rockContext = new RockContext(); dvpRefundReason.DefinedTypeId = DefinedTypeCache.Get(Rock.SystemGuid.DefinedType.FINANCIAL_TRANSACTION_REFUND_REASON.AsGuid(), rockContext).Id; if (!ddlSystemCommunication.SelectedValueAsInt().HasValue) { SystemCommunicationService systemCommunicationService = new SystemCommunicationService(rockContext); var systemCommunications = systemCommunicationService.Queryable().Where(c => c.IsActive == true).Select(e => new { Title = e.Category.Name + " - " + e.Title, e.Id }).OrderBy(e => e.Title).ToList(); systemCommunications.Insert(0, new { Title = "", Id = 0 }); ddlSystemCommunication.DataSource = systemCommunications; ddlSystemCommunication.DataValueField = "Id"; ddlSystemCommunication.DataTextField = "Title"; ddlSystemCommunication.DataBind(); } List <int> registrationTemplateIds = rtpRegistrationTemplate.ItemIds.AsIntegerList(); registrationTemplateIds.RemoveAll(i => i.Equals(0)); int itemCount = 0; decimal totalPayments = 0; if (liRegistration.Visible == true && 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); } itemCount = instances.SelectMany(i => i.Registrations).Count(); totalPayments = instances.SelectMany(i => i.Registrations).ToList().SelectMany(r => r.Payments).Sum(p => p.Transaction.TotalAmount); 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(); } } if (liTransactionCodes.Visible == true && tbTransactionCodes.Text.Length > 0) { var codes = tbTransactionCodes.Text.SplitDelimitedValues(); FinancialTransactionService financialTransactionService = new FinancialTransactionService(rockContext); var transactions = financialTransactionService.Queryable().Where(ft => codes.Contains(ft.TransactionCode)); totalPayments = transactions.SelectMany(t => t.TransactionDetails).Sum(td => td.Amount); itemCount = transactions.Count(); } lAlert.Text = itemCount + (pnlRegistration.Visible?" Registrations - ": " Transactions - ") + totalPayments.FormatAsCurrency() + " Total"; }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { var SystemCommunicationService = new SystemCommunicationService(new RockContext()); SortProperty sortProperty = gEmailTemplates.SortProperty; var systemCommunications = SystemCommunicationService.Queryable("Category"); // Filter By: Category int?categoryId = rFilter.GetUserPreference(FilterSettingName.Category).AsIntegerOrNull(); if (categoryId.HasValue) { systemCommunications = systemCommunications.Where(a => a.CategoryId.HasValue && a.CategoryId.Value == categoryId.Value); } // Filter By: Is Active var activeFilter = rFilter.GetUserPreference(FilterSettingName.Active); switch (activeFilter) { case "Active": systemCommunications = systemCommunications.Where(a => a.IsActive ?? false); break; case "Inactive": systemCommunications = systemCommunications.Where(a => !(a.IsActive ?? false)); break; } // Filter By: Supports (Email|SMS) var supports = rFilter.GetUserPreference(FilterSettingName.Supports); switch (supports) { case NotificationTypeSupportedFilterValueSpecifier.SMS: systemCommunications = systemCommunications.Where(a => a.SMSMessage != null && a.SMSMessage.Trim() != ""); break; case NotificationTypeSupportedFilterValueSpecifier.Push: systemCommunications = systemCommunications.Where(a => a.PushMessage != null && a.PushMessage.Trim() != ""); break; } // Apply grid sort order. if (sortProperty != null) { gEmailTemplates.DataSource = systemCommunications.Sort(sortProperty).ToList(); } else { gEmailTemplates.DataSource = systemCommunications.OrderBy(a => a.Category.Name).ThenBy(a => a.Title).ToList(); } gEmailTemplates.EntityTypeId = EntityTypeCache.Get <Rock.Model.SystemCommunication>().Id; gEmailTemplates.DataBind(); }
/// <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(); var systemEmailService = new SystemCommunicationService(rockContext); foreach (var 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; } }