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); }
static SqlPreCommand?EmailTemplateLogic_PreDeleteSqlSync(Entity arg) { EmailModelEntity emailModel = (EmailModelEntity)arg; var emailTemplates = Administrator.UnsafeDeletePreCommand(Database.Query <EmailTemplateEntity>().Where(et => et.Model == emailModel)); return(emailTemplates); }
private static EmailTemplateEntity GetDefaultTemplate(EmailModelEntity emailModelEntity, Entity?entity) { var isAllowed = Schema.Current.GetInMemoryFilter <EmailTemplateEntity>(userInterface: false); var templates = EmailModelToTemplates.Value.TryGetC(emailModelEntity.ToLite()).EmptyIfNull(); if (templates.IsNullOrEmpty()) { using (ExecutionMode.Global()) using (OperationLogic.AllowSave <EmailTemplateEntity>()) using (Transaction tr = Transaction.ForceNew()) { var template = CreateDefaultTemplate(emailModelEntity); template.Save(); return(tr.Commit(template)); } } templates = templates.Where(isAllowed); return(templates.Where(t => t.IsApplicable(entity)).SingleEx(() => "Active EmailTemplates for EmailModel {0}".FormatWith(emailModelEntity))); }
public static IQueryable <EmailTemplateEntity> EmailTemplates(this EmailModelEntity se) { return(EmailTemplatesExpression.Evaluate(se)); }
public static IQueryable <EmailTemplateEntity> EmailTemplates(this EmailModelEntity se) => As.Expression(() => Database.Query <EmailTemplateEntity>().Where(et => et.Model == se));
public static IEmailModel CreateModel(EmailModelEntity model, ModifiableEntity?entity) { return((IEmailModel)EmailModelLogic.GetEntityConstructor(model.ToType()).Invoke(new[] { entity })); }
internal static bool HasDefaultTemplateConstructor(EmailModelEntity emailModelEntity) { EmailModelInfo info = registeredModels.GetOrThrow(emailModelEntity.ToType()); return(info.DefaultTemplateConstructor != null); }
public static bool RequiresExtraParameters(EmailModelEntity emailModelEntity) { return(GetEntityConstructor(entityToType.Value.GetOrThrow(emailModelEntity)) == null); }
public static Type ToType(this EmailModelEntity modelEntity) { return(entityToType.Value.GetOrThrow(modelEntity, "The EmailModel {0} was not registered")); }
public string GetConstructorType([Required, FromBody] EmailModelEntity model) { var type = EmailModelLogic.GetEntityType(model.ToType()); return(ReflectionServer.GetTypeName(type)); }