Beispiel #1
0
 /// <summary>
 /// Copies the properties from another CommunicationTemplate object to this CommunicationTemplate object
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="source">The source.</param>
 public static void CopyPropertiesFrom(this CommunicationTemplate target, CommunicationTemplate source)
 {
     target.Id                      = source.Id;
     target.BCCEmails               = source.BCCEmails;
     target.CategoryId              = source.CategoryId;
     target.CCEmails                = source.CCEmails;
     target.CssInliningEnabled      = source.CssInliningEnabled;
     target.Description             = source.Description;
     target.ForeignGuid             = source.ForeignGuid;
     target.ForeignKey              = source.ForeignKey;
     target.FromEmail               = source.FromEmail;
     target.FromName                = source.FromName;
     target.ImageFileId             = source.ImageFileId;
     target.IsActive                = source.IsActive;
     target.IsSystem                = source.IsSystem;
     target.LavaFieldsJson          = source.LavaFieldsJson;
     target.LogoBinaryFileId        = source.LogoBinaryFileId;
     target.Message                 = source.Message;
     target.MessageMetaData         = source.MessageMetaData;
     target.Name                    = source.Name;
     target.PushMessage             = source.PushMessage;
     target.PushSound               = source.PushSound;
     target.PushTitle               = source.PushTitle;
     target.ReplyToEmail            = source.ReplyToEmail;
     target.SenderPersonAliasId     = source.SenderPersonAliasId;
     target.SMSFromDefinedValueId   = source.SMSFromDefinedValueId;
     target.SMSMessage              = source.SMSMessage;
     target.Subject                 = source.Subject;
     target.CreatedDateTime         = source.CreatedDateTime;
     target.ModifiedDateTime        = source.ModifiedDateTime;
     target.CreatedByPersonAliasId  = source.CreatedByPersonAliasId;
     target.ModifiedByPersonAliasId = source.ModifiedByPersonAliasId;
     target.Guid                    = source.Guid;
     target.ForeignId               = source.ForeignId;
 }
        /// <summary>
        /// Handles the Click event of the btnSave 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 btnSave_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                var rockContext = new RockContext();

                var service = new CommunicationTemplateService(rockContext);

                Rock.Model.CommunicationTemplate template = null;
                if (CommunicationTemplateId.HasValue)
                {
                    template = service.Get(CommunicationTemplateId.Value);
                }

                bool newTemplate = false;
                if (template == null)
                {
                    newTemplate = true;
                    template    = new Rock.Model.CommunicationTemplate();
                    service.Add(template);
                }

                template.Name               = tbName.Text;
                template.Description        = tbDescription.Text;
                template.MediumEntityTypeId = MediumEntityTypeId;

                template.MediumData.Clear();
                GetMediumData();
                foreach (var keyVal in MediumData)
                {
                    if (!string.IsNullOrEmpty(keyVal.Value))
                    {
                        template.MediumData.Add(keyVal.Key, keyVal.Value);
                    }
                }

                if (template.MediumData.ContainsKey("Subject"))
                {
                    template.Subject = template.MediumData["Subject"];
                    template.MediumData.Remove("Subject");
                }
                else
                {
                    template.Subject = string.Empty;
                }

                if (template != null)
                {
                    rockContext.SaveChanges();
                    NavigateToParentPage();
                }

                if (newTemplate && !_canEdit)
                {
                    template.MakePrivate(Authorization.VIEW, CurrentPerson);
                    template.MakePrivate(Authorization.EDIT, CurrentPerson);
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// Clones this CommunicationTemplate object to a new CommunicationTemplate object
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="deepCopy">if set to <c>true</c> a deep copy is made. If false, only the basic entity properties are copied.</param>
 /// <returns></returns>
 public static CommunicationTemplate Clone(this CommunicationTemplate source, bool deepCopy)
 {
     if (deepCopy)
     {
         return(source.Clone() as CommunicationTemplate);
     }
     else
     {
         var target = new CommunicationTemplate();
         target.CopyPropertiesFrom(source);
         return(target);
     }
 }
 /// <summary>
 /// Copies the properties from another CommunicationTemplate object to this CommunicationTemplate object
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="source">The source.</param>
 public static void CopyPropertiesFrom(this CommunicationTemplate target, CommunicationTemplate source)
 {
     target.Id                      = source.Id;
     target.Description             = source.Description;
     target.MediumDataJson          = source.MediumDataJson;
     target.MediumEntityTypeId      = source.MediumEntityTypeId;
     target.Name                    = source.Name;
     target.SenderPersonAliasId     = source.SenderPersonAliasId;
     target.Subject                 = source.Subject;
     target.CreatedDateTime         = source.CreatedDateTime;
     target.ModifiedDateTime        = source.ModifiedDateTime;
     target.CreatedByPersonAliasId  = source.CreatedByPersonAliasId;
     target.ModifiedByPersonAliasId = source.ModifiedByPersonAliasId;
     target.Guid                    = source.Guid;
     target.ForeignId               = source.ForeignId;
 }
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="itemKey">The item key.</param>
        /// <param name="itemKeyValue">The item key value.</param>
        private void ShowDetail(string itemKey, int itemKeyValue)
        {
            if (!itemKey.Equals("TemplateId"))
            {
                return;
            }

            Rock.Model.CommunicationTemplate template = null;

            if (!itemKeyValue.Equals(0))
            {
                template = new CommunicationTemplateService(new RockContext())
                           .Queryable()
                           .Where(c => c.Id == itemKeyValue)
                           .FirstOrDefault();
                if (template != null)
                {
                    lTitle.Text = template.Name.FormatAsHtmlTitle();
                }
            }
            else
            {
                template           = new Rock.Model.CommunicationTemplate();
                RockPage.PageTitle = "New Communication Template";
                lTitle.Text        = "New Communication Template".FormatAsHtmlTitle();
            }

            if (template == null)
            {
                return;
            }

            CommunicationTemplateId = template.Id;

            tbName.Text        = template.Name;
            tbDescription.Text = template.Description;

            ChannelEntityTypeId = template.ChannelEntityTypeId;
            BindChannels();

            ChannelData = template.ChannelData;
            ChannelData.Add("Subject", template.Subject);

            ChannelControl control = LoadChannelControl(true);
        }
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="templateId">The template identifier.</param>
        private void ShowDetail(int templateId)
        {
            Rock.Model.CommunicationTemplate template = null;

            if (!templateId.Equals(0))
            {
                template = new CommunicationTemplateService(new RockContext())
                           .Queryable()
                           .Where(c => c.Id == templateId)
                           .FirstOrDefault();
                if (template != null)
                {
                    lTitle.Text = template.Name.FormatAsHtmlTitle();
                }
            }

            if (template == null)
            {
                template           = new Rock.Model.CommunicationTemplate();
                RockPage.PageTitle = "New Communication Template";
                lTitle.Text        = "New Communication Template".FormatAsHtmlTitle();
            }

            CommunicationTemplateId = template.Id;

            tbName.Text        = template.Name;
            tbDescription.Text = template.Description;

            MediumEntityTypeId = template.MediumEntityTypeId;
            BindMediums();

            MediumData = template.MediumData;
            MediumData.Add("Subject", template.Subject);

            MediumControl control = LoadMediumControl(true);
        }
Beispiel #7
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="templateId">The template identifier.</param>
        private void ShowDetail( int templateId )
        {
            Rock.Model.CommunicationTemplate template = null;

            if ( !templateId.Equals( 0 ) )
            {
                template = new CommunicationTemplateService( new RockContext() )
                    .Queryable()
                    .Where( c => c.Id == templateId )
                    .FirstOrDefault();
                if ( template != null )
                {
                    lTitle.Text = template.Name.FormatAsHtmlTitle();
                }
            }

            if (template == null)
            {
                template = new Rock.Model.CommunicationTemplate();
                RockPage.PageTitle = "New Communication Template";
                lTitle.Text = "New Communication Template".FormatAsHtmlTitle();
            }

            CommunicationTemplateId = template.Id;

            tbName.Text = template.Name;
            tbDescription.Text = template.Description;

            ChannelEntityTypeId = template.ChannelEntityTypeId;
            BindChannels();

            ChannelData = template.ChannelData;
            ChannelData.Add( "Subject", template.Subject );

            ChannelControl control = LoadChannelControl( true );
        }
Beispiel #8
0
        /// <summary>
        /// Handles the Click event of the btnSave 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 btnSave_Click( object sender, EventArgs e )
        {
            if ( Page.IsValid )
            {
                var rockContext = new RockContext();

                var service = new CommunicationTemplateService( rockContext );

                Rock.Model.CommunicationTemplate template = null;
                if ( CommunicationTemplateId.HasValue )
                {
                    template = service.Get( CommunicationTemplateId.Value );
                }

                bool newTemplate = false;
                if ( template == null )
                {
                    newTemplate = true;
                    template = new Rock.Model.CommunicationTemplate();
                    service.Add( template );
                }

                template.Name = tbName.Text;
                template.Description = tbDescription.Text;
                template.ChannelEntityTypeId = ChannelEntityTypeId;

                template.ChannelData.Clear();
                GetChannelData();
                foreach(var keyVal in ChannelData)
                {
                    if (!string.IsNullOrEmpty(keyVal.Value))
                    {
                        template.ChannelData.Add(keyVal.Key, keyVal.Value);
                    }
                }

                if ( template.ChannelData.ContainsKey( "Subject" ) )
                {
                    template.Subject = template.ChannelData["Subject"];
                    template.ChannelData.Remove( "Subject" );
                }

                if ( template != null )
                {
                    rockContext.SaveChanges();
                    NavigateToParentPage();
                }

                if ( newTemplate && !_canEdit )
                {
                    template.MakePrivate( Authorization.VIEW, CurrentPerson );
                    template.MakePrivate( Authorization.EDIT, CurrentPerson );
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// Handles the Click event of the btnSave 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 btnSave_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                var rockContext = new RockContext();

                var communicationTemplateService           = new CommunicationTemplateService(rockContext);
                var communicationTemplateAttachmentService = new CommunicationTemplateAttachmentService(rockContext);

                CommunicationTemplate communicationTemplate = null;
                int?communicationTemplateId = hfCommunicationTemplateId.Value.AsIntegerOrNull();
                if (communicationTemplateId.HasValue)
                {
                    communicationTemplate = communicationTemplateService.Get(communicationTemplateId.Value);
                }

                bool newTemplate = false;
                if (communicationTemplate == null)
                {
                    newTemplate           = true;
                    communicationTemplate = new Rock.Model.CommunicationTemplate();
                    communicationTemplateService.Add(communicationTemplate);
                }

                communicationTemplate.Name             = tbName.Text;
                communicationTemplate.IsActive         = cbIsActive.Checked;
                communicationTemplate.Description      = tbDescription.Text;
                communicationTemplate.ImageFileId      = imgTemplatePreview.BinaryFileId;
                communicationTemplate.LogoBinaryFileId = imgTemplateLogo.BinaryFileId;

                communicationTemplate.FromName           = tbFromName.Text;
                communicationTemplate.FromEmail          = tbFromAddress.Text;
                communicationTemplate.ReplyToEmail       = tbReplyToAddress.Text;
                communicationTemplate.CCEmails           = tbCCList.Text;
                communicationTemplate.BCCEmails          = tbBCCList.Text;
                communicationTemplate.LavaFields         = kvlMergeFields.Value.AsDictionaryOrNull();
                communicationTemplate.CssInliningEnabled = cbCssInliningEnabled.Checked;

                var binaryFileIds = hfAttachedBinaryFileIds.Value.SplitDelimitedValues().AsIntegerList();

                // delete any attachments that are no longer included
                foreach (var attachment in communicationTemplate.Attachments.Where(a => !binaryFileIds.Contains(a.BinaryFileId)).ToList())
                {
                    communicationTemplate.Attachments.Remove(attachment);
                    communicationTemplateAttachmentService.Delete(attachment);
                }

                // add any new attachments that were added
                foreach (var attachmentBinaryFileId in binaryFileIds.Where(a => !communicationTemplate.Attachments.Any(x => x.BinaryFileId == a)))
                {
                    communicationTemplate.Attachments.Add(new CommunicationTemplateAttachment {
                        BinaryFileId = attachmentBinaryFileId
                    });
                }

                communicationTemplate.Subject = tbEmailSubject.Text;
                communicationTemplate.Message = ceEmailTemplate.Text;

                communicationTemplate.SMSFromDefinedValueId = ddlSMSFrom.SelectedValue.AsIntegerOrNull();
                communicationTemplate.SMSMessage            = tbSMSTextMessage.Text;

                communicationTemplate.CategoryId = cpCategory.SelectedValueAsInt();

                if (communicationTemplate != null)
                {
                    rockContext.SaveChanges();
                    NavigateToParentPage();
                }

                if (newTemplate && !IsUserAuthorized(Authorization.EDIT))
                {
                    communicationTemplate.MakePrivate(Authorization.VIEW, CurrentPerson);
                    communicationTemplate.MakePrivate(Authorization.EDIT, CurrentPerson);
                }
            }
        }