public void CheckCommunicationTemplate()
        {
            #pragma warning disable 0618
            RockContext rockContext = new RockContext();
            CommunicationTemplateService communicationTemplateService = new CommunicationTemplateService(rockContext);

            foreach (CommunicationTemplate communicationTemplate in communicationTemplateService.Queryable().ToList())
            {
                // don't change if modified
                if (communicationTemplate.ModifiedDateTime != null)
                {
                    continue;
                }

                bool isUpdated = false;

                communicationTemplate.MediumDataJson = ReplaceUnformatted(communicationTemplate.MediumDataJson, ref isUpdated);
                communicationTemplate.MediumDataJson = ReplaceUrl(communicationTemplate.MediumDataJson, ref isUpdated);
                communicationTemplate.MediumDataJson = ReplaceGlobal(communicationTemplate.MediumDataJson, ref isUpdated);
                communicationTemplate.MediumDataJson = ReplaceDotNotation(communicationTemplate.MediumDataJson, ref isUpdated);

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

                if (isUpdated)
                {
                    string sql = $"UPDATE [CommunicationTemplate] SET [MediumDataJson] = '{communicationTemplate.MediumDataJson.Replace( "'", "''" )}', [Subject] = '{communicationTemplate.Subject.Replace( "'", "''" )}' WHERE [Guid] = '{communicationTemplate.Guid}';";
                    _sqlUpdateScripts.Add(sql);
                }
            }

            #pragma warning restore 0618
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles the Copy event of the gCommunicationTemplates control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param>
        protected void gCommunicationTemplates_Copy(object sender, RowEventArgs e)
        {
            var rockContext = new RockContext();
            var service     = new CommunicationTemplateService(rockContext);
            var template    = service.Get(e.RowKeyId);

            if (template != null)
            {
                var templateCopy = template.Clone(false);
                templateCopy.Id = 0;
                int copyNumber = 0;
                var copyName   = "Copy of " + template.Name;
                while (service.Queryable().Any(a => a.Name == copyName))
                {
                    copyNumber++;
                    copyName = string.Format("Copy({0}) of {1}", copyNumber, template.Name);
                }

                templateCopy.Name     = copyName.Truncate(100);
                templateCopy.IsSystem = false;
                templateCopy.Guid     = Guid.NewGuid();
                service.Add(templateCopy);
                rockContext.SaveChanges();
            }

            BindGrid();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Handles the Copy event of the gCommunicationTemplates control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param>
        protected void gCommunicationTemplates_Copy(object sender, RowEventArgs e)
        {
            var rockContext = new RockContext();
            var service     = new CommunicationTemplateService(rockContext);
            var template    = service.Get(e.RowKeyId);

            if (template != null)
            {
                if (!template.IsAuthorized(Authorization.EDIT, this.CurrentPerson))
                {
                    maGridWarning.Show("You are not authorized to copy this template", ModalAlertType.Information);
                    return;
                }

                var templateCopy = template.Clone(false);
                templateCopy.Id = 0;
                int copyNumber = 0;
                var copyName   = "Copy of " + template.Name;
                while (service.Queryable().Where(a => a.Name == copyName).Any())
                {
                    copyNumber++;
                    copyName = string.Format("Copy({0}) of {1}", copyNumber, template.Name);
                }

                template.Name     = copyName.Truncate(100);
                templateCopy.Guid = Guid.NewGuid();
                service.Add(templateCopy);
                rockContext.SaveChanges();
            }

            BindGrid();
        }