From 4d685cab7b4b9380b42694dfeafcb3e3729ef633 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 22 Feb 2021 21:06:17 +0000 Subject: [PATCH] --- server/AyaNova/biz/PurchaseOrderBiz.cs | 5 +++-- server/AyaNova/biz/RequiredFieldsValidator.cs | 4 ++-- server/AyaNova/biz/ValidationError.cs | 9 ++++++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/server/AyaNova/biz/PurchaseOrderBiz.cs b/server/AyaNova/biz/PurchaseOrderBiz.cs index 1a6c50df..fb9ff27e 100644 --- a/server/AyaNova/biz/PurchaseOrderBiz.cs +++ b/server/AyaNova/biz/PurchaseOrderBiz.cs @@ -322,11 +322,12 @@ namespace AyaNova.Biz bool isNew = currentObj == null; //No poitem can receive negative amounts - foreach (var propPOItem in proposedObj.Items) + for (int i = 0; i < proposedObj.Items.Count; i++) { + var propPOItem = proposedObj.Items[i]; if (propPOItem.QuantityReceived < 0 || propPOItem.QuantityReceived > propPOItem.QuantityOrdered) { - AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "generalerror", "LT:PurchaseOrderReceiptItemQuantityReceivedErrorInvalid"); + AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, $"Items[{i}].QuantityReceived", "LT:PurchaseOrderReceiptItemQuantityReceivedErrorInvalid"); return; } } diff --git a/server/AyaNova/biz/RequiredFieldsValidator.cs b/server/AyaNova/biz/RequiredFieldsValidator.cs index 631d086d..632258f1 100644 --- a/server/AyaNova/biz/RequiredFieldsValidator.cs +++ b/server/AyaNova/biz/RequiredFieldsValidator.cs @@ -40,11 +40,11 @@ namespace AyaNova.Biz //TODO: CHILD COLLECTION MOD /* Update RequiredFieldsValidator to look for these period seperated items and navigate through teh collection by name / reflection to step through children and flag errors to include parent - e.g in validation error field name could be "poitems.vendorpartnumber:3" to indicate poitems collection 4th row has error in vendorpartnumber - or perhaps it makes sense to add a seperate INDEX property to make client processing easier and not a colon:index scheme in the field name (that actually makes more sense) + e.g in validation error field name could be "poitems[3].vendorpartnumber" to indicate poitems collection 4th row has error in vendorpartnumber */ //Now get the actual property name from the available fields using the lt key string RequiredPropertyName = FF.FieldKey; + //use reflection to get the underlying value from the proposed object to be saved object propertyValue = proposedObject.GetType().GetProperty(RequiredPropertyName).GetValue(proposedObject, null); diff --git a/server/AyaNova/biz/ValidationError.cs b/server/AyaNova/biz/ValidationError.cs index a3aeba47..7481407b 100644 --- a/server/AyaNova/biz/ValidationError.cs +++ b/server/AyaNova/biz/ValidationError.cs @@ -1,8 +1,15 @@ namespace AyaNova.Biz { -//TODO: CHILD COLLECTION MOD add "Index" property to indicate child collection index location of error + public class ValidationError { + //TARGET is the Model name of the property which matches the client UI annotations for ref + + //if the target error is a child item collection field the Target must be "items[2].field" + //where "items" is the item collection model name and 2 is the index of the collection with the error and field is the ultimate field model name + //Case doesn't matter as the client will compare in lower case all items anyway + + public ApiErrorCode Code { get; set; } public string Target { get; set; } public string Message { get; set; }