|
@@ -212,34 +212,9 @@ namespace InABox.Core
|
|
|
Instance.Form.ID = formid;
|
|
|
}
|
|
|
|
|
|
- public string? EvaluateExpression(string expression)
|
|
|
- {
|
|
|
- if (string.IsNullOrWhiteSpace(expression))
|
|
|
- return null;
|
|
|
-
|
|
|
- Dictionary<string, object?> variables = new Dictionary<string, object?>();
|
|
|
-
|
|
|
- var formData = DigitalForm.DeserializeFormData(Instance);
|
|
|
- if(formData != null)
|
|
|
- {
|
|
|
- foreach (var item in formData.Items())
|
|
|
- variables[$"Data.{item.Key}"] = item.Value;
|
|
|
- }
|
|
|
-
|
|
|
- foreach (var property in DatabaseSchema.Properties(Instance.GetType()).Where(x => !x.Name.StartsWith("Parent.")))
|
|
|
- variables[$"Form.{property.Name}"] = property.Getter()(Instance);
|
|
|
-
|
|
|
- foreach (var property in DatabaseSchema.Properties(Entity.GetType()))
|
|
|
- variables[$"{typeof(TEntity).Name}.{property.Name}"] = property.Getter()(Entity);
|
|
|
-
|
|
|
- var exp = new CoreExpression(expression);
|
|
|
- return exp.Evaluate(variables)?.ToString();
|
|
|
- }
|
|
|
-
|
|
|
private void DoUpdate()
|
|
|
{
|
|
|
-
|
|
|
- var result = EvaluateExpression(Instance.Form.DescriptionExpression);
|
|
|
+ var result = DigitalFormDataModel.EvaluateExpression(Instance.Form.DescriptionExpression, Instance, Entity);
|
|
|
Instance.Description = !String.IsNullOrWhiteSpace(result)
|
|
|
? result
|
|
|
: Instance.Form.Description;
|
|
@@ -286,4 +261,72 @@ namespace InABox.Core
|
|
|
OnModelSaved?.Invoke(this);
|
|
|
}
|
|
|
}
|
|
|
+ public static class DigitalFormDataModel
|
|
|
+ {
|
|
|
+ public static string? EvaluateExpression(string expression, IDigitalFormInstance instance, Entity entity)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrWhiteSpace(expression))
|
|
|
+ return null;
|
|
|
+
|
|
|
+ Dictionary<string, object?> variables = new Dictionary<string, object?>();
|
|
|
+
|
|
|
+ var formData = DigitalForm.DeserializeFormData(instance);
|
|
|
+ if(formData != null)
|
|
|
+ {
|
|
|
+ foreach (var item in formData.Items())
|
|
|
+ variables[$"Data.{item.Key}"] = item.Value;
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach (var property in DatabaseSchema.Properties(instance.GetType()).Where(x => !x.Name.StartsWith("Parent.")))
|
|
|
+ variables[$"Form.{property.Name}"] = property.Getter()(instance);
|
|
|
+
|
|
|
+ foreach (var property in DatabaseSchema.Properties(entity.GetType()))
|
|
|
+ variables[$"{entity.GetType().Name}.{property.Name}"] = property.Getter()(entity);
|
|
|
+
|
|
|
+ var exp = new CoreExpression(expression);
|
|
|
+ return exp.Evaluate(variables)?.ToString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void Update(IDigitalFormInstance instance, Entity entity)
|
|
|
+ {
|
|
|
+ var result = EvaluateExpression(instance.Form.DescriptionExpression, instance, entity);
|
|
|
+ instance.Description = !String.IsNullOrWhiteSpace(result)
|
|
|
+ ? result
|
|
|
+ : instance.Form.Description;
|
|
|
+
|
|
|
+ var entityaudittrail = "";
|
|
|
+ var instanceaudittrail = "";
|
|
|
+
|
|
|
+ var parents = new MultiSave();
|
|
|
+ if (entity.IsChanged())
|
|
|
+ {
|
|
|
+ parents.Add(entity);
|
|
|
+ entityaudittrail = "Updated from App - Digital Forms Module";
|
|
|
+ }
|
|
|
+ else if (entity.ID == Guid.Empty)
|
|
|
+ {
|
|
|
+ parents.Add(entity);
|
|
|
+ entityaudittrail = "Created from App - Digital Forms Module";
|
|
|
+ }
|
|
|
+
|
|
|
+ parents.Save(null, entityaudittrail);
|
|
|
+
|
|
|
+ instance.Parent.ID = entity.ID;
|
|
|
+
|
|
|
+ var children = new MultiSave();
|
|
|
+ if (instance.IsChanged())
|
|
|
+ {
|
|
|
+ children.Add((Entity)instance);
|
|
|
+ instanceaudittrail = "Updated from App - Digital Forms Module";
|
|
|
+ }
|
|
|
+ else if (entity.ID == Guid.Empty)
|
|
|
+ {
|
|
|
+ children.Add((Entity)instance);
|
|
|
+ instanceaudittrail = "Created from App - Digital Forms Module";
|
|
|
+ }
|
|
|
+ children.Save(null, instanceaudittrail);
|
|
|
+
|
|
|
+ DFUtils.OnSave(instance.GetType(), instance, entity);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|