This commit is contained in:
@@ -213,7 +213,6 @@ namespace AyaNova.Api.Controllers
|
||||
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(new ApiOkResponse(new { ConcurrencyToken = o.ConcurrencyToken }));
|
||||
}
|
||||
|
||||
@@ -245,7 +244,6 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
//Instantiate the business object handler
|
||||
UserBiz biz = UserBiz.GetBiz(ct, HttpContext);
|
||||
|
||||
var o = await ct.User.SingleOrDefaultAsync(m => m.Id == id);
|
||||
|
||||
if (o == null)
|
||||
|
||||
@@ -77,15 +77,9 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
//Instantiate the business object handler
|
||||
WidgetBiz biz = WidgetBiz.GetBiz(ct, HttpContext);
|
||||
|
||||
var o = await biz.GetAsync(id);
|
||||
|
||||
if (o == null)
|
||||
{
|
||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||
}
|
||||
|
||||
|
||||
return Ok(new ApiOkResponse(o));
|
||||
}
|
||||
|
||||
@@ -199,17 +193,10 @@ namespace AyaNova.Api.Controllers
|
||||
//Instantiate the business object handler
|
||||
WidgetBiz biz = WidgetBiz.GetBiz(ct, HttpContext);
|
||||
|
||||
if (!biz.Put(o, inObj))
|
||||
{
|
||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
//Log
|
||||
EventLogProcessor.AddEntry(new Event(biz.UserId, o.Id, WidgetBiz.BizType, AyaEvent.Modified), ct);
|
||||
await ct.SaveChangesAsync();
|
||||
Search.ProcessUpdatedObjectKeywords(ct, UserLocaleIdFromContext.Id(HttpContext.Items), o.Id, WidgetBiz.BizType, o.Name, o.Notes, o.Name);
|
||||
if (!biz.Put(o, inObj))
|
||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
@@ -225,9 +212,6 @@ namespace AyaNova.Api.Controllers
|
||||
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return Ok(new ApiOkResponse(new { ConcurrencyToken = o.ConcurrencyToken }));
|
||||
}
|
||||
|
||||
@@ -261,8 +245,6 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
//Instantiate the business object handler
|
||||
WidgetBiz biz = WidgetBiz.GetBiz(ct, HttpContext);
|
||||
|
||||
|
||||
var o = await ct.Widget.SingleOrDefaultAsync(m => m.Id == id);
|
||||
|
||||
if (o == null)
|
||||
@@ -275,21 +257,13 @@ namespace AyaNova.Api.Controllers
|
||||
return StatusCode(401, new ApiNotAuthorizedResponse());
|
||||
}
|
||||
|
||||
//patch and validate
|
||||
if (!biz.Patch(o, objectPatch, concurrencyToken))
|
||||
{
|
||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
//Log
|
||||
EventLogProcessor.AddEntry(new Event(biz.UserId, o.Id, WidgetBiz.BizType, AyaEvent.Modified), ct);
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//this will save the context as part of it's operations
|
||||
Search.ProcessUpdatedObjectKeywords(ct, UserLocaleIdFromContext.Id(HttpContext.Items), o.Id, WidgetBiz.BizType, o.Name, o.Notes, o.Name);
|
||||
|
||||
//patch and validate
|
||||
if (!biz.Patch(o, objectPatch, concurrencyToken))
|
||||
{
|
||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
}
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
@@ -348,17 +322,6 @@ namespace AyaNova.Api.Controllers
|
||||
else
|
||||
{
|
||||
|
||||
//save to get Id
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//Log now that we have the Id
|
||||
EventLogProcessor.AddEntry(new Event(biz.UserId, o.Id, WidgetBiz.BizType, AyaEvent.Created), ct);
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//this will save the context as part of it's operations
|
||||
Search.ProcessNewObjectKeywords(ct, UserLocaleIdFromContext.Id(HttpContext.Items), o.Id, WidgetBiz.BizType, o.Name, o.Notes, o.Name);
|
||||
|
||||
|
||||
//return success and link
|
||||
return CreatedAtAction("GetWidget", new { id = o.Id }, new ApiCreatedResponse(o));
|
||||
}
|
||||
@@ -379,7 +342,6 @@ namespace AyaNova.Api.Controllers
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> DeleteWidget([FromRoute] long id)
|
||||
{
|
||||
|
||||
if (!serverState.IsOpen)
|
||||
{
|
||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||
@@ -409,17 +371,6 @@ namespace AyaNova.Api.Controllers
|
||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
}
|
||||
|
||||
//Log
|
||||
EventLogProcessor.DeleteObject(biz.UserId, WidgetBiz.BizType, dbObj.Id, dbObj.Name, ct);
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//This will directly execute and is not part of context for saving purposes
|
||||
Search.ProcessDeletedObjectKeywords(ct, dbObj.Id, WidgetBiz.BizType);
|
||||
|
||||
|
||||
//Delete children / attached objects
|
||||
biz.DeleteChildren(dbObj);
|
||||
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
@@ -272,7 +272,6 @@ namespace AyaNova.Biz
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//DELETE
|
||||
//
|
||||
|
||||
internal bool Delete(User dbObj)
|
||||
{
|
||||
ValidateCanDelete(dbObj);
|
||||
|
||||
@@ -57,19 +57,16 @@ namespace AyaNova.Biz
|
||||
|
||||
|
||||
await ct.Widget.AddAsync(outObj);
|
||||
|
||||
//save to get Id
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//Handle child and associated items
|
||||
//Handle child and associated items:
|
||||
|
||||
//Log event
|
||||
//EVENT LOG
|
||||
EventLogProcessor.AddEntry(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//SEARCH INDEXING
|
||||
Search.ProcessNewObjectKeywords(ct, UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.Notes, outObj.Name);
|
||||
HERE
|
||||
|
||||
return outObj;
|
||||
|
||||
@@ -182,6 +179,12 @@ HERE
|
||||
if (HasErrors)
|
||||
return false;
|
||||
|
||||
//Log modification
|
||||
EventLogProcessor.AddEntry(new Event(UserId, dbObj.Id, BizType, AyaEvent.Modified), ct);
|
||||
ct.SaveChanges();
|
||||
//Update keywords
|
||||
Search.ProcessUpdatedObjectKeywords(ct, UserLocaleId, dbObj.Id, BizType, dbObj.Name, dbObj.Notes, dbObj.Name);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -198,6 +201,12 @@ HERE
|
||||
if (HasErrors)
|
||||
return false;
|
||||
|
||||
//Log modification
|
||||
EventLogProcessor.AddEntry(new Event(UserId, dbObj.Id, BizType, AyaEvent.Modified), ct);
|
||||
ct.SaveChanges();
|
||||
//Update keywords
|
||||
Search.ProcessUpdatedObjectKeywords(ct, UserLocaleId, dbObj.Id, BizType, dbObj.Name, dbObj.Notes, dbObj.Name);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -205,7 +214,6 @@ HERE
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//DELETE
|
||||
//
|
||||
|
||||
internal bool Delete(Widget dbObj)
|
||||
{
|
||||
//Determine if the object can be deleted, do the deletion tentatively
|
||||
@@ -215,17 +223,22 @@ HERE
|
||||
if (HasErrors)
|
||||
return false;
|
||||
ct.Widget.Remove(dbObj);
|
||||
return true;
|
||||
}
|
||||
ct.SaveChanges();
|
||||
|
||||
//Delete sibling objects
|
||||
|
||||
//Event log process delete
|
||||
EventLogProcessor.DeleteObject(UserId, BizType, dbObj.Id, dbObj.Name, ct);
|
||||
ct.SaveChanges();
|
||||
|
||||
//Delete search index
|
||||
Search.ProcessDeletedObjectKeywords(ct, dbObj.Id, BizType);
|
||||
|
||||
/// <summary>
|
||||
/// Delete child objects like tags and attachments and etc
|
||||
/// </summary>
|
||||
/// <param name="dbObj"></param>
|
||||
internal void DeleteChildren(Widget dbObj)
|
||||
{
|
||||
//TAGS
|
||||
TagMapBiz.DeleteAllForObject(new AyaTypeId(BizType, dbObj.Id), ct);
|
||||
ct.SaveChanges();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -298,7 +311,6 @@ HERE
|
||||
private void ValidateCanDelete(Widget inObj)
|
||||
{
|
||||
//whatever needs to be check to delete this object
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user