Skip to content

Commit 07d35ff

Browse files
Merge pull request #21 from Inxton/bulk_data_validation_fix_when_not_modified
* validation has been reported when write status was NoChange
2 parents d205dd8 + bc584ff commit 07d35ff

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

src/TcoData/src/Wpf/TcoData.Wpf/Data/BulkData/Helpers/PropertyHelper.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@
77

88
namespace TcoData.Helpers
99
{
10+
using System;
11+
using System.Linq.Expressions;
12+
13+
public static class SymbolHelper
14+
{
15+
public static string GetFullPath<T>(Expression<Func<T>> expr)
16+
{
17+
var memberExpr = expr.Body as MemberExpression;
18+
if (memberExpr == null)
19+
throw new ArgumentException("Expression must be a MemberExpression");
20+
21+
var parts = new System.Collections.Generic.List<string>();
22+
while (memberExpr != null)
23+
{
24+
parts.Insert(0, memberExpr.Member.Name);
25+
memberExpr = memberExpr.Expression as MemberExpression;
26+
}
27+
28+
return string.Join(".", parts);
29+
}
30+
}
31+
1032
public static class PropertyHelper
1133
{
1234
public static string GetPropertyName<T, TProperty>(Expression<Func<T, TProperty>> property)

src/TcoData/src/Wpf/TcoData.Wpf/Data/BulkData/Models/BulkTraversalModel.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ public void ApplyWriteRequests()
203203

204204
if (!writeItems.Any())
205205
return;
206+
// Create a HashSet for fast symbol lookup
207+
var modifiedSymbols = new HashSet<string>(writeItems.Where(p=>p.WriteStatus == BulkItemWriteStatus.Modified).Select(i => i.Symbol));
206208

207209
IEnumerable<TEntity> allEntities = new List<TEntity>();
208210
if (WriteToAllEntities)
@@ -236,11 +238,11 @@ public void ApplyWriteRequests()
236238
if (validations != null && validations.Any())
237239
{
238240
LastValidationLog = string.Join(Environment.NewLine, validations
239-
.Where(v => v.Failed == true)
241+
.Where(v => v.Failed == true && modifiedSymbols.Any(symbol => v.Error.Contains(symbol)))
240242
.Select(v => $"❌ {v.Error}"));
241243
}
242244

243-
if (validations.Any(p => p.Failed == true))
245+
if (validations.Any(v => v.Failed && modifiedSymbols.Any(symbol => v.Error.Contains(symbol))))
244246
{
245247
return;
246248
}

src/TcoData/tests/Sandbox.TcoData.Wpf/App.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ public App()
9999
{
100100
return new DataItemValidation[]
101101
{
102-
new DataItemValidation($"'{nameof(data.sampleData.SampleInt)}' must be greater than 0", data.sampleData.SampleInt <= 0),
102+
new DataItemValidation($"'{SymbolHelper.GetFullPath(() =>data.sampleData.SampleInt)}' must be greater than 0", data.sampleData.SampleInt <= 0),
103103

104-
new DataItemValidation($"'{nameof(data.sampleData.SampleInt2)}' must be less than 0", data.sampleData.SampleInt2 > 0)
104+
new DataItemValidation($"'{SymbolHelper.GetFullPath(() =>data.sampleData.SampleInt2)}' must be less than 0", data.sampleData.SampleInt2 > 0)
105105
};
106106
};
107107

0 commit comments

Comments
 (0)