This commit is contained in:
2018-12-14 18:57:55 +00:00
parent 45ec20954d
commit 0da38fb1db
3 changed files with 122 additions and 138 deletions

View File

@@ -5,11 +5,6 @@ Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOiIxNTQ0NTU5NzAwIiwiZXhwIjoi
## IMMEDIATE ITEMS
ENUM
- make tests then done
NEXT
- This should be the point that the lists code is concluded and can move on to the other SERVER items below then back to client stuff in the middle here
-----------------------

View File

@@ -337,7 +337,7 @@ namespace AyaNova.Biz
// Search.ProcessUpdatedObjectKeywords(UserLocaleId, dbObj.Id, BizType, dbObj.Name, dbObj.EmployeeNumber, dbObj.Notes, dbObj.Name);
var SearchParams = new Search.SearchIndexProcessObjectParameters(UserLocaleId, dbObj.Id, BizType, dbObj.Name);
SearchParams.AddWord(dbObj.Notes).AddWord(dbObj.Name).AddWord(dbObj.EmployeeNumber).AddWord(dbObj.Tags);
Search.ProcessNewObjectKeywords(SearchParams);
Search.ProcessUpdatedObjectKeywords(SearchParams);
return true;
}
@@ -375,7 +375,7 @@ namespace AyaNova.Biz
// Search.ProcessUpdatedObjectKeywords(UserLocaleId, dbObj.Id, BizType, dbObj.Name, dbObj.EmployeeNumber, dbObj.Notes, dbObj.Name);
var SearchParams = new Search.SearchIndexProcessObjectParameters(UserLocaleId, dbObj.Id, BizType, dbObj.Name);
SearchParams.AddWord(dbObj.Notes).AddWord(dbObj.Name).AddWord(dbObj.EmployeeNumber).AddWord(dbObj.Tags);
Search.ProcessNewObjectKeywords(SearchParams);
Search.ProcessUpdatedObjectKeywords(SearchParams);
return true;
}

View File

@@ -46,15 +46,36 @@ namespace AyaNova.Biz
}
////////////////////////////////////////////////////////////////////////////////////////////////
/// GET
/// GET
///
///
//Get without logging
internal async Task<Widget> GetNoLogAsync(long fetchId)
{
//This is simple so nothing more here, but often will be copying to a different output object or some other ops
return await ct.Widget.SingleOrDefaultAsync(m => m.Id == fetchId);
}
//Get one with logging
internal async Task<Widget> 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.Widget.SingleOrDefaultAsync(m => m.Id == fetchId);
if (ret != null)
{
//Log
EventLogProcessor.LogEventToDatabase(new Event(UserId, fetchId, BizType, AyaEvent.Retrieved), ct);
}
return ret;
}
////////////////////////////////////////////////////////////////////////////////////////////////
//CREATE
//CREATE
//route linked version for external api access
internal async Task<Widget> CreateAsync(Widget inObj)
{
Validate(inObj, true);
@@ -74,23 +95,16 @@ namespace AyaNova.Biz
await ct.Widget.AddAsync(outObj);
await ct.SaveChangesAsync();
//Handle child and associated items:
//EVENT LOG
//Handle child and associated items:
EventLogProcessor.LogEventToDatabase(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
//SEARCH INDEXING
var SearchParams = new Search.SearchIndexProcessObjectParameters(UserLocaleId, outObj.Id, BizType, outObj.Name);
SearchParams.AddWord(outObj.Notes).AddWord(outObj.Name).AddWord(outObj.Serial).AddWord(outObj.Tags);
Search.ProcessNewObjectKeywords(SearchParams);
SearchIndex(outObj, true);
return outObj;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
//CREATE
//Internal version for seeding
internal Widget Create(AyContext TempContext, Widget inObj)
{
Validate(inObj, true);
@@ -109,37 +123,111 @@ namespace AyaNova.Biz
TempContext.SaveChanges();
//Handle child and associated items:
//EVENT LOG
EventLogProcessor.LogEventToDatabase(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), TempContext);
//SEARCH INDEXING
var SearchParams = new Search.SearchIndexProcessObjectParameters(UserLocaleId, outObj.Id, BizType, outObj.Name);
SearchParams.AddWord(outObj.Notes).AddWord(outObj.Name).AddWord(outObj.Serial).AddWord(outObj.Tags);
Search.ProcessNewObjectKeywords(SearchParams);
SearchIndex(outObj, true);
return outObj;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
/// GET
//UPDATE
//
//Get one
internal async Task<Widget> GetAsync(long fetchId)
//put
internal bool Put(Widget dbObj, Widget inObj)
{
//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.Widget.SingleOrDefaultAsync(m => m.Id == fetchId);
if (ret != null)
{
//Log
EventLogProcessor.LogEventToDatabase(new Event(UserId, fetchId, BizType, AyaEvent.Retrieved), ct);
}
return ret;
//preserve the owner ID if none was specified
if (inObj.OwnerId == 0)
inObj.OwnerId = dbObj.OwnerId;
//Replace the db object with the PUT object
CopyObject.Copy(inObj, dbObj, "Id,Serial");
dbObj.Tags = TagUtil.NormalizeTags(dbObj.Tags);
//Set "original" value of concurrency token to input token
//this will allow EF to check it out
ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = inObj.ConcurrencyToken;
Validate(dbObj, false);
if (HasErrors)
return false;
//Associated items
EventLogProcessor.LogEventToDatabase(new Event(UserId, dbObj.Id, BizType, AyaEvent.Modified), ct);
SearchIndex(dbObj, false);
return true;
}
//patch
internal bool Patch(Widget dbObj, JsonPatchDocument<Widget> objectPatch, uint concurrencyToken)
{
//Validate Patch is allowed
//Note: Id, OwnerId and Serial are all checked for and disallowed in the validate code by default
if (!ValidateJsonPatch<Widget>.Validate(this, objectPatch)) return false;
//Do the patching
objectPatch.ApplyTo(dbObj);
dbObj.Tags = TagUtil.NormalizeTags(dbObj.Tags);
ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = concurrencyToken;
Validate(dbObj, false);
if (HasErrors)
return false;
//Associated items
EventLogProcessor.LogEventToDatabase(new Event(UserId, dbObj.Id, BizType, AyaEvent.Modified), ct);
SearchIndex(dbObj, false);
return true;
}
private void SearchIndex(Widget obj, bool isNew)
{
//SEARCH INDEXING
var SearchParams = new Search.SearchIndexProcessObjectParameters(UserLocaleId, obj.Id, BizType, obj.Name);
SearchParams.AddWord(obj.Notes).AddWord(obj.Name).AddWord(obj.Serial).AddWord(obj.Tags);
if (isNew)
Search.ProcessNewObjectKeywords(SearchParams);
else
Search.ProcessUpdatedObjectKeywords(SearchParams);
}
////////////////////////////////////////////////////////////////////////////////////////////////
//DELETE
//
internal bool Delete(Widget dbObj)
{
//Determine if the object can be deleted, do the deletion tentatively
//Probably also in here deal with tags and associated search text etc
ValidateCanDelete(dbObj);
if (HasErrors)
return false;
ct.Widget.Remove(dbObj);
ct.SaveChanges();
//Associated items
EventLogProcessor.DeleteObject(UserId, BizType, dbObj.Id, dbObj.Name, ct);
ct.SaveChanges();
Search.ProcessDeletedObjectKeywords(dbObj.Id, BizType);
return true;
}
////////////////////////////////////////////////////////////////////////////////////////////////
// LISTS
//
public static FilterOptions FilterOptions(long localizeToLocaleId = 0)
{
@@ -213,9 +301,6 @@ namespace AyaNova.Biz
}
/// <summary>
/// Get PickList
/// </summary>
@@ -236,102 +321,6 @@ namespace AyaNova.Biz
////////////////////////////////////////////////////////////////////////////////////////////////
//UPDATE
//
//put
internal bool Put(Widget dbObj, Widget inObj)
{
//preserve the owner ID if none was specified
if (inObj.OwnerId == 0)
inObj.OwnerId = dbObj.OwnerId;
//Replace the db object with the PUT object
CopyObject.Copy(inObj, dbObj, "Id,Serial");
dbObj.Tags = TagUtil.NormalizeTags(dbObj.Tags);
//Set "original" value of concurrency token to input token
//this will allow EF to check it out
ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = inObj.ConcurrencyToken;
Validate(dbObj, false);
if (HasErrors)
return false;
//Log modification
EventLogProcessor.LogEventToDatabase(new Event(UserId, dbObj.Id, BizType, AyaEvent.Modified), ct);
//Update keywords
// Search.ProcessUpdatedObjectKeywords(UserLocaleId, dbObj.Id, BizType, dbObj.Name, dbObj.Notes, dbObj.Name, dbObj.Serial.ToString());
var SearchParams = new Search.SearchIndexProcessObjectParameters(UserLocaleId, dbObj.Id, BizType, dbObj.Name);
SearchParams.AddWord(dbObj.Notes).AddWord(dbObj.Name).AddWord(dbObj.Serial).AddWord(dbObj.Tags);
Search.ProcessNewObjectKeywords(SearchParams);
return true;
}
//patch
internal bool Patch(Widget dbObj, JsonPatchDocument<Widget> objectPatch, uint concurrencyToken)
{
//Validate Patch is allowed
//Note: Id, OwnerId and Serial are all checked for and disallowed in the validate code by default
if (!ValidateJsonPatch<Widget>.Validate(this, objectPatch)) return false;
//Do the patching
objectPatch.ApplyTo(dbObj);
dbObj.Tags = TagUtil.NormalizeTags(dbObj.Tags);
ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = concurrencyToken;
Validate(dbObj, false);
if (HasErrors)
return false;
//Log modification
EventLogProcessor.LogEventToDatabase(new Event(UserId, dbObj.Id, BizType, AyaEvent.Modified), ct);
//Update keywords
//Search.ProcessUpdatedObjectKeywords(UserLocaleId, dbObj.Id, BizType, dbObj.Name, dbObj.Notes, dbObj.Name, dbObj.Serial.ToString());
var SearchParams = new Search.SearchIndexProcessObjectParameters(UserLocaleId, dbObj.Id, BizType, dbObj.Name);
SearchParams.AddWord(dbObj.Notes).AddWord(dbObj.Name).AddWord(dbObj.Serial).AddWord(dbObj.Tags);
Search.ProcessNewObjectKeywords(SearchParams);
return true;
}
////////////////////////////////////////////////////////////////////////////////////////////////
//DELETE
//
internal bool Delete(Widget dbObj)
{
//Determine if the object can be deleted, do the deletion tentatively
//Probably also in here deal with tags and associated search text etc
ValidateCanDelete(dbObj);
if (HasErrors)
return false;
ct.Widget.Remove(dbObj);
ct.SaveChanges();
//Delete sibling objects
//Event log process delete
EventLogProcessor.DeleteObject(UserId, BizType, dbObj.Id, dbObj.Name, ct);
ct.SaveChanges();
//Delete search index
Search.ProcessDeletedObjectKeywords(dbObj.Id, BizType);
// //TAGS
// TagMapBiz.DeleteAllForObject(new AyaTypeId(BizType, dbObj.Id), ct);
// ct.SaveChanges();
return true;
}
////////////////////////////////////////////////////////////////////////////////////////////////
//VALIDATION