This commit is contained in:
@@ -9,6 +9,7 @@ using Microsoft.Extensions.Logging;
|
||||
using AyaNova.Models;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
using AyaNova.Biz;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
|
||||
namespace AyaNova.Api.Controllers
|
||||
@@ -177,6 +178,59 @@ namespace AyaNova.Api.Controllers
|
||||
return Accepted(new { JobId = j.GId });//202 accepted
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// EXTENSION BULK JOBS
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Bulk DELETE list of object id's specified
|
||||
/// </summary>
|
||||
/// <param name="dataListSelection"></param>
|
||||
/// <returns>Job Id</returns>
|
||||
[HttpPost("bulk-delete")]
|
||||
public async Task<IActionResult> BulkAdd([FromBody] DataListSelection dataListSelection)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
|
||||
if (dataListSelection.IsEmpty)
|
||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_REQUIRED, null, "DataListSelection is required"));
|
||||
|
||||
|
||||
if (!Authorized.HasDeleteRole(HttpContext.Items, dataListSelection.ObjectType))
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
|
||||
|
||||
await dataListSelection.RehydrateIdList(ct, UserRolesFromContext.Roles(HttpContext.Items), log);
|
||||
if (dataListSelection.SelectedRowIds.Length == 0)
|
||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_REQUIRED, null, "List of ids"));
|
||||
|
||||
var JobName = $"Bulk operation: DELETE on {dataListSelection.ObjectType} ({dataListSelection.SelectedRowIds.LongLength} specified)";
|
||||
JObject o = JObject.FromObject(new
|
||||
{
|
||||
idList = dataListSelection.SelectedRowIds
|
||||
});
|
||||
|
||||
OpsJob j = new OpsJob();
|
||||
j.Name = JobName;
|
||||
j.ObjectType = dataListSelection.ObjectType;
|
||||
j.JobType = JobType.BulkCoreBizObjectOperation;
|
||||
j.SubType = JobSubType.Delete;
|
||||
j.Exclusive = false;
|
||||
j.JobInfo = o.ToString();
|
||||
await JobsBiz.AddJobAsync(j);
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.ServerJob, AyaEvent.Created, JobName), ct);
|
||||
return Accepted(new { JobId = j.GId });
|
||||
}
|
||||
|
||||
|
||||
//------------
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user