This commit is contained in:
@@ -77,53 +77,19 @@ namespace AyaNova.Biz
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//DUPLICATE
|
||||
//
|
||||
|
||||
internal async Task<DataListSavedFilter> DuplicateAsync(DataListSavedFilter dbObject)
|
||||
{
|
||||
|
||||
DataListSavedFilter outObj = new DataListSavedFilter();
|
||||
CopyObject.Copy(dbObject, outObj);
|
||||
//generate unique name
|
||||
string newUniqueName = string.Empty;
|
||||
bool NotUnique = true;
|
||||
long l = 1;
|
||||
do
|
||||
{
|
||||
newUniqueName = Util.StringUtil.UniqueNameBuilder(dbObject.Name, l++, 255);
|
||||
NotUnique = await ct.DataListSavedFilter.AnyAsync(z => z.Name == newUniqueName);
|
||||
} while (NotUnique);
|
||||
outObj.Name = newUniqueName;
|
||||
outObj.Id = 0;
|
||||
outObj.Concurrency = 0;
|
||||
|
||||
|
||||
|
||||
await ct.DataListSavedFilter.AddAsync(outObj);
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//Handle child and associated items:
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
|
||||
|
||||
return outObj;
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// GET
|
||||
|
||||
//Get one
|
||||
internal async Task<DataListSavedFilter> GetAsync(long fetchId, bool logTheGetEvent = true)
|
||||
internal async Task<DataListSavedFilter> GetAsync(long fetchId)
|
||||
{
|
||||
//This is simple so nothing more here, but often will be copying to a different output object or some other ops
|
||||
var ret = await ct.DataListSavedFilter.SingleOrDefaultAsync(z => z.Id == fetchId && (z.Public == true || z.UserId == UserId));
|
||||
if (logTheGetEvent && ret != null)
|
||||
{
|
||||
//Log
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, fetchId, BizType, AyaEvent.Retrieved), ct);
|
||||
}
|
||||
var ret = await ct.DataListSavedFilter.AsNoTracking().SingleOrDefaultAsync(z => z.Id == fetchId && (z.Public == true || z.UserId == UserId));
|
||||
// if (logTheGetEvent && ret != null)
|
||||
// {
|
||||
// //Log
|
||||
// await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, fetchId, BizType, AyaEvent.Retrieved), ct);
|
||||
// }
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -204,27 +170,15 @@ namespace AyaNova.Biz
|
||||
//
|
||||
internal async Task<bool> DeleteAsync(DataListSavedFilter dbObject)
|
||||
{
|
||||
//Determine if the object can be deleted, do the deletion tentatively
|
||||
//Probably also in here deal with tags and associated search text etc
|
||||
|
||||
//FUTURE POSSIBLE NEED
|
||||
//ValidateCanDelete(dbObject);
|
||||
|
||||
ValidateCanDelete(dbObject);
|
||||
if (HasErrors)
|
||||
return false;
|
||||
ct.DataListSavedFilter.Remove(dbObject);
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//Delete sibling objects
|
||||
|
||||
//Event log process delete
|
||||
await EventLogProcessor.DeleteObjectLogAsync(UserId, BizType, dbObject.Id, dbObject.Name, ct);
|
||||
|
||||
|
||||
//Delete search index
|
||||
//Search.ProcessDeletedObjectKeywords(dbObject.Id, BizType);
|
||||
|
||||
|
||||
//was it a "reset" of default?
|
||||
if (dbObject.DefaultFilter)
|
||||
await EnsureDefaultAsync(dbObject.ListKey);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -232,6 +186,15 @@ namespace AyaNova.Biz
|
||||
//VALIDATION
|
||||
//
|
||||
|
||||
private void ValidateCanDelete(DataListSavedFilter inObj)
|
||||
{
|
||||
if (inObj.UserId != UserId)
|
||||
{
|
||||
AddError(ApiErrorCode.NOT_AUTHORIZED, "generalerror", "Can't delete another users filter");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Can save or update?
|
||||
private void Validate(DataListSavedFilter inObj, bool isNew)
|
||||
{
|
||||
@@ -285,53 +248,6 @@ namespace AyaNova.Biz
|
||||
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Filter", "Filter is not valid JSON string, can't convert to List<DataListFilterOption>, error: " + ex.Message);
|
||||
}
|
||||
|
||||
|
||||
// //Filter json must parse
|
||||
// //this is all automated normally so not going to do too much parsing here
|
||||
// //just ensure it's basically there
|
||||
// if (!string.IsNullOrWhiteSpace(inObj.ListView))
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// var v = JArray.Parse(inObj.ListView);
|
||||
// for (int i = 0; i < v.Count; i++)
|
||||
// {
|
||||
// var filterItem = v[i];
|
||||
// if (filterItem["fld"] == null)
|
||||
// AddError(ApiErrorCode.VALIDATION_REQUIRED, "ListView", $"ListView array item {i}, object is missing required \"fld\" property ");
|
||||
// else
|
||||
// {
|
||||
// var fld = filterItem["fld"].Value<string>();
|
||||
// if (string.IsNullOrWhiteSpace(fld))
|
||||
// AddError(ApiErrorCode.VALIDATION_REQUIRED, "ListView", $"ListView array item {i}, \"fld\" property is empty and required");
|
||||
|
||||
// //validate the field name if we can
|
||||
// if (DataList != null)
|
||||
// {
|
||||
|
||||
// var TheField = DataList.FieldDefinitions.SingleOrDefault(z => z.FieldKey.ToLowerInvariant() == fld.ToLowerInvariant());
|
||||
|
||||
// if (TheField == null)
|
||||
// {
|
||||
// AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "ListView", $"ListView array item {i}, fld property value \"{fld}\" is not a valid value for ListKey specified");
|
||||
// }
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// //NOTE: value of nothing, null or empty is a valid value so no checking for it here
|
||||
// }
|
||||
// }
|
||||
// catch (Newtonsoft.Json.JsonReaderException ex)
|
||||
// {
|
||||
// AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "ListView", "ListView is not valid JSON string: " + ex.Message);
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user