case 3999

This commit is contained in:
2021-10-14 23:19:12 +00:00
parent 29d98e4d77
commit 0a9d1fcbef
16 changed files with 46 additions and 85 deletions

View File

@@ -213,8 +213,7 @@ namespace AyaNova.Biz
{
if (obj != null)
searchParams.AddText(obj.Notes)
.AddText(obj.Name)
.AddText(obj.Number)
.AddText(obj.Name)
.AddText(obj.UPC)
.AddText(obj.WarrantyTerms)
.AddText(obj.Wiki)
@@ -233,23 +232,21 @@ namespace AyaNova.Biz
bool isNew = currentObj == null;
//## Name is not required nor required to be unique for a UnitModel so no validation for that here
//number is required but also not necessarily unique as two manufacturers could have the same model number for different products
//However, a number and vendorid combo must be unique as it's considered that the same vendor would not have two models with identical numbers
//Name required
if (string.IsNullOrWhiteSpace(proposedObj.Name))
AddError(ApiErrorCode.VALIDATION_REQUIRED, "Name");
//Number required
if (string.IsNullOrWhiteSpace(proposedObj.Number))
{
AddError(ApiErrorCode.VALIDATION_REQUIRED, "Number");
return;//this is disqualifying outright so no need to check further rules
}
//If Number is otherwise OK, check CONSTRAINT UNQ_UnitModelNumberVendorId UNIQUE (number, vendorid)
if (await ct.UnitModel.AnyAsync(m => m.Number == proposedObj.Number && m.VendorId == proposedObj.VendorId && m.Id != proposedObj.Id))
//If name is otherwise OK, check that name is unique
if (!PropertyHasErrors("Name"))
{
AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "Number", "Model number + Vendor must be unique");
return;//this is disqualifying outright so no need to check further rules
//Use Any command is efficient way to check existance, it doesn't return the record, just a true or false
if (await ct.UnitModel.AnyAsync(z => z.Name == proposedObj.Name && z.Id != proposedObj.Id))
{
AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "Name");
}
}
//Any form customizations to validate?
var FormCustomization = await ct.FormCustom.AsNoTracking().SingleOrDefaultAsync(z => z.FormKey == AyaType.UnitModel.ToString());