This commit is contained in:
2020-01-22 15:36:11 +00:00
parent 6a2b5bdea2
commit 5565424108
2 changed files with 85 additions and 83 deletions

View File

@@ -35,7 +35,7 @@ TEST CHANGES
- New routes for lists - New routes for lists
TODO: REFACTOR GetNoLogAsync function is used in many places redundantly when the logging version could do the same thing but not log it with an optional bool switch so refactor that shit

View File

@@ -36,86 +36,80 @@ namespace AyaNova.Biz
return new DataListTemplateBiz(ct, 1, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, AuthorizationRoles.BizAdminFull); return new DataListTemplateBiz(ct, 1, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, AuthorizationRoles.BizAdminFull);
} }
//////////////////////////////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////////////////////////////
//EXISTS // //EXISTS
internal async Task<bool> ExistsAsync(long id) // internal async Task<bool> ExistsAsync(long id)
{ // {
return await ct.DataListTemplate.AnyAsync(e => e.Id == id); // return await ct.DataListTemplate.AnyAsync(e => e.Id == id);
} // }
////////////////////////////////////////////////////////////////////////////////////////////////
/// GET
internal async Task<DataListTemplate> 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.DataListTemplate.SingleOrDefaultAsync(m => m.Id == fetchId);
}
////////////////////////////////////////////////////////////////////////////////////////////////
//CREATE
internal async Task<DataListTemplate> CreateAsync(DataListTemplate inObj)
{
Validate(inObj, true);
if (HasErrors)
return null;
else
{
//do stuff with datafilter
DataListTemplate outObj = inObj;
outObj.UserId = UserId;
await ct.DataListTemplate.AddAsync(outObj);
await ct.SaveChangesAsync();
//Handle child and associated items: // ////////////////////////////////////////////////////////////////////////////////////////////////
// //CREATE
//EVENT LOG // internal async Task<DataListTemplate> CreateAsync(DataListTemplate inObj)
EventLogProcessor.LogEventToDatabase(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct); // {
// Validate(inObj, true);
//SEARCH INDEXING // if (HasErrors)
// Search.ProcessNewObjectKeywords(UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.Name); // return null;
// else
return outObj; // {
// //do stuff with datafilter
} // DataListTemplate outObj = inObj;
} // outObj.UserId = UserId;
////////////////////////////////////////////////////////////////////////////////////////////////
//CREATE
internal DataListTemplate Create(AyContext TempContext, DataListTemplate inObj)
{
Validate(inObj, true);
if (HasErrors)
return null;
else
{
//do stuff with datafilter
DataListTemplate outObj = inObj;
outObj.UserId = UserId;
TempContext.DataListTemplate.Add(outObj); // await ct.DataListTemplate.AddAsync(outObj);
TempContext.SaveChanges(); // await ct.SaveChangesAsync();
//Handle child and associated items: // //Handle child and associated items:
//EVENT LOG // //EVENT LOG
EventLogProcessor.LogEventToDatabase(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), TempContext); // EventLogProcessor.LogEventToDatabase(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
//SEARCH INDEXING // //SEARCH INDEXING
// Search.ProcessNewObjectKeywords(UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.Name); // // Search.ProcessNewObjectKeywords(UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.Name);
return outObj; // return outObj;
} // }
} // }
// ////////////////////////////////////////////////////////////////////////////////////////////////
// //CREATE
// internal DataListTemplate Create(AyContext TempContext, DataListTemplate inObj)
// {
// Validate(inObj, true);
// if (HasErrors)
// return null;
// else
// {
// //do stuff with datafilter
// DataListTemplate outObj = inObj;
// outObj.UserId = UserId;
// TempContext.DataListTemplate.Add(outObj);
// TempContext.SaveChanges();
// //Handle child and associated items:
// //EVENT LOG
// EventLogProcessor.LogEventToDatabase(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), TempContext);
// //SEARCH INDEXING
// // Search.ProcessNewObjectKeywords(UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.Name);
// return outObj;
// }
// }
//////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
/// GET /// GET
//Get one //Get one
internal async Task<DataListTemplate> GetAsync(long fetchId) internal async Task<DataListTemplate> GetAsync(string DataListKey, bool log=true)
{ {
//This is simple so nothing more here, but often will be copying to a different output object or some other ops //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.DataListTemplate.SingleOrDefaultAsync(m => m.Id == fetchId && (m.Public == true || m.UserId == UserId)); var ret = await ct.DataListTemplate.SingleOrDefaultAsync(m => m.Id == fetchId && (m.Public == true || m.UserId == UserId));
@@ -128,26 +122,34 @@ namespace AyaNova.Biz
} }
//get picklist (NOT PAGED) ////////////////////////////////////////////////////////////////////////////////////////////////
internal async Task<List<NameIdItem>> GetPickListAsync(string listKey) /// GET
internal async Task<DataListTemplate> GetNoLogAsync(long fetchId)
{ {
List<NameIdItem> items = new List<NameIdItem>(); //This is simple so nothing more here, but often will be copying to a different output object or some other ops
if (!string.IsNullOrWhiteSpace(listKey)) return await ct.DataListTemplate.SingleOrDefaultAsync(m => m.Id == fetchId);
{
items = await ct.DataListTemplate
.AsNoTracking()
.Where(m => m.ListKey == listKey && (m.Public == true || m.UserId == UserId))
.OrderBy(m => m.Name)
.Select(m => new NameIdItem()
{
Id = m.Id,
Name = m.Name
}).ToListAsync();
}
return items;
} }
// //get picklist (NOT PAGED)
// internal async Task<List<NameIdItem>> GetPickListAsync(string listKey)
// {
// List<NameIdItem> items = new List<NameIdItem>();
// if (!string.IsNullOrWhiteSpace(listKey))
// {
// items = await ct.DataListTemplate
// .AsNoTracking()
// .Where(m => m.ListKey == listKey && (m.Public == true || m.UserId == UserId))
// .OrderBy(m => m.Name)
// .Select(m => new NameIdItem()
// {
// Id = m.Id,
// Name = m.Name
// }).ToListAsync();
// }
// return items;
// }