This commit is contained in:
@@ -213,7 +213,6 @@ namespace AyaNova.Api.Controllers
|
|||||||
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
|
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(new ApiOkResponse(new { ConcurrencyToken = o.ConcurrencyToken }));
|
return Ok(new ApiOkResponse(new { ConcurrencyToken = o.ConcurrencyToken }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,7 +244,6 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
//Instantiate the business object handler
|
//Instantiate the business object handler
|
||||||
UserBiz biz = UserBiz.GetBiz(ct, HttpContext);
|
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);
|
||||||
|
|
||||||
if (o == null)
|
if (o == null)
|
||||||
|
|||||||
@@ -77,15 +77,9 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
//Instantiate the business object handler
|
//Instantiate the business object handler
|
||||||
WidgetBiz biz = WidgetBiz.GetBiz(ct, HttpContext);
|
WidgetBiz biz = WidgetBiz.GetBiz(ct, HttpContext);
|
||||||
|
|
||||||
var o = await biz.GetAsync(id);
|
var o = await biz.GetAsync(id);
|
||||||
|
|
||||||
if (o == null)
|
if (o == null)
|
||||||
{
|
|
||||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return Ok(new ApiOkResponse(o));
|
return Ok(new ApiOkResponse(o));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,17 +193,10 @@ namespace AyaNova.Api.Controllers
|
|||||||
//Instantiate the business object handler
|
//Instantiate the business object handler
|
||||||
WidgetBiz biz = WidgetBiz.GetBiz(ct, HttpContext);
|
WidgetBiz biz = WidgetBiz.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, WidgetBiz.BizType, AyaEvent.Modified), ct);
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
await ct.SaveChangesAsync();
|
|
||||||
Search.ProcessUpdatedObjectKeywords(ct, UserLocaleIdFromContext.Id(HttpContext.Items), o.Id, WidgetBiz.BizType, o.Name, o.Notes, o.Name);
|
|
||||||
}
|
}
|
||||||
catch (DbUpdateConcurrencyException)
|
catch (DbUpdateConcurrencyException)
|
||||||
{
|
{
|
||||||
@@ -225,9 +212,6 @@ namespace AyaNova.Api.Controllers
|
|||||||
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
|
return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return Ok(new ApiOkResponse(new { ConcurrencyToken = o.ConcurrencyToken }));
|
return Ok(new ApiOkResponse(new { ConcurrencyToken = o.ConcurrencyToken }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,8 +245,6 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
//Instantiate the business object handler
|
//Instantiate the business object handler
|
||||||
WidgetBiz biz = WidgetBiz.GetBiz(ct, HttpContext);
|
WidgetBiz biz = WidgetBiz.GetBiz(ct, HttpContext);
|
||||||
|
|
||||||
|
|
||||||
var o = await ct.Widget.SingleOrDefaultAsync(m => m.Id == id);
|
var o = await ct.Widget.SingleOrDefaultAsync(m => m.Id == id);
|
||||||
|
|
||||||
if (o == null)
|
if (o == null)
|
||||||
@@ -275,21 +257,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, WidgetBiz.BizType, AyaEvent.Modified), ct);
|
if (!biz.Patch(o, objectPatch, concurrencyToken))
|
||||||
await ct.SaveChangesAsync();
|
{
|
||||||
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
//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);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (DbUpdateConcurrencyException)
|
catch (DbUpdateConcurrencyException)
|
||||||
{
|
{
|
||||||
@@ -348,17 +322,6 @@ namespace AyaNova.Api.Controllers
|
|||||||
else
|
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 success and link
|
||||||
return CreatedAtAction("GetWidget", new { id = o.Id }, new ApiCreatedResponse(o));
|
return CreatedAtAction("GetWidget", new { id = o.Id }, new ApiCreatedResponse(o));
|
||||||
}
|
}
|
||||||
@@ -379,7 +342,6 @@ namespace AyaNova.Api.Controllers
|
|||||||
[HttpDelete("{id}")]
|
[HttpDelete("{id}")]
|
||||||
public async Task<IActionResult> DeleteWidget([FromRoute] long id)
|
public async Task<IActionResult> DeleteWidget([FromRoute] long id)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!serverState.IsOpen)
|
if (!serverState.IsOpen)
|
||||||
{
|
{
|
||||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
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));
|
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();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -272,7 +272,6 @@ namespace AyaNova.Biz
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//DELETE
|
//DELETE
|
||||||
//
|
//
|
||||||
|
|
||||||
internal bool Delete(User dbObj)
|
internal bool Delete(User dbObj)
|
||||||
{
|
{
|
||||||
ValidateCanDelete(dbObj);
|
ValidateCanDelete(dbObj);
|
||||||
|
|||||||
@@ -57,19 +57,16 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
|
|
||||||
await ct.Widget.AddAsync(outObj);
|
await ct.Widget.AddAsync(outObj);
|
||||||
|
|
||||||
//save to get Id
|
|
||||||
await ct.SaveChangesAsync();
|
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);
|
EventLogProcessor.AddEntry(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
|
||||||
await ct.SaveChangesAsync();
|
await ct.SaveChangesAsync();
|
||||||
|
|
||||||
//SEARCH INDEXING
|
//SEARCH INDEXING
|
||||||
Search.ProcessNewObjectKeywords(ct, UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.Notes, outObj.Name);
|
Search.ProcessNewObjectKeywords(ct, UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.Notes, outObj.Name);
|
||||||
HERE
|
|
||||||
|
|
||||||
return outObj;
|
return outObj;
|
||||||
|
|
||||||
@@ -182,6 +179,12 @@ HERE
|
|||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
return false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,6 +201,12 @@ HERE
|
|||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
return false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,7 +214,6 @@ HERE
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//DELETE
|
//DELETE
|
||||||
//
|
//
|
||||||
|
|
||||||
internal bool Delete(Widget dbObj)
|
internal bool Delete(Widget dbObj)
|
||||||
{
|
{
|
||||||
//Determine if the object can be deleted, do the deletion tentatively
|
//Determine if the object can be deleted, do the deletion tentatively
|
||||||
@@ -215,17 +223,22 @@ HERE
|
|||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
return false;
|
return false;
|
||||||
ct.Widget.Remove(dbObj);
|
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
|
//TAGS
|
||||||
TagMapBiz.DeleteAllForObject(new AyaTypeId(BizType, dbObj.Id), ct);
|
TagMapBiz.DeleteAllForObject(new AyaTypeId(BizType, dbObj.Id), ct);
|
||||||
|
ct.SaveChanges();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -298,7 +311,6 @@ HERE
|
|||||||
private void ValidateCanDelete(Widget inObj)
|
private void ValidateCanDelete(Widget inObj)
|
||||||
{
|
{
|
||||||
//whatever needs to be check to delete this object
|
//whatever needs to be check to delete this object
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user