This commit is contained in:
@@ -73,8 +73,8 @@ namespace AyaNova.Api.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Instantiate the business object handler
|
//Instantiate the business object handler
|
||||||
UserBiz biz = UserBiz.GetBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserLocaleIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
UserBiz biz = UserBiz.GetBiz(ct, HttpContext);
|
||||||
|
|
||||||
var o = await biz.GetAsync(id);
|
var o = await biz.GetAsync(id);
|
||||||
|
|
||||||
if (o == null)
|
if (o == null)
|
||||||
@@ -118,7 +118,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Instantiate the business object handler
|
//Instantiate the business object handler
|
||||||
UserBiz biz = UserBiz.GetBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserLocaleIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
UserBiz biz = UserBiz.GetBiz(ct, HttpContext);
|
||||||
|
|
||||||
ApiPagedResponse<System.Object> pr = await biz.GetManyAsync(Url, nameof(ListUsers), pagingOptions);
|
ApiPagedResponse<System.Object> pr = await biz.GetManyAsync(Url, nameof(ListUsers), pagingOptions);
|
||||||
return Ok(new ApiOkWithPagingResponse<System.Object>(pr));
|
return Ok(new ApiOkWithPagingResponse<System.Object>(pr));
|
||||||
@@ -154,7 +154,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Instantiate the business object handler
|
//Instantiate the business object handler
|
||||||
UserBiz biz = UserBiz.GetBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserLocaleIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
UserBiz biz = UserBiz.GetBiz(ct, HttpContext);
|
||||||
ApiPagedResponse<NameIdItem> pr = await biz.GetPickListAsync(Url, nameof(UserPickList), pagingOptions, q);
|
ApiPagedResponse<NameIdItem> pr = await biz.GetPickListAsync(Url, nameof(UserPickList), pagingOptions, q);
|
||||||
return Ok(new ApiOkWithPagingResponse<NameIdItem>(pr));
|
return Ok(new ApiOkWithPagingResponse<NameIdItem>(pr));
|
||||||
}
|
}
|
||||||
@@ -196,19 +196,12 @@ namespace AyaNova.Api.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Instantiate the business object handler
|
//Instantiate the business object handler
|
||||||
UserBiz biz = UserBiz.GetBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserLocaleIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
UserBiz biz = UserBiz.GetBiz(ct, HttpContext);
|
||||||
|
|
||||||
if (!biz.Put(o, inObj))
|
|
||||||
{
|
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//Log
|
if (!biz.Put(o, inObj))
|
||||||
EventLogProcessor.AddEntry(new Event(biz.UserId, o.Id, AyaType.User, AyaEvent.Modified), ct);
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
await ct.SaveChangesAsync();
|
|
||||||
Search.ProcessUpdatedObjectKeywords(ct, UserLocaleIdFromContext.Id(HttpContext.Items), o.Id, AyaType.User, o.Name, o.EmployeeNumber, o.Notes, o.Name);
|
|
||||||
}
|
}
|
||||||
catch (DbUpdateConcurrencyException)
|
catch (DbUpdateConcurrencyException)
|
||||||
{
|
{
|
||||||
@@ -225,8 +218,6 @@ namespace AyaNova.Api.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return Ok(new ApiOkResponse(new { ConcurrencyToken = o.ConcurrencyToken }));
|
return Ok(new ApiOkResponse(new { ConcurrencyToken = o.ConcurrencyToken }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,7 +248,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Instantiate the business object handler
|
//Instantiate the business object handler
|
||||||
UserBiz biz = UserBiz.GetBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserLocaleIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
UserBiz biz = UserBiz.GetBiz(ct, HttpContext);
|
||||||
|
|
||||||
var o = await ct.User.SingleOrDefaultAsync(m => m.Id == id);
|
var o = await ct.User.SingleOrDefaultAsync(m => m.Id == id);
|
||||||
|
|
||||||
@@ -271,18 +262,13 @@ namespace AyaNova.Api.Controllers
|
|||||||
return StatusCode(401, new ApiNotAuthorizedResponse());
|
return StatusCode(401, new ApiNotAuthorizedResponse());
|
||||||
}
|
}
|
||||||
|
|
||||||
//patch and validate
|
|
||||||
if (!biz.Patch(o, objectPatch, concurrencyToken))
|
|
||||||
{
|
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//Log
|
//patch and validate
|
||||||
EventLogProcessor.AddEntry(new Event(biz.UserId, o.Id, AyaType.User, AyaEvent.Modified), ct);
|
if (!biz.Patch(o, objectPatch, concurrencyToken))
|
||||||
await ct.SaveChangesAsync();
|
{
|
||||||
Search.ProcessUpdatedObjectKeywords(ct, UserLocaleIdFromContext.Id(HttpContext.Items), o.Id, AyaType.User, o.Name, o.EmployeeNumber, o.Notes, o.Name);
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (DbUpdateConcurrencyException)
|
catch (DbUpdateConcurrencyException)
|
||||||
{
|
{
|
||||||
@@ -296,9 +282,6 @@ namespace AyaNova.Api.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return Ok(new ApiOkResponse(new { ConcurrencyToken = o.ConcurrencyToken }));
|
return Ok(new ApiOkResponse(new { ConcurrencyToken = o.ConcurrencyToken }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,7 +315,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Instantiate the business object handler
|
//Instantiate the business object handler
|
||||||
UserBiz biz = UserBiz.GetBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserLocaleIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
UserBiz biz = UserBiz.GetBiz(ct, HttpContext);
|
||||||
|
|
||||||
//Create and validate
|
//Create and validate
|
||||||
User o = await biz.CreateAsync(inObj);
|
User o = await biz.CreateAsync(inObj);
|
||||||
@@ -345,10 +328,6 @@ namespace AyaNova.Api.Controllers
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
//EVENT LOG
|
|
||||||
//Note that event log is processed in the biz object unlike the widget for no apparent reason
|
|
||||||
|
|
||||||
|
|
||||||
//return success and link
|
//return success and link
|
||||||
//NOTE: this is a USER object so we don't want to return some key fields for security reasons
|
//NOTE: this is a USER object so we don't want to return some key fields for security reasons
|
||||||
//which is why the object is "cleaned" before return
|
//which is why the object is "cleaned" before return
|
||||||
@@ -393,23 +372,12 @@ namespace AyaNova.Api.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Instantiate the business object handler
|
//Instantiate the business object handler
|
||||||
UserBiz biz = UserBiz.GetBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserLocaleIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
UserBiz biz = UserBiz.GetBiz(ct, HttpContext);
|
||||||
if (!biz.Delete(dbObj))
|
if (!biz.Delete(dbObj))
|
||||||
{
|
{
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Log
|
|
||||||
EventLogProcessor.DeleteObject(biz.UserId, AyaType.User, dbObj.Id, dbObj.Name, ct);
|
|
||||||
await ct.SaveChangesAsync();
|
|
||||||
|
|
||||||
//Delete children / attached objects
|
|
||||||
biz.DeleteChildren(dbObj);
|
|
||||||
|
|
||||||
//This will directly execute and is not part of context for saving purposes
|
|
||||||
Search.ProcessDeletedObjectKeywords(ct, dbObj.Id, AyaType.User);
|
|
||||||
|
|
||||||
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace AyaNova.Biz
|
|||||||
switch (aytype)
|
switch (aytype)
|
||||||
{
|
{
|
||||||
case AyaType.User:
|
case AyaType.User:
|
||||||
return new UserBiz(dbcontext, userId, roles);
|
return new UserBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, roles);
|
||||||
case AyaType.Widget:
|
case AyaType.Widget:
|
||||||
return new WidgetBiz(dbcontext, userId, roles);
|
return new WidgetBiz(dbcontext, userId, roles);
|
||||||
case AyaType.Tag:
|
case AyaType.Tag:
|
||||||
|
|||||||
@@ -33,19 +33,18 @@ namespace AyaNova.Biz
|
|||||||
V7ValidationImportMode = false;//default
|
V7ValidationImportMode = false;//default
|
||||||
}
|
}
|
||||||
|
|
||||||
todo: reorging this to be a simple static fetcher for the biz object, pass it the httpcontext and it will figure the rest
|
//todo:
|
||||||
//then move all indexing and eventlog and associated record handling into here so that routes can just call into it simply and it handles all
|
//then move all indexing and eventlog and associated record handling into here so that routes can just call into it simply and it handles all
|
||||||
//here at the biz level
|
//here at the biz level
|
||||||
|
|
||||||
//Then after that go into seeder and re-org to use the biz object to create the users (it will be slower but WTF other way is this going to work properly to generate data??)
|
//Then after that go into seeder and re-org to use the biz object to create the users (it will be slower but WTF other way is this going to work properly to generate data??)
|
||||||
|
|
||||||
//then after that go into widget and anywhere else that there is this associated type code being called for event and search and implement everywhere,
|
//then after that go into widget and anywhere else that there is this associated type code being called for event and search and implement everywhere,
|
||||||
//then update seeder code to use it and get back on to the main critical path again in the todo
|
//then update seeder code to use it and get back on to the main critical path again in the todo
|
||||||
|
|
||||||
internal static UserBiz GetBiz(AyContext ct, HttpContextExtensions , AuthorizationRoles UserRoles)
|
internal static UserBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext)
|
||||||
{
|
{
|
||||||
//long currentUserId, long userLocaleId
|
return new UserBiz(ct, UserIdFromContext.Id(httpContext.Items), UserLocaleIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items));
|
||||||
return new UserBiz(ct, currentUserId, userLocaleId, UserRoles);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -214,6 +213,13 @@ todo: reorging this to be a simple static fetcher for the biz object, pass it th
|
|||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
||||||
|
//Log modification
|
||||||
|
EventLogProcessor.AddEntry(new Event(UserId, dbObj.Id, AyaType.User, AyaEvent.Modified), ct);
|
||||||
|
ct.SaveChanges();
|
||||||
|
//Update keywords
|
||||||
|
Search.ProcessUpdatedObjectKeywords(ct, UserLocaleId, dbObj.Id, AyaType.User, dbObj.Name, dbObj.EmployeeNumber, dbObj.Notes, dbObj.Name);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,6 +247,13 @@ todo: reorging this to be a simple static fetcher for the biz object, pass it th
|
|||||||
Validate(dbObj, snapshotObj);
|
Validate(dbObj, snapshotObj);
|
||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
//Log modification
|
||||||
|
EventLogProcessor.AddEntry(new Event(UserId, dbObj.Id, AyaType.User, AyaEvent.Modified), ct);
|
||||||
|
ct.SaveChanges();
|
||||||
|
//Update keywords
|
||||||
|
Search.ProcessUpdatedObjectKeywords(ct, UserLocaleId, dbObj.Id, AyaType.User, dbObj.Name, dbObj.EmployeeNumber, dbObj.Notes, dbObj.Name);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,28 +264,32 @@ todo: reorging this to be a simple static fetcher for the biz object, pass it th
|
|||||||
|
|
||||||
internal bool Delete(User dbObj)
|
internal bool Delete(User dbObj)
|
||||||
{
|
{
|
||||||
//Determine if the object can be deleted, do the deletion tentatively
|
|
||||||
//Probably also in here deal with tags and associated search text etc
|
|
||||||
|
|
||||||
ValidateCanDelete(dbObj);
|
ValidateCanDelete(dbObj);
|
||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
//Remove the object
|
||||||
ct.User.Remove(dbObj);
|
ct.User.Remove(dbObj);
|
||||||
|
ct.SaveChanges();
|
||||||
|
|
||||||
|
//Delete sibling objects
|
||||||
|
//USEROPTIONS
|
||||||
|
ct.Database.ExecuteSqlCommand($"delete from auseroptions where userid={dbObj.Id}");
|
||||||
|
|
||||||
|
//Event log process delete
|
||||||
|
EventLogProcessor.DeleteObject(UserId, AyaType.User, dbObj.Id, dbObj.Name, ct);
|
||||||
|
ct.SaveChanges();
|
||||||
|
|
||||||
|
//Delete search index
|
||||||
|
Search.ProcessDeletedObjectKeywords(ct, dbObj.Id, AyaType.User);
|
||||||
|
|
||||||
|
//TAGS
|
||||||
|
TagMapBiz.DeleteAllForObject(new AyaTypeId(AyaType.User, dbObj.Id), ct);
|
||||||
|
ct.SaveChanges();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Delete child objects like tags and attachments and etc
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="dbObj"></param>
|
|
||||||
internal void DeleteChildren(User dbObj)
|
|
||||||
{
|
|
||||||
//TAGS
|
|
||||||
TagMapBiz.DeleteAllForObject(new AyaTypeId(AyaType.User, dbObj.Id), ct);
|
|
||||||
|
|
||||||
//USEROPTIONS
|
|
||||||
ct.Database.ExecuteSqlCommand($"delete from auseroptions where userid={dbObj.Id}");
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//VALIDATION
|
//VALIDATION
|
||||||
|
|||||||
Reference in New Issue
Block a user