public override IDisplayResult Edit(ContentTypePartDefinition contentTypePartDefinition, IUpdateModel updater) { if (!String.Equals(nameof(EmailTemplatePart), contentTypePartDefinition.PartDefinition.Name)) { return(null); } return(Initialize <EmailTemplatePartSettingsViewModel>("EmailTemplatePartSettings_Edit", async model => { var settings = contentTypePartDefinition.GetSettings <EmailTemplatePartSettings>(); var templateDocuments = await _templatesManager.GetEmailTemplatesDocumentAsync(); if (settings.SelectedEmailTemplates != null) { model.SelectedEmailTemplates = settings.SelectedEmailTemplates; } model.EmailTemplates = new List <SelectListItem>(); foreach (var templateDocument in templateDocuments.Templates) { model.EmailTemplates.Add(new SelectListItem { Value = templateDocument.Key, Text = templateDocument.Value.Name }); } model.EmailTemplatePartSettings = settings; }).Location("Content"));; }
public async Task <int> UpdateFrom1Async() { var templateDocuments = _templatesManager.GetEmailTemplatesDocumentAsync().Result; // if any EmailTemplates has a value on the name property it was already updated if (templateDocuments.Templates.Any(x => x.Value.Name != null)) { return(2); } foreach (var templateDocument in templateDocuments.Templates) { // Assign all value to a new template, generate an Id and delete the old one. var template = new EmailTemplate { Name = templateDocument.Key, Description = templateDocument.Value.Description, AuthorExpression = templateDocument.Value.AuthorExpression, SenderExpression = templateDocument.Value.SenderExpression, ReplyToExpression = templateDocument.Value.ReplyToExpression, RecipientsExpression = templateDocument.Value.RecipientsExpression, SubjectExpression = templateDocument.Value.SubjectExpression, Body = templateDocument.Value.Body, IsBodyHtml = templateDocument.Value.IsBodyHtml, }; await _templatesManager.UpdateTemplateAsync(IdGenerator.GenerateId(), template); await _templatesManager.RemoveTemplateAsync(templateDocument.Key); } return(2); }
public override IDisplayResult Display(EmailTemplatePart emailTemplatePart, BuildPartDisplayContext context) { var settings = context.TypePartDefinition.GetSettings <EmailTemplatePartSettings>(); if (settings.SelectedEmailTemplates != null) { var templateDocuments = _templatesManager.GetEmailTemplatesDocumentAsync().Result; var emailTemplates = new List <SelectListItem>(); foreach (var templateDocument in templateDocuments.Templates) { emailTemplates.Add(new SelectListItem { Value = templateDocument.Key, Text = templateDocument.Value.Name }); } // This injects a button on the SummaryAdmin view for any ContentItem with an Email Template return(Initialize <EmailTemplatePartViewModel>("EmailTemplatePart", m => { m.SelectedEmailTemplates = emailTemplates.Where(x => settings.SelectedEmailTemplates.Contains(x.Value)).ToList(); m.ContentItemId = emailTemplatePart.ContentItem.ContentItemId; }) .Location("SummaryAdmin", "Actions:9")); } return(null); }
public async Task <IActionResult> Index(ViewModels.ContentOptions options, PagerParameters pagerParameters) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageEmailTemplates)) { return(Forbid()); } var siteSettings = await _siteService.GetSiteSettingsAsync(); var pager = new Pager(pagerParameters, siteSettings.PageSize); var templatesDocument = await _templatesManager.GetEmailTemplatesDocumentAsync(); var templates = templatesDocument.Templates.ToList(); if (!string.IsNullOrWhiteSpace(options.Search)) { templates = templates.Where(x => x.Value.Name.Contains(options.Search, StringComparison.OrdinalIgnoreCase)).ToList(); } var count = templates.Count; templates = templates.OrderBy(x => x.Value.Name) .Skip(pager.GetStartIndex()) .Take(pager.PageSize).ToList(); var pagerShape = (await New.Pager(pager)).TotalItemCount(count); var model = new EmailTemplateIndexViewModel { Templates = templates.ConvertAll(x => new TemplateEntry { Id = x.Key, Template = x.Value }), Options = options, Pager = pagerShape }; model.Options.ContentsBulkAction = new List <SelectListItem>() { new SelectListItem() { Text = S["Delete"], Value = nameof(ContentsBulkAction.Remove) } }; return(View("Index", model)); }
protected override void EditActivity(EmailTemplateTask activity, EmailTemplateTaskViewModel model) { var templateDocuments = _templatesManager.GetEmailTemplatesDocumentAsync().Result; model.EmailTemplates = new List <SelectListItem>(); foreach (var templateDocument in templateDocuments.Templates) { model.EmailTemplates.Add(new SelectListItem { Value = templateDocument.Key, Text = templateDocument.Value.Name }); } model.SelectedEmailTemplateId = activity.SelectedEmailTemplateId.Expression; model.TemplateModelExpression = activity.TemplateModelExpression.Expression; }
public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) { var allEmailTemplatesStep = step as AllEmailTemplatesDeploymentStep; if (allEmailTemplatesStep == null) { return; } var templateObjects = new JObject(); var templates = await _templatesManager.GetEmailTemplatesDocumentAsync(); foreach (var template in templates.Templates) { templateObjects[template.Key] = JObject.FromObject(template.Value); } result.Steps.Add(new JObject( new JProperty("id", "EmailTemplates"), new JProperty("EmailTemplates", templateObjects) )); }