This commit is contained in:
@@ -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
|
||||||
{
|
{
|
||||||
@@ -171,77 +171,117 @@ 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
|
||||||
// //###############################################################################
|
//###############################################################################
|
||||||
|
|
||||||
|
//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
|
// //Name must be less than 255 characters
|
||||||
// // if (string.IsNullOrWhiteSpace(proposedObj.Name))
|
// if (proposedObj.Name.Length > 255)
|
||||||
// // AddError(ApiErrorCode.VALIDATION_REQUIRED, "Name");
|
// AddError(ApiErrorCode.VALIDATION_LENGTH_EXCEEDED, "Name", "255 max");
|
||||||
|
|
||||||
// // //Name must be less than 255 characters
|
// //If name is otherwise OK, check that name is unique
|
||||||
// // if (proposedObj.Name.Length > 255)
|
// if (!PropertyHasErrors("Name"))
|
||||||
// // AddError(ApiErrorCode.VALIDATION_LENGTH_EXCEEDED, "Name", "255 max");
|
// {
|
||||||
|
// //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
|
// //Start date AND end date must both be null or both contain values
|
||||||
// // if (!PropertyHasErrors("Name"))
|
// if (proposedObj.StartDate == null && proposedObj.EndDate != null)
|
||||||
// // {
|
// AddError(ApiErrorCode.VALIDATION_REQUIRED, "StartDate");
|
||||||
// // //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)
|
||||||
// // if (proposedObj.StartDate == null && proposedObj.EndDate != null)
|
// AddError(ApiErrorCode.VALIDATION_REQUIRED, "EndDate");
|
||||||
// // AddError(ApiErrorCode.VALIDATION_REQUIRED, "StartDate");
|
|
||||||
|
|
||||||
// // if (proposedObj.StartDate != null && proposedObj.EndDate == null)
|
// //Start date before end date
|
||||||
// // AddError(ApiErrorCode.VALIDATION_REQUIRED, "EndDate");
|
// if (proposedObj.StartDate != null && proposedObj.EndDate != null)
|
||||||
|
// if (proposedObj.StartDate > proposedObj.EndDate)
|
||||||
|
// AddError(ApiErrorCode.VALIDATION_STARTDATE_AFTER_ENDDATE, "StartDate");
|
||||||
|
|
||||||
// // //Start date before end date
|
// //Enum is valid value
|
||||||
// // if (proposedObj.StartDate != null && proposedObj.EndDate != null)
|
// if (!proposedObj.UserType.IsValid())
|
||||||
// // if (proposedObj.StartDate > proposedObj.EndDate)
|
// {
|
||||||
// // AddError(ApiErrorCode.VALIDATION_STARTDATE_AFTER_ENDDATE, "StartDate");
|
// AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "UserType");
|
||||||
|
// }
|
||||||
|
|
||||||
// // //Enum is valid value
|
// //Any form customizations to validate?
|
||||||
// // if (!proposedObj.UserType.IsValid())
|
// var FormCustomization = await ct.FormCustom.AsNoTracking().SingleOrDefaultAsync(z => z.FormKey == AyaType.NotifySubscription.ToString());
|
||||||
// // {
|
// if (FormCustomization != null)
|
||||||
// // AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "UserType");
|
// {
|
||||||
// // }
|
// //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?
|
// //validate users choices for required non custom fields
|
||||||
// // var FormCustomization = await ct.FormCustom.AsNoTracking().SingleOrDefaultAsync(z => z.FormKey == AyaType.NotifySubscription.ToString());
|
// RequiredFieldsValidator.Validate(this, FormCustomization, proposedObj);
|
||||||
// // 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
|
// //validate custom fields
|
||||||
// // RequiredFieldsValidator.Validate(this, FormCustomization, proposedObj);
|
// CustomFieldsValidator.Validate(this, FormCustomization, proposedObj.CustomFields);
|
||||||
|
// }
|
||||||
// // //validate custom fields
|
}
|
||||||
// // CustomFieldsValidator.Validate(this, FormCustomization, proposedObj.CustomFields);
|
|
||||||
// // }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private void ValidateCanDelete(NotifySubscription inObj)
|
// private void ValidateCanDelete(NotifySubscription inObj)
|
||||||
// {
|
// {
|
||||||
|
|||||||
Reference in New Issue
Block a user