This commit is contained in:
2020-07-31 23:41:38 +00:00
parent a760112691
commit 56a278f3a8

View File

@@ -42,7 +42,7 @@ namespace AyaNova.Biz
//
internal async Task<NotifySubscription> CreateAsync(NotifySubscription newObject)
{
// await ValidateAsync(newObject);
await ValidateAsync(newObject);
if (HasErrors)
return null;
else
@@ -112,7 +112,7 @@ namespace AyaNova.Biz
dbObject.Tags = TagBiz.NormalizeTags(dbObject.Tags);
ct.Entry(dbObject).OriginalValues["Concurrency"] = putObject.Concurrency;
// await ValidateAsync(dbObject);
await ValidateAsync(dbObject);
if (HasErrors) return null;
try
{
@@ -171,77 +171,117 @@ namespace AyaNova.Biz
// ////////////////////////////////////////////////////////////////////////////////////////////////
// //VALIDATION
// //
// private async Task ValidateAsync(NotifySubscription proposedObj)
// {
////////////////////////////////////////////////////////////////////////////////////////////////
//VALIDATION
//
private async Task ValidateAsync(NotifySubscription proposedObj)
{
// //###############################################################################
// //todo: validate subscription is valid
// //perhaps check if customer type user doesn't have non customer notification etc
//###############################################################################
//todo: validate subscription is valid
//perhaps check if customer type user doesn't have non customer notification etc
// //todo: notifysubscriptionbiz Check for duplicate before accepting new / edit in validator
// //DISALLOW entirely duplicate notifications (down to email address)
// //USE NAME DUPE CHECK PATTERN BELOW
// //###############################################################################
//todo: notifysubscriptionbiz Check for duplicate before accepting new / edit in validator
//DISALLOW entirely duplicate notifications (down to email address)
//USE NAME DUPE CHECK PATTERN BELOW
//###############################################################################
//ensure user exists and need it for other shit later
var user = await ct.User.AsNoTracking().FirstOrDefaultAsync(z => z.Id == proposedObj.UserId);
if (user == null)
{
AddError(ApiErrorCode.VALIDATION_REQUIRED, "UserId");
}
else
{
//Validate user can see this subscription type
if (user.UserType == UserType.Customer || user.UserType == UserType.HeadOffice)
{
//Outside users can't choose inside user type notification events
switch (proposedObj.EventType)
{
case NotifyEventType.CSRAccepted:
case NotifyEventType.CSRRejected:
case NotifyEventType.CustomerServiceImminent:
break;
default:
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "EventType");
break;
}
}
else
{
//Inside users can't use Outside (customer) users notification types
switch (proposedObj.EventType)
{
case NotifyEventType.CSRAccepted:
case NotifyEventType.CSRRejected:
case NotifyEventType.CustomerServiceImminent:
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "EventType");
break;
default:
break;
}
}
}
//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
// if (string.IsNullOrWhiteSpace(proposedObj.Name))
// AddError(ApiErrorCode.VALIDATION_REQUIRED, "Name");
// // //Name required
// // if (string.IsNullOrWhiteSpace(proposedObj.Name))
// // AddError(ApiErrorCode.VALIDATION_REQUIRED, "Name");
// //Name must be less than 255 characters
// if (proposedObj.Name.Length > 255)
// AddError(ApiErrorCode.VALIDATION_LENGTH_EXCEEDED, "Name", "255 max");
// // //Name must be less than 255 characters
// // if (proposedObj.Name.Length > 255)
// // AddError(ApiErrorCode.VALIDATION_LENGTH_EXCEEDED, "Name", "255 max");
// //If name is otherwise OK, check that name is unique
// if (!PropertyHasErrors("Name"))
// {
// //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))
// {
// AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "Name");
// }
// }
// // //If name is otherwise OK, check that name is unique
// // if (!PropertyHasErrors("Name"))
// // {
// // //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))
// // {
// // AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "Name");
// // }
// // }
// //Start date AND end date must both be null or both contain values
// if (proposedObj.StartDate == null && proposedObj.EndDate != null)
// AddError(ApiErrorCode.VALIDATION_REQUIRED, "StartDate");
// // //Start date AND end date must both be null or both contain values
// // if (proposedObj.StartDate == null && proposedObj.EndDate != null)
// // AddError(ApiErrorCode.VALIDATION_REQUIRED, "StartDate");
// if (proposedObj.StartDate != null && proposedObj.EndDate == null)
// AddError(ApiErrorCode.VALIDATION_REQUIRED, "EndDate");
// // if (proposedObj.StartDate != null && proposedObj.EndDate == null)
// // AddError(ApiErrorCode.VALIDATION_REQUIRED, "EndDate");
// //Start date before end date
// if (proposedObj.StartDate != null && proposedObj.EndDate != null)
// if (proposedObj.StartDate > proposedObj.EndDate)
// AddError(ApiErrorCode.VALIDATION_STARTDATE_AFTER_ENDDATE, "StartDate");
// // //Start date before end date
// // if (proposedObj.StartDate != null && proposedObj.EndDate != null)
// // if (proposedObj.StartDate > proposedObj.EndDate)
// // AddError(ApiErrorCode.VALIDATION_STARTDATE_AFTER_ENDDATE, "StartDate");
// //Enum is valid value
// if (!proposedObj.UserType.IsValid())
// {
// AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "UserType");
// }
// // //Enum is valid value
// // if (!proposedObj.UserType.IsValid())
// // {
// // AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "UserType");
// // }
// //Any form customizations to validate?
// var FormCustomization = await ct.FormCustom.AsNoTracking().SingleOrDefaultAsync(z => z.FormKey == AyaType.NotifySubscription.ToString());
// if (FormCustomization != null)
// {
// //Yeppers, do the validation, there are two, the custom fields and the regular fields that might be set to required
// // //Any form customizations to validate?
// // var FormCustomization = await ct.FormCustom.AsNoTracking().SingleOrDefaultAsync(z => z.FormKey == AyaType.NotifySubscription.ToString());
// // if (FormCustomization != null)
// // {
// // //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
// RequiredFieldsValidator.Validate(this, FormCustomization, proposedObj);
// // //validate users choices for required non custom fields
// // RequiredFieldsValidator.Validate(this, FormCustomization, proposedObj);
// // //validate custom fields
// // CustomFieldsValidator.Validate(this, FormCustomization, proposedObj.CustomFields);
// // }
// }
// //validate custom fields
// CustomFieldsValidator.Validate(this, FormCustomization, proposedObj.CustomFields);
// }
}
// private void ValidateCanDelete(NotifySubscription inObj)
// {