This commit is contained in:
@@ -76,7 +76,9 @@ INITIAL TESTING NOTES:
|
|||||||
- broken rule display
|
- 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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Collections.Generic;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.JsonPatch;
|
using Microsoft.AspNetCore.JsonPatch;
|
||||||
@@ -61,13 +62,10 @@ namespace AyaNova.Biz
|
|||||||
return null;
|
return null;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//do stuff with widget
|
//do stuff with datafilter
|
||||||
DataFilter outObj = inObj;
|
DataFilter outObj = inObj;
|
||||||
outObj.OwnerId = UserId;
|
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.DataFilter.AddAsync(outObj);
|
||||||
await ct.SaveChangesAsync();
|
await ct.SaveChangesAsync();
|
||||||
@@ -78,7 +76,7 @@ namespace AyaNova.Biz
|
|||||||
EventLogProcessor.LogEventToDatabase(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
|
EventLogProcessor.LogEventToDatabase(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
|
||||||
|
|
||||||
//SEARCH INDEXING
|
//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;
|
return outObj;
|
||||||
|
|
||||||
@@ -94,11 +92,10 @@ namespace AyaNova.Biz
|
|||||||
return null;
|
return null;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//do stuff with widget
|
//do stuff with datafilter
|
||||||
DataFilter outObj = inObj;
|
DataFilter outObj = inObj;
|
||||||
outObj.OwnerId = UserId;
|
outObj.OwnerId = UserId;
|
||||||
//Test get serial id visible id number from generator
|
|
||||||
outObj.Serial = ServerBootConfig.WIDGET_SERIAL.GetNext();
|
|
||||||
|
|
||||||
TempContext.DataFilter.Add(outObj);
|
TempContext.DataFilter.Add(outObj);
|
||||||
TempContext.SaveChanges();
|
TempContext.SaveChanges();
|
||||||
@@ -109,7 +106,7 @@ namespace AyaNova.Biz
|
|||||||
EventLogProcessor.LogEventToDatabase(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), TempContext);
|
EventLogProcessor.LogEventToDatabase(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), TempContext);
|
||||||
|
|
||||||
//SEARCH INDEXING
|
//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;
|
return outObj;
|
||||||
|
|
||||||
@@ -153,51 +150,23 @@ namespace AyaNova.Biz
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//get picklist (paged)
|
//get picklist (NOT PAGED)
|
||||||
internal async Task<ApiPagedResponse<NameIdItem>> GetPickListAsync(IUrlHelper Url, string routeName, PagingOptions pagingOptions, string q)
|
internal async Task<List<NameIdItem>> GetPickListAsync(string listKey)
|
||||||
{
|
{
|
||||||
pagingOptions.Offset = pagingOptions.Offset ?? PagingOptions.DefaultOffset;
|
List<NameIdItem> items = new List<NameIdItem>();
|
||||||
pagingOptions.Limit = pagingOptions.Limit ?? PagingOptions.DefaultLimit;
|
if (!string.IsNullOrWhiteSpace(listKey))
|
||||||
|
|
||||||
NameIdItem[] items;
|
|
||||||
int totalRecordCount = 0;
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(q))
|
|
||||||
{
|
{
|
||||||
items = await ct.DataFilter
|
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)
|
.OrderBy(m => m.Name)
|
||||||
.Skip(pagingOptions.Offset.Value)
|
|
||||||
.Take(pagingOptions.Limit.Value)
|
|
||||||
.Select(m => new NameIdItem()
|
.Select(m => new NameIdItem()
|
||||||
{
|
{
|
||||||
Id = m.Id,
|
Id = m.Id,
|
||||||
Name = m.Name
|
Name = m.Name
|
||||||
}).ToArrayAsync();
|
}).ToListAsync();
|
||||||
|
|
||||||
totalRecordCount = await ct.DataFilter.Where(m => EF.Functions.ILike(m.Name, q)).CountAsync();
|
|
||||||
}
|
}
|
||||||
else
|
return items;
|
||||||
{
|
|
||||||
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<NameIdItem> pr = new ApiPagedResponse<NameIdItem>(items, pageLinks);
|
|
||||||
return pr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -225,30 +194,7 @@ namespace AyaNova.Biz
|
|||||||
EventLogProcessor.LogEventToDatabase(new Event(UserId, dbObj.Id, BizType, AyaEvent.Modified), ct);
|
EventLogProcessor.LogEventToDatabase(new Event(UserId, dbObj.Id, BizType, AyaEvent.Modified), ct);
|
||||||
|
|
||||||
//Update keywords
|
//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;
|
|
||||||
}
|
|
||||||
|
|
||||||
//patch
|
|
||||||
internal bool Patch(DataFilter dbObj, JsonPatchDocument<DataFilter> 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<DataFilter>.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());
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -294,10 +240,10 @@ namespace AyaNova.Biz
|
|||||||
//run validation and biz rules
|
//run validation and biz rules
|
||||||
if (isNew)
|
if (isNew)
|
||||||
{
|
{
|
||||||
//NEW widgets must be active
|
//NEW datafilters must be active
|
||||||
if (inObj.Active == null || ((bool)inObj.Active) == false)
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user