internal static EmailTemplateEntity CreateDefaultTemplate(EmailModelEntity emailModel) { EmailModelInfo info = registeredModels.GetOrThrow(entityToType.Value.GetOrThrow(emailModel)); if (info.DefaultTemplateConstructor == null) { throw new InvalidOperationException($"No EmailTemplate for {emailModel} found and DefaultTemplateConstructor = null"); } EmailTemplateEntity template = info.DefaultTemplateConstructor.Invoke(); if (template.MasterTemplate != null) { template.MasterTemplate = EmailMasterTemplateLogic.GetDefaultMasterTemplate(); } if (template.Name == null) { template.Name = emailModel.FullClassName; } template.Model = emailModel; template.Query = QueryLogic.GetQueryEntity(info.QueryName); template.ParseData(QueryLogic.Queries.QueryDescription(info.QueryName)); return(template); }
public static void Register() { new Construct(EmailTemplateOperation.Create) { Construct = _ => new EmailTemplateEntity { MasterTemplate = EmailMasterTemplateLogic.GetDefaultMasterTemplate(), } }.Register(); new Execute(EmailTemplateOperation.Save) { CanBeNew = true, CanBeModified = true, Execute = (t, _) => { } }.Register(); new Delete(EmailTemplateOperation.Delete) { Delete = (t, _) => { var attachments = t.Attachments.Select(a => a.ToLite()).ToList(); t.Delete(); attachments.ForEach(at => at.Delete()); } }.Register(); registered = true; }
internal static EmailTemplateEntity CreateDefaultTemplate(SystemEmailEntity systemEmail) { SystemEmailInfo info = systemEmails.GetOrThrow(systemEmailToType.Value.GetOrThrow(systemEmail)); EmailTemplateEntity template = info.DefaultTemplateConstructor(); if (template.MasterTemplate != null) { template.MasterTemplate = EmailMasterTemplateLogic.GetDefaultMasterTemplate(); } if (template.Name == null) { template.Name = systemEmail.FullClassName; } template.SystemEmail = systemEmail; template.Query = QueryLogic.GetQueryEntity(info.QueryName); template.ParseData(DynamicQueryManager.Current.QueryDescription(info.QueryName)); return(template); }
public static void Start(SchemaBuilder sb, Func <EmailTemplateEntity, Lite <Entity>?, SmtpConfigurationEntity?>?getSmtpConfiguration) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { CultureInfoLogic.AssertStarted(sb); TemplatingLogic.Start(sb); GetSmtpConfiguration = getSmtpConfiguration; sb.Include <EmailTemplateEntity>() .WithQuery(() => t => new { Entity = t, t.Id, t.Name, t.IsBodyHtml }); EmailTemplatesLazy = sb.GlobalLazy(() => Database.Query <EmailTemplateEntity>().ToDictionary(et => et.ToLite()) , new InvalidateWith(typeof(EmailTemplateEntity))); TemplatesByQueryName = sb.GlobalLazy(() => { return(EmailTemplatesLazy.Value.Values.SelectCatch(et => KVP.Create(et.Query.ToQueryName(), et)).GroupToDictionary()); }, new InvalidateWith(typeof(EmailTemplateEntity))); EmailModelLogic.Start(sb); EmailMasterTemplateLogic.Start(sb); sb.Schema.EntityEvents <EmailTemplateEntity>().PreSaving += new PreSavingEventHandler <EmailTemplateEntity>(EmailTemplate_PreSaving); sb.Schema.EntityEvents <EmailTemplateEntity>().Retrieved += EmailTemplateLogic_Retrieved; sb.Schema.Table <EmailModelEntity>().PreDeleteSqlSync += e => Administrator.UnsafeDeletePreCommand(Database.Query <EmailTemplateEntity>() .Where(a => a.Model.Is(e))); Validator.OverridePropertyValidator((EmailTemplateMessageEmbedded m) => m.Text).StaticPropertyValidation += EmailTemplateMessageText_StaticPropertyValidation; Validator.OverridePropertyValidator((EmailTemplateMessageEmbedded m) => m.Subject).StaticPropertyValidation += EmailTemplateMessageSubject_StaticPropertyValidation; EmailTemplateGraph.Register(); GlobalValueProvider.RegisterGlobalVariable("UrlLeft", _ => EmailLogic.Configuration.UrlLeft); GlobalValueProvider.RegisterGlobalVariable("Now", _ => TimeZoneManager.Now); GlobalValueProvider.RegisterGlobalVariable("Today", _ => TimeZoneManager.Now.Date, "d"); sb.Schema.Synchronizing += Schema_Synchronizing_Tokens; sb.Schema.Synchronizing += Schema_Synchronizing_DefaultTemplates; sb.Schema.Table <EmailModelEntity>().PreDeleteSqlSync += EmailTemplateLogic_PreDeleteSqlSync; Validator.PropertyValidator <EmailTemplateEntity>(et => et.Messages).StaticPropertyValidation += (et, pi) => { if (!et.Messages.Any(m => m.CultureInfo.Is(EmailLogic.Configuration.DefaultCulture))) { return(EmailTemplateMessage.ThereMustBeAMessageFor0.NiceToString().FormatWith(EmailLogic.Configuration.DefaultCulture.EnglishName)); } return(null); }; } }