This commit is contained in:
2020-01-22 15:49:04 +00:00
parent 5565424108
commit 7d3d9cfeee
3 changed files with 34 additions and 17 deletions

View File

@@ -57,6 +57,11 @@ namespace AyaNova.Api.Controllers
if (serverState.IsClosed)
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
//Attempt to get the data list by key to see if key is valid and for the default template and valid field names
var DataList = DataListFactory.GetAyaDataList(DataListKey);
if (DataList == null)
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
//Instantiate the business object handler
DataListTemplateBiz biz = DataListTemplateBiz.GetBiz(ct, HttpContext);
@@ -66,7 +71,7 @@ namespace AyaNova.Api.Controllers
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
var o = await biz.GetAsync(DataListKey);
var o = await biz.GetAsync(DataListKey, true, DataList);
if (o == null)
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
@@ -111,10 +116,15 @@ namespace AyaNova.Api.Controllers
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
//Attempt to get the data list by key to see if key is valid and for the default template and valid field names
var DataList = DataListFactory.GetAyaDataList(DataListKey);
if (DataList == null)
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
//Instantiate the business object handler
DataListTemplateBiz biz = DataListTemplateBiz.GetBiz(ct, HttpContext);
var o = await biz.GetNoLogAsync(DataListKey);
var o = await biz.GetAsync(DataListKey, false, DataList);
if (o == null)
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
@@ -123,7 +133,7 @@ namespace AyaNova.Api.Controllers
try
{
if (!biz.Put(o, inObj))
if (!biz.Put(o, inObj, DataList))
return BadRequest(new ApiErrorResponse(biz.Errors));
}
catch (DbUpdateConcurrencyException)
@@ -132,7 +142,7 @@ namespace AyaNova.Api.Controllers
// return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
// else
//these always exist so can only be concurrency conflict
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
}
return Ok(ApiOkResponse.Response(new { ConcurrencyToken = o.ConcurrencyToken }, true));
}
@@ -157,10 +167,15 @@ namespace AyaNova.Api.Controllers
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
//Attempt to get the data list by key to see if key is valid
var DataList = DataListFactory.GetAyaDataList(DataListKey);
if (DataList == null)
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
//Instantiate the business object handler
DataListTemplateBiz biz = DataListTemplateBiz.GetBiz(ct, HttpContext);
var o = await biz.GetNoLogAsync(DataListKey);
var o = await biz.GetAsync(DataListKey, false, DataList);
if (o == null)
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));

View File

@@ -10,6 +10,7 @@ namespace AyaNova.DataList
//Instantiate list object specified
//this is safe as it's only attempting to load assemblies in the AyaNova.DataList namespace so can't attempt to instantiate some random object or nefarious object
//returns null if doesn't exist
internal static IAyaDataList GetAyaDataList(string ListKey)
{
System.Reflection.Assembly ass = System.Reflection.Assembly.GetEntryAssembly();

View File

@@ -109,26 +109,27 @@ namespace AyaNova.Biz
/// GET
//Get one
internal async Task<DataListTemplate> GetAsync(string DataListKey, bool log=true)
internal async Task<DataListTemplate> GetAsync(string DataListKey, bool log, IAyaDataList dataList)
{
//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));
if (ret != null)
//DataListKey always exists, if not in db then in default form
var ret = await ct.DataListTemplate.SingleOrDefaultAsync(m => m.DataListKey == DataListKey);
if (log)
{
//Log
EventLogProcessor.LogEventToDatabase(new Event(UserId, fetchId, BizType, AyaEvent.Retrieved), ct);
EventLogProcessor.LogEventToDatabase(new Event(UserId, ret.Id, BizType, AyaEvent.Retrieved), ct);
}
return ret;
}
////////////////////////////////////////////////////////////////////////////////////////////////
/// 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);
}
// ////////////////////////////////////////////////////////////////////////////////////////////////
// /// 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);
// }
// //get picklist (NOT PAGED)
// internal async Task<List<NameIdItem>> GetPickListAsync(string listKey)