From a6b82eab2785e318d1d7bb1b063430abf456b70c Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 29 Nov 2018 15:50:22 +0000 Subject: [PATCH] --- devdocs/todo.txt | 4 +- server/AyaNova/biz/DataFilterBiz.cs | 86 ++++++----------------------- 2 files changed, 19 insertions(+), 71 deletions(-) diff --git a/devdocs/todo.txt b/devdocs/todo.txt index c525fe17..529ffb8d 100644 --- a/devdocs/todo.txt +++ b/devdocs/todo.txt @@ -76,7 +76,9 @@ INITIAL TESTING NOTES: - broken rule display - +SERVER + - WidgetBiz Create / CreateAsync share much the same code, move redundancies to common method + - This object will be replicated repeatedly so it always pays to clean it up more and more diff --git a/server/AyaNova/biz/DataFilterBiz.cs b/server/AyaNova/biz/DataFilterBiz.cs index 1e19ed90..80ddc4fd 100644 --- a/server/AyaNova/biz/DataFilterBiz.cs +++ b/server/AyaNova/biz/DataFilterBiz.cs @@ -1,5 +1,6 @@ using System.Linq; using System.Threading.Tasks; +using System.Collections.Generic; using Microsoft.EntityFrameworkCore; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.JsonPatch; @@ -61,13 +62,10 @@ namespace AyaNova.Biz return null; else { - //do stuff with widget + //do stuff with datafilter DataFilter outObj = inObj; outObj.OwnerId = UserId; - //Test get serial id visible id number from generator - outObj.Serial = ServerBootConfig.WIDGET_SERIAL.GetNext(); - await ct.DataFilter.AddAsync(outObj); await ct.SaveChangesAsync(); @@ -78,7 +76,7 @@ namespace AyaNova.Biz EventLogProcessor.LogEventToDatabase(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct); //SEARCH INDEXING - Search.ProcessNewObjectKeywords( UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.Notes, outObj.Name, outObj.Serial.ToString()); + Search.ProcessNewObjectKeywords(UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.Name); return outObj; @@ -94,11 +92,10 @@ namespace AyaNova.Biz return null; else { - //do stuff with widget + //do stuff with datafilter DataFilter outObj = inObj; outObj.OwnerId = UserId; - //Test get serial id visible id number from generator - outObj.Serial = ServerBootConfig.WIDGET_SERIAL.GetNext(); + TempContext.DataFilter.Add(outObj); TempContext.SaveChanges(); @@ -109,7 +106,7 @@ namespace AyaNova.Biz EventLogProcessor.LogEventToDatabase(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), TempContext); //SEARCH INDEXING - Search.ProcessNewObjectKeywords(UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.Notes, outObj.Name, outObj.Serial.ToString()); + Search.ProcessNewObjectKeywords(UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.Name); return outObj; @@ -153,51 +150,23 @@ namespace AyaNova.Biz } - //get picklist (paged) - internal async Task> GetPickListAsync(IUrlHelper Url, string routeName, PagingOptions pagingOptions, string q) + //get picklist (NOT PAGED) + internal async Task> GetPickListAsync(string listKey) { - pagingOptions.Offset = pagingOptions.Offset ?? PagingOptions.DefaultOffset; - pagingOptions.Limit = pagingOptions.Limit ?? PagingOptions.DefaultLimit; - - NameIdItem[] items; - int totalRecordCount = 0; - - if (!string.IsNullOrWhiteSpace(q)) + List items = new List(); + if (!string.IsNullOrWhiteSpace(listKey)) { items = await ct.DataFilter - .Where(m => EF.Functions.ILike(m.Name, q)) + .Where(m => m.ListKey == listKey && (m.Public == true || m.OwnerId == UserId)) .OrderBy(m => m.Name) - .Skip(pagingOptions.Offset.Value) - .Take(pagingOptions.Limit.Value) .Select(m => new NameIdItem() { Id = m.Id, Name = m.Name - }).ToArrayAsync(); + }).ToListAsync(); - totalRecordCount = await ct.DataFilter.Where(m => EF.Functions.ILike(m.Name, q)).CountAsync(); } - else - { - items = await ct.DataFilter - .OrderBy(m => m.Name) - .Skip(pagingOptions.Offset.Value) - .Take(pagingOptions.Limit.Value) - .Select(m => new NameIdItem() - { - Id = m.Id, - Name = m.Name - }).ToArrayAsync(); - - totalRecordCount = await ct.DataFilter.CountAsync(); - } - - - - var pageLinks = new PaginationLinkBuilder(Url, routeName, null, pagingOptions, totalRecordCount).PagingLinksObject(); - - ApiPagedResponse pr = new ApiPagedResponse(items, pageLinks); - return pr; + return items; } @@ -225,30 +194,7 @@ namespace AyaNova.Biz 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()); - - return true; - } - - //patch - internal bool Patch(DataFilter dbObj, JsonPatchDocument 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.Validate(this, objectPatch)) return false; - - //Do the patching - objectPatch.ApplyTo(dbObj); - 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()); + Search.ProcessUpdatedObjectKeywords(UserLocaleId, dbObj.Id, BizType, dbObj.Name, dbObj.Notes, dbObj.Name, dbObj.Serial.ToString()); return true; } @@ -294,10 +240,10 @@ namespace AyaNova.Biz //run validation and biz rules if (isNew) { - //NEW widgets must be active + //NEW datafilters must be active if (inObj.Active == null || ((bool)inObj.Active) == false) { - AddError(ValidationErrorType.InvalidValue, "Active", "New widget must be active"); + AddError(ValidationErrorType.InvalidValue, "Active", "New datafilter must be active"); } }