This commit is contained in:
@@ -38,7 +38,7 @@ AUTOCOMPLETE
|
||||
- PUT PickList/Template (body AyaType, body viewJson)
|
||||
- Update a view to use a new default
|
||||
- updates cache when it updates db as well
|
||||
- POST PickList/TemplateReset(AyaType)
|
||||
- DELETE PickList/Template (AyaType)
|
||||
- for ui, resets the view back to it's default
|
||||
- GET PickList/Template (AyaType)
|
||||
- for ui picklistvieweditor to populate ui with current template (or default if not edited)
|
||||
|
||||
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using AyaNova.Models;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
using AyaNova.Biz;
|
||||
@@ -55,7 +56,7 @@ namespace AyaNova.Api.Controllers
|
||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||
}
|
||||
|
||||
//Instantiate the business object handler
|
||||
//Instantiate the business object handler
|
||||
PickListBiz biz = PickListBiz.GetBiz(ct, HttpContext);
|
||||
|
||||
// //NOTE: This is the first check and often the only check but in some cases with some objects this will also need to check biz object rules
|
||||
@@ -65,7 +66,7 @@ namespace AyaNova.Api.Controllers
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
|
||||
var o = await biz.GetPickListAsync(ayaType,query);
|
||||
var o = await biz.GetPickListAsync(ayaType, query);
|
||||
if (o == null)
|
||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
|
||||
@@ -90,27 +91,81 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// List of all fields for data list key specified
|
||||
/// </summary>
|
||||
/// <returns>List of PickListFieldDefinition</returns>
|
||||
[HttpGet("ListFields")]
|
||||
public ActionResult GetPickListFields([FromQuery] string PickListKey)
|
||||
/// POST (replace) Pick List template
|
||||
/// </summary>
|
||||
/// <param name="aytype"></param>
|
||||
/// <param name="template"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("Template/{ayatype}")]
|
||||
public async Task<IActionResult> ReplacePickListTemplate([FromRoute] AyaType ayaType, [FromBody] string template)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
{
|
||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||
}
|
||||
|
||||
var PickList = PickListFactory.GetAyaPickList(PickListKey);
|
||||
//was the name not found as a list?
|
||||
if (PickList == null)
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
|
||||
//Instantiate the business object handler
|
||||
PickListBiz biz = PickListBiz.GetBiz(ct, HttpContext);
|
||||
|
||||
// var o = await biz.GetAsync(ayaType, false);
|
||||
// if (o == null)
|
||||
// return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
|
||||
if (!Authorized.HasModifyRole(HttpContext.Items, biz.BizType))
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
|
||||
try
|
||||
{
|
||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.NOT_FOUND, "PickListKey", $"PickList \"{PickListKey}\" specified does not exist"));
|
||||
if (!await biz.ReplaceAsync(ayaType, template))
|
||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
|
||||
return Ok(ApiOkResponse.Response(PickList.FieldDefinitions, true));
|
||||
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
|
||||
}
|
||||
return Ok(ApiOkResponse.Response(new { ConcurrencyToken = o.ConcurrencyToken }, true));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Delete customized template
|
||||
/// (revert to default)
|
||||
/// </summary>
|
||||
/// <param name="ayatype"></param>
|
||||
/// <returns>Ok</returns>
|
||||
[HttpDelete("Template/{ayatype}")]
|
||||
public async Task<IActionResult> DeletePickListTemplate([FromRoute] AyaType ayatype)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
|
||||
//Instantiate the business object handler
|
||||
PickListBiz biz = PickListBiz.GetBiz(ct, HttpContext);
|
||||
|
||||
|
||||
if (!Authorized.HasDeleteRole(HttpContext.Items, biz.BizType))
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
|
||||
if (!await biz.DeleteAsync(o))
|
||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}//eoc
|
||||
}//ens
|
||||
@@ -27,7 +27,7 @@ namespace AyaNova.Biz
|
||||
ServerState = 4,
|
||||
License = 5,
|
||||
LogFile = 6,
|
||||
DEPRECATED_REUSELATER_7 = 7,
|
||||
PickListTemplate = 7,
|
||||
DEPRECATED_REUSELATER_8 = 8,
|
||||
JobOperations = 9,
|
||||
AyaNova7Import = 10,
|
||||
|
||||
@@ -155,6 +155,15 @@ namespace AyaNova.Biz
|
||||
ReadFullRecord = AuthorizationRoles.All
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//PICKLISTTEMPLATE
|
||||
//
|
||||
roles.Add(AyaType.PickListTemplate, new BizRoleSet()
|
||||
{
|
||||
Change = AuthorizationRoles.BizAdminFull,
|
||||
ReadFullRecord = AuthorizationRoles.All
|
||||
});
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
#endregion all roles init
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace AyaNova.Biz
|
||||
UserId = currentUserId;
|
||||
UserTranslationId = userTranslationId;
|
||||
CurrentUserRoles = UserRoles;
|
||||
BizType = AyaType.DataListView;
|
||||
BizType = AyaType.PickListTemplate;
|
||||
}
|
||||
|
||||
internal static PickListBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext = null)
|
||||
@@ -34,81 +34,7 @@ namespace AyaNova.Biz
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// //EXISTS
|
||||
// internal async Task<bool> ExistsAsync(long id)
|
||||
// {
|
||||
// return await ct.DataListView.AnyAsync(e => e.Id == id);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// //CREATE
|
||||
// internal async Task<DataListView> CreateAsync(DataListView inObj)
|
||||
// {
|
||||
// await ValidateAsync(inObj, true);
|
||||
// if (HasErrors)
|
||||
// return null;
|
||||
// else
|
||||
// {
|
||||
// //do stuff with datafilter
|
||||
// DataListView outObj = inObj;
|
||||
// outObj.UserId = UserId;
|
||||
|
||||
|
||||
// await ct.DataListView.AddAsync(outObj);
|
||||
// await ct.SaveChangesAsync();
|
||||
|
||||
// //Handle child and associated items:
|
||||
|
||||
// //EVENT LOG
|
||||
// await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
|
||||
|
||||
|
||||
|
||||
// return outObj;
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// //DUPLICATE
|
||||
// //
|
||||
|
||||
// internal async Task<DataListView> DuplicateAsync(DataListView dbObj)
|
||||
// {
|
||||
|
||||
// DataListView outObj = new DataListView();
|
||||
// CopyObject.Copy(dbObj, outObj);
|
||||
// //generate unique name
|
||||
// string newUniqueName = string.Empty;
|
||||
// bool NotUnique = true;
|
||||
// long l = 1;
|
||||
// do
|
||||
// {
|
||||
// newUniqueName = Util.StringUtil.UniqueNameBuilder(dbObj.Name, l++, 255);
|
||||
// NotUnique = await ct.DataListView.AnyAsync(m => m.Name == newUniqueName);
|
||||
// } while (NotUnique);
|
||||
// outObj.Name = newUniqueName;
|
||||
// outObj.Id = 0;
|
||||
// outObj.ConcurrencyToken = 0;
|
||||
|
||||
|
||||
|
||||
// await ct.DataListView.AddAsync(outObj);
|
||||
// await ct.SaveChangesAsync();
|
||||
|
||||
// //Handle child and associated items:
|
||||
// await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
|
||||
|
||||
// return outObj;
|
||||
|
||||
// }
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// GET
|
||||
@@ -184,34 +110,34 @@ namespace AyaNova.Biz
|
||||
}
|
||||
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// //DELETE
|
||||
// //
|
||||
// internal async Task<bool> DeleteAsync(DataListView dbObj)
|
||||
// {
|
||||
// //Determine if the object can be deleted, do the deletion tentatively
|
||||
// //Probably also in here deal with tags and associated search text etc
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//DELETE
|
||||
//
|
||||
internal async Task<bool> DeleteAsync(DataListView dbObj)
|
||||
{
|
||||
//Determine if the object can be deleted, do the deletion tentatively
|
||||
//Probably also in here deal with tags and associated search text etc
|
||||
|
||||
// //FUTURE POSSIBLE NEED
|
||||
// //ValidateCanDelete(dbObj);
|
||||
//FUTURE POSSIBLE NEED
|
||||
//ValidateCanDelete(dbObj);
|
||||
|
||||
// if (HasErrors)
|
||||
// return false;
|
||||
// ct.DataListView.Remove(dbObj);
|
||||
// await ct.SaveChangesAsync();
|
||||
if (HasErrors)
|
||||
return false;
|
||||
ct.DataListView.Remove(dbObj);
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
// //Delete sibling objects
|
||||
//Delete sibling objects
|
||||
|
||||
// //Event log process delete
|
||||
// await EventLogProcessor.DeleteObjectLogAsync(UserId, BizType, dbObj.Id, dbObj.Name, ct);
|
||||
//Event log process delete
|
||||
await EventLogProcessor.DeleteObjectLogAsync(UserId, BizType, dbObj.Id, dbObj.Name, ct);
|
||||
|
||||
|
||||
// //Delete search index
|
||||
// //Search.ProcessDeletedObjectKeywords(dbObj.Id, BizType);
|
||||
//Delete search index
|
||||
//Search.ProcessDeletedObjectKeywords(dbObj.Id, BizType);
|
||||
|
||||
|
||||
// return true;
|
||||
// }
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//VALIDATION
|
||||
|
||||
Reference in New Issue
Block a user