|
@@ -208,30 +208,36 @@ namespace InABox.Core
|
|
|
Instance.Form.ID = formid;
|
|
|
}
|
|
|
|
|
|
- private void DoUpdate()
|
|
|
+ public string? EvaluateExpression(string expression)
|
|
|
{
|
|
|
- if (!String.IsNullOrWhiteSpace(this.Instance.Form.DescriptionExpression))
|
|
|
- {
|
|
|
- Dictionary<string, object?> variables = new Dictionary<string, object?>();
|
|
|
+ if (string.IsNullOrWhiteSpace(expression))
|
|
|
+ return null;
|
|
|
+
|
|
|
+ Dictionary<string, object?> variables = new Dictionary<string, object?>();
|
|
|
|
|
|
- var formData = DigitalForm.DeserializeFormData(Instance);
|
|
|
- foreach (var item in formData.Items())
|
|
|
- variables[$"Data.{item.Key}"] = item.Value;
|
|
|
+ var formData = DigitalForm.DeserializeFormData(Instance);
|
|
|
+ foreach (var item in formData.Items())
|
|
|
+ variables[$"Data.{item.Key}"] = item.Value;
|
|
|
|
|
|
- var instancedata = Instance.GetValues(true);
|
|
|
- foreach (var item in instancedata)
|
|
|
- variables[$"Form.{item.Key}"] = item.Value;
|
|
|
+ var instancedata = Instance.GetValues(true);
|
|
|
+ foreach (var item in instancedata)
|
|
|
+ variables[$"Form.{item.Key}"] = item.Value;
|
|
|
|
|
|
- var entitydata = Entity.GetValues(true);
|
|
|
- foreach (var item in entitydata)
|
|
|
- variables[$"{typeof(TEntity).EntityName().Split('.').Last()}.{item.Key}"] = item.Value;
|
|
|
+ var entitydata = Entity.GetValues(true);
|
|
|
+ foreach (var item in entitydata)
|
|
|
+ variables[$"{typeof(TEntity).EntityName().Split('.').Last()}.{item.Key}"] = item.Value;
|
|
|
|
|
|
- var expression = new CoreExpression(Instance.Form.DescriptionExpression);
|
|
|
- var result = expression.Evaluate(variables)?.ToString();
|
|
|
- Instance.Description = !String.IsNullOrWhiteSpace(result)
|
|
|
- ? result
|
|
|
- : Instance.Form.Description;
|
|
|
- }
|
|
|
+ var exp = new CoreExpression(expression);
|
|
|
+ return exp.Evaluate(variables)?.ToString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void DoUpdate()
|
|
|
+ {
|
|
|
+
|
|
|
+ var result = EvaluateExpression(Instance.Form.DescriptionExpression);
|
|
|
+ Instance.Description = !String.IsNullOrWhiteSpace(result)
|
|
|
+ ? result
|
|
|
+ : Instance.Form.Description;
|
|
|
|
|
|
BeforeModelSaved?.Invoke(this);
|
|
|
|