This commit is contained in:
@@ -20,6 +20,10 @@ CODING WORK
|
||||
|
||||
Overall plan for now: anything standing in the way of making the initial client shell UI needs to be done first, everything else can wait
|
||||
- Audit log
|
||||
- CRUD methods for widget
|
||||
- replicate crud to other objects
|
||||
- Route for retrieving as log format for reading (like reports: one for specific object id and type, one for user id as log of what they've been doing etc)
|
||||
- Test with huge dataset
|
||||
- Localized text
|
||||
- Search and search text indexing
|
||||
- Auto visible id number assigning code
|
||||
|
||||
@@ -85,6 +85,9 @@ namespace AyaNova.Api.Controllers
|
||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
}
|
||||
|
||||
//Log
|
||||
EventLogProcessor.AddEntry(new Event(biz.userId, o.Id, AyaType.Widget, AyaEvent.Retrieved), ct);
|
||||
|
||||
return Ok(new ApiOkResponse(o));
|
||||
}
|
||||
|
||||
@@ -191,14 +194,14 @@ namespace AyaNova.Api.Controllers
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
}
|
||||
|
||||
var oFromDb = await ct.Widget.SingleOrDefaultAsync(m => m.Id == id);
|
||||
var o = await ct.Widget.SingleOrDefaultAsync(m => m.Id == id);
|
||||
|
||||
if (oFromDb == null)
|
||||
if (o == null)
|
||||
{
|
||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
}
|
||||
|
||||
if (!Authorized.IsAuthorizedToModify(HttpContext.Items, AyaType.Widget, oFromDb.OwnerId))
|
||||
if (!Authorized.IsAuthorizedToModify(HttpContext.Items, AyaType.Widget, o.OwnerId))
|
||||
{
|
||||
return StatusCode(401, new ApiNotAuthorizedResponse());
|
||||
}
|
||||
@@ -206,7 +209,7 @@ namespace AyaNova.Api.Controllers
|
||||
//Instantiate the business object handler
|
||||
WidgetBiz biz = new WidgetBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
||||
|
||||
if (!biz.Put(oFromDb, inObj))
|
||||
if (!biz.Put(o, inObj))
|
||||
{
|
||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
}
|
||||
@@ -230,7 +233,10 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(new ApiOkResponse(new { ConcurrencyToken = oFromDb.ConcurrencyToken }));
|
||||
//Log
|
||||
EventLogProcessor.AddEntry(new Event(biz.userId, o.Id, AyaType.Widget, AyaEvent.Modified), ct);
|
||||
|
||||
return Ok(new ApiOkResponse(new { ConcurrencyToken = o.ConcurrencyToken }));
|
||||
}
|
||||
|
||||
|
||||
@@ -265,20 +271,20 @@ namespace AyaNova.Api.Controllers
|
||||
WidgetBiz biz = new WidgetBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
||||
|
||||
|
||||
var oFromDb = await ct.Widget.SingleOrDefaultAsync(m => m.Id == id);
|
||||
var o = await ct.Widget.SingleOrDefaultAsync(m => m.Id == id);
|
||||
|
||||
if (oFromDb == null)
|
||||
if (o == null)
|
||||
{
|
||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
}
|
||||
|
||||
if (!Authorized.IsAuthorizedToModify(HttpContext.Items, AyaType.Widget, oFromDb.OwnerId))
|
||||
if (!Authorized.IsAuthorizedToModify(HttpContext.Items, AyaType.Widget, o.OwnerId))
|
||||
{
|
||||
return StatusCode(401, new ApiNotAuthorizedResponse());
|
||||
}
|
||||
|
||||
//patch and validate
|
||||
if (!biz.Patch(oFromDb, objectPatch, concurrencyToken))
|
||||
if (!biz.Patch(o, objectPatch, concurrencyToken))
|
||||
{
|
||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
}
|
||||
@@ -299,7 +305,11 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(new ApiOkResponse(new { ConcurrencyToken = oFromDb.ConcurrencyToken }));
|
||||
|
||||
//Log
|
||||
EventLogProcessor.AddEntry(new Event(biz.userId, o.Id, AyaType.Widget, AyaEvent.Modified), ct);
|
||||
|
||||
return Ok(new ApiOkResponse(new { ConcurrencyToken = o.ConcurrencyToken }));
|
||||
}
|
||||
|
||||
|
||||
@@ -346,8 +356,9 @@ namespace AyaNova.Api.Controllers
|
||||
//save and success return
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//Only here process save event??
|
||||
EventLogProcessor.AddEntry();
|
||||
//Log
|
||||
EventLogProcessor.AddEntry(new Event(biz.userId, o.Id, AyaType.Widget, AyaEvent.Created), ct);
|
||||
|
||||
return CreatedAtAction("GetWidget", new { id = o.Id }, new ApiCreatedResponse(o));
|
||||
}
|
||||
}
|
||||
@@ -400,6 +411,9 @@ namespace AyaNova.Api.Controllers
|
||||
//Delete children / attached objects
|
||||
biz.DeleteChildren(dbObj);
|
||||
|
||||
//Log
|
||||
EventLogProcessor.DeleteObject(biz.userId, AyaType.Widget, dbObj.Id, dbObj.Name, ct);
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,23 @@ namespace AyaNova.Biz
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Handle delete
|
||||
/// remove all prior entries for object, add one deleted entry
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="ayType"></param>
|
||||
/// <param name="ayId"></param>
|
||||
/// <param name="textra"></param>
|
||||
/// <param name="ct"></param>
|
||||
internal static void DeleteObject(long userId, AyaType ayType, long ayId, string textra, AyContext ct)
|
||||
{
|
||||
ct.Database.ExecuteSqlCommand("delete from aevent where aytype = {0} and ayid={1}", new object[] { (int)ayType }, new object[] { ayId });
|
||||
ct.Event.Add(new Event(userId, ayId, ayType, AyaEvent.Deleted, textra));
|
||||
ct.SaveChanges();
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
}//eoc
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace AyaNova.Biz
|
||||
internal class WidgetBiz : BizObject, IJobObject
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
private readonly long userId;
|
||||
public readonly long userId;
|
||||
private readonly AuthorizationRoles userRoles;
|
||||
|
||||
|
||||
@@ -38,43 +38,13 @@ namespace AyaNova.Biz
|
||||
return null;
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
using (var trans = ct.Database.BeginTransaction())
|
||||
{
|
||||
// try
|
||||
// {
|
||||
//do stuff with widget
|
||||
Widget outObj = inObj;
|
||||
outObj.OwnerId = userId;
|
||||
//SearchHelper(break down text fields, save to db)
|
||||
//TagHelper(collection of tags??)
|
||||
await ct.Widget.AddAsync(outObj);
|
||||
|
||||
//Log creation
|
||||
Event ev = new Event();
|
||||
ev.AyEvent = AyaEvent.Created;
|
||||
ev.AyId = outObj.Id;
|
||||
ev.AyType = AyaType.Widget;
|
||||
ev.OwnerId = outObj.OwnerId;
|
||||
await ct.Event.AddAsync(ev);
|
||||
|
||||
|
||||
// Commit transaction if all commands succeed, transaction will auto-rollback
|
||||
// when disposed if either commands fails
|
||||
trans.Commit();
|
||||
|
||||
return outObj;
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// throw ex;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,12 @@ namespace AyaNova.Util
|
||||
/////////////////////////////////////////////////////////////////
|
||||
/////////// CHANGE THIS ON NEW SCHEMA UPDATE ////////////////////
|
||||
|
||||
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::PrepareDatabaseForSeeding WHEN NEW TABLES ADDED!!!!
|
||||
private const int DESIRED_SCHEMA_LEVEL = 9;
|
||||
|
||||
internal const long EXPECTED_COLUMN_COUNT = 76;
|
||||
internal const long EXPECTED_INDEX_COUNT = 15;
|
||||
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::PrepareDatabaseForSeeding WHEN NEW TABLES ADDED!!!!
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@@ -278,6 +278,7 @@ namespace AyaNova.Util
|
||||
EraseTable("atag", conn);
|
||||
EraseTable("afileattachment", conn);
|
||||
EraseTable("awidget", conn);
|
||||
EraseTable("aevent", conn);
|
||||
|
||||
conn.Close();
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace AyaNova.Util
|
||||
|
||||
//get the current server state so can set back to it later
|
||||
ApiServerState.ServerState wasServerState = apiServerState.GetState();
|
||||
string wasReason=apiServerState.Reason;
|
||||
string wasReason = apiServerState.Reason;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -245,7 +245,7 @@ namespace AyaNova.Util
|
||||
else
|
||||
u.Password = Hasher.hash(u.Salt, u.Login);
|
||||
u.Roles = roles;
|
||||
u.LocaleId=ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID;
|
||||
u.LocaleId = ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID;
|
||||
ct.User.Add(u);
|
||||
}
|
||||
ct.SaveChanges();
|
||||
@@ -273,8 +273,10 @@ namespace AyaNova.Util
|
||||
//this is nonsense but just to test an enum
|
||||
o.Roles = AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited | AuthorizationRoles.OpsAdminLimited;
|
||||
ct.Widget.Add(o);
|
||||
}
|
||||
ct.SaveChanges();
|
||||
EventLogProcessor.AddEntry(new Event(o.OwnerId, o.Id, AyaType.Widget, AyaEvent.Created), ct);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user