This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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<ApiPagedResponse<NameIdItem>> GetPickListAsync(IUrlHelper Url, string routeName, PagingOptions pagingOptions, string q)
|
||||
//get picklist (NOT PAGED)
|
||||
internal async Task<List<NameIdItem>> 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<NameIdItem> items = new List<NameIdItem>();
|
||||
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<NameIdItem> pr = new ApiPagedResponse<NameIdItem>(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<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());
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user