This commit is contained in:
@@ -99,7 +99,40 @@ namespace AyaNova.Api.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// V7 Import replace log entry
|
||||||
|
/// (internal use only)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="inObj"></param>
|
||||||
|
/// <param name="apiVersion">Automatically filled from route path, no need to specify in body</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[ApiExplorerSettings(IgnoreApi = true)]
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<IActionResult> PostV7Modify([FromBody] V7Event inObj, ApiVersion apiVersion)
|
||||||
|
{
|
||||||
|
if (!serverState.IsOpen)
|
||||||
|
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||||
|
|
||||||
|
//Only biz admin full users can do this
|
||||||
|
if (!Authorized.HasAnyRole(HttpContext.Items, AuthorizationRoles.BizAdminFull))
|
||||||
|
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||||
|
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
|
|
||||||
|
await EventLogProcessor.V7_Modify_LogAsync(inObj, ct);
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
public sealed class V7Event
|
||||||
|
{
|
||||||
|
public AyaType AyType { get; set; }
|
||||||
|
public long AyId { get; set; }
|
||||||
|
public long Creator { get; set; }
|
||||||
|
public long Modifier { get; set; }
|
||||||
|
public DateTime Created { get; set; }
|
||||||
|
public DateTime Modified { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//------------
|
//------------
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using System.Linq;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using AyaNova.Models;
|
using AyaNova.Models;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
|
||||||
namespace AyaNova.Biz
|
namespace AyaNova.Biz
|
||||||
@@ -56,7 +57,7 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
//Set up the query
|
//Set up the query
|
||||||
var q = ct.Event.Select(m => m).Skip(offset).Take(limit).AsNoTracking();
|
var q = ct.Event.Select(m => m).Skip(offset).Take(limit).AsNoTracking();
|
||||||
q = q.Where(m => m.AyId == opt.AyId && m.AyType== opt.AyType);
|
q = q.Where(m => m.AyId == opt.AyId && m.AyType == opt.AyType);
|
||||||
q = q.OrderByDescending(m => m.Created);
|
q = q.OrderByDescending(m => m.Created);
|
||||||
q = q.Skip(offset).Take(limit);
|
q = q.Skip(offset).Take(limit);
|
||||||
|
|
||||||
@@ -123,6 +124,28 @@ namespace AyaNova.Biz
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// V7 import handler
|
||||||
|
/// Import needs to fixup event log CREATED entry to show original created and last modified times
|
||||||
|
/// and users
|
||||||
|
/// </summary>
|
||||||
|
internal static async Task V7_Modify_LogAsync(AyaNova.Api.Controllers.EventLogController.V7Event ev, AyContext ct)
|
||||||
|
{
|
||||||
|
//delete the automatically created entry from the import object
|
||||||
|
await ct.Database.ExecuteSqlInterpolatedAsync($"delete from aevent where aytype = {ev.AyType} and ayid={ev.AyId}");
|
||||||
|
|
||||||
|
//Now create the entries to reflect the original data from v7
|
||||||
|
//CREATED
|
||||||
|
await EventLogProcessor.LogEventToDatabaseAsync(new Event(ev.Creator, ev.AyId, ev.AyType, AyaEvent.Created, ev.Created, null), ct);
|
||||||
|
|
||||||
|
//MODIFIED
|
||||||
|
await EventLogProcessor.LogEventToDatabaseAsync(new Event(ev.Modifier,ev.AyId, ev.AyType, AyaEvent.Modified, ev.Modified, null), ct);
|
||||||
|
|
||||||
|
|
||||||
|
await ct.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user