This commit is contained in:
2020-07-29 19:16:58 +00:00
parent c824fb531d
commit e4ef3c5cd5

View File

@@ -42,7 +42,7 @@ namespace AyaNova.Biz
// //
internal async Task<NotifySubscription> CreateAsync(NotifySubscription newObject) internal async Task<NotifySubscription> CreateAsync(NotifySubscription newObject)
{ {
await ValidateAsync(newObject); // await ValidateAsync(newObject);
if (HasErrors) if (HasErrors)
return null; return null;
else else
@@ -112,7 +112,7 @@ namespace AyaNova.Biz
dbObject.Tags = TagBiz.NormalizeTags(dbObject.Tags); dbObject.Tags = TagBiz.NormalizeTags(dbObject.Tags);
ct.Entry(dbObject).OriginalValues["Concurrency"] = putObject.Concurrency; ct.Entry(dbObject).OriginalValues["Concurrency"] = putObject.Concurrency;
await ValidateAsync(dbObject); // await ValidateAsync(dbObject);
if (HasErrors) return null; if (HasErrors) return null;
try try
{ {
@@ -142,7 +142,7 @@ namespace AyaNova.Biz
try try
{ {
NotifySubscription dbObject = await ct.NotifySubscription.SingleOrDefaultAsync(z => z.Id == id); NotifySubscription dbObject = await ct.NotifySubscription.SingleOrDefaultAsync(z => z.Id == id);
ValidateCanDelete(dbObject); //ValidateCanDelete(dbObject);
if (HasErrors) if (HasErrors)
return false; return false;
if (HasErrors) if (HasErrors)
@@ -171,82 +171,82 @@ namespace AyaNova.Biz
//////////////////////////////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////////////////////////////
//VALIDATION // //VALIDATION
// // //
private async Task ValidateAsync(NotifySubscription proposedObj) // private async Task ValidateAsync(NotifySubscription proposedObj)
{ // {
//############################################################################### // //###############################################################################
//todo: validate subscription is valid // //todo: validate subscription is valid
//perhaps check if customer type user doesn't have non customer notification etc // //perhaps check if customer type user doesn't have non customer notification etc
//todo: notifysubscriptionbiz Check for duplicate before accepting new / edit in validator // //todo: notifysubscriptionbiz Check for duplicate before accepting new / edit in validator
//DISALLOW entirely duplicate notifications (down to email address) // //DISALLOW entirely duplicate notifications (down to email address)
//USE NAME DUPE CHECK PATTERN BELOW // //USE NAME DUPE CHECK PATTERN BELOW
//############################################################################### // //###############################################################################
//NOTE: In DB schema only name and serial are not nullable // //NOTE: In DB schema only name and serial are not nullable
//run validation and biz rules // //run validation and biz rules
// //Name required // // //Name required
// if (string.IsNullOrWhiteSpace(proposedObj.Name)) // // if (string.IsNullOrWhiteSpace(proposedObj.Name))
// AddError(ApiErrorCode.VALIDATION_REQUIRED, "Name"); // // AddError(ApiErrorCode.VALIDATION_REQUIRED, "Name");
// //Name must be less than 255 characters // // //Name must be less than 255 characters
// if (proposedObj.Name.Length > 255) // // if (proposedObj.Name.Length > 255)
// AddError(ApiErrorCode.VALIDATION_LENGTH_EXCEEDED, "Name", "255 max"); // // AddError(ApiErrorCode.VALIDATION_LENGTH_EXCEEDED, "Name", "255 max");
// //If name is otherwise OK, check that name is unique // // //If name is otherwise OK, check that name is unique
// if (!PropertyHasErrors("Name")) // // if (!PropertyHasErrors("Name"))
// { // // {
// //Use Any command is efficient way to check existance, it doesn't return the record, just a true or false // // //Use Any command is efficient way to check existance, it doesn't return the record, just a true or false
// if (await ct.NotifySubscription.AnyAsync(z => z.Name == proposedObj.Name && z.Id != proposedObj.Id)) // // if (await ct.NotifySubscription.AnyAsync(z => z.Name == proposedObj.Name && z.Id != proposedObj.Id))
// { // // {
// AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "Name"); // // AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "Name");
// } // // }
// } // // }
// //Start date AND end date must both be null or both contain values // // //Start date AND end date must both be null or both contain values
// if (proposedObj.StartDate == null && proposedObj.EndDate != null) // // if (proposedObj.StartDate == null && proposedObj.EndDate != null)
// AddError(ApiErrorCode.VALIDATION_REQUIRED, "StartDate"); // // AddError(ApiErrorCode.VALIDATION_REQUIRED, "StartDate");
// if (proposedObj.StartDate != null && proposedObj.EndDate == null) // // if (proposedObj.StartDate != null && proposedObj.EndDate == null)
// AddError(ApiErrorCode.VALIDATION_REQUIRED, "EndDate"); // // AddError(ApiErrorCode.VALIDATION_REQUIRED, "EndDate");
// //Start date before end date // // //Start date before end date
// if (proposedObj.StartDate != null && proposedObj.EndDate != null) // // if (proposedObj.StartDate != null && proposedObj.EndDate != null)
// if (proposedObj.StartDate > proposedObj.EndDate) // // if (proposedObj.StartDate > proposedObj.EndDate)
// AddError(ApiErrorCode.VALIDATION_STARTDATE_AFTER_ENDDATE, "StartDate"); // // AddError(ApiErrorCode.VALIDATION_STARTDATE_AFTER_ENDDATE, "StartDate");
// //Enum is valid value // // //Enum is valid value
// if (!proposedObj.UserType.IsValid()) // // if (!proposedObj.UserType.IsValid())
// { // // {
// AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "UserType"); // // AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "UserType");
// } // // }
// //Any form customizations to validate? // // //Any form customizations to validate?
// var FormCustomization = await ct.FormCustom.AsNoTracking().SingleOrDefaultAsync(z => z.FormKey == AyaType.NotifySubscription.ToString()); // // var FormCustomization = await ct.FormCustom.AsNoTracking().SingleOrDefaultAsync(z => z.FormKey == AyaType.NotifySubscription.ToString());
// if (FormCustomization != null) // // if (FormCustomization != null)
// { // // {
// //Yeppers, do the validation, there are two, the custom fields and the regular fields that might be set to required // // //Yeppers, do the validation, there are two, the custom fields and the regular fields that might be set to required
// //validate users choices for required non custom fields // // //validate users choices for required non custom fields
// RequiredFieldsValidator.Validate(this, FormCustomization, proposedObj); // // RequiredFieldsValidator.Validate(this, FormCustomization, proposedObj);
// //validate custom fields // // //validate custom fields
// CustomFieldsValidator.Validate(this, FormCustomization, proposedObj.CustomFields); // // CustomFieldsValidator.Validate(this, FormCustomization, proposedObj.CustomFields);
// } // // }
} // }
private void ValidateCanDelete(NotifySubscription inObj) // private void ValidateCanDelete(NotifySubscription inObj)
{ // {
//whatever needs to be check to delete this object // //whatever needs to be check to delete this object
} // }