Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        static SqlPreCommand?EmailTemplateLogic_PreDeleteSqlSync(Entity arg)
        {
            EmailModelEntity emailModel = (EmailModelEntity)arg;

            var emailTemplates = Administrator.UnsafeDeletePreCommand(Database.Query <EmailTemplateEntity>().Where(et => et.Model == emailModel));

            return(emailTemplates);
        }
Ejemplo n.º 3
0
        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)));
        }
Ejemplo n.º 4
0
 public static IQueryable <EmailTemplateEntity> EmailTemplates(this EmailModelEntity se)
 {
     return(EmailTemplatesExpression.Evaluate(se));
 }
Ejemplo n.º 5
0
 public static IQueryable <EmailTemplateEntity> EmailTemplates(this EmailModelEntity se) =>
 As.Expression(() => Database.Query <EmailTemplateEntity>().Where(et => et.Model == se));
Ejemplo n.º 6
0
 public static IEmailModel CreateModel(EmailModelEntity model, ModifiableEntity?entity)
 {
     return((IEmailModel)EmailModelLogic.GetEntityConstructor(model.ToType()).Invoke(new[] { entity }));
 }
Ejemplo n.º 7
0
        internal static bool HasDefaultTemplateConstructor(EmailModelEntity emailModelEntity)
        {
            EmailModelInfo info = registeredModels.GetOrThrow(emailModelEntity.ToType());

            return(info.DefaultTemplateConstructor != null);
        }
Ejemplo n.º 8
0
 public static bool RequiresExtraParameters(EmailModelEntity emailModelEntity)
 {
     return(GetEntityConstructor(entityToType.Value.GetOrThrow(emailModelEntity)) == null);
 }
Ejemplo n.º 9
0
 public static Type ToType(this EmailModelEntity modelEntity)
 {
     return(entityToType.Value.GetOrThrow(modelEntity, "The EmailModel {0} was not registered"));
 }
Ejemplo n.º 10
0
        public string GetConstructorType([Required, FromBody] EmailModelEntity model)
        {
            var type = EmailModelLogic.GetEntityType(model.ToType());

            return(ReflectionServer.GetTypeName(type));
        }