This commit is contained in:
2020-07-30 20:39:38 +00:00
parent 129eafa64c
commit dfa47ab89f
8 changed files with 125 additions and 61 deletions

View File

@@ -216,7 +216,7 @@ namespace AyaNova.Api.Controllers
}
}
/// <summary>
/// <summary>
/// Duplicate User
/// (Wiki and Attachments are not duplicated)
/// </summary>
@@ -245,38 +245,19 @@ namespace AyaNova.Api.Controllers
/// Delete User
/// </summary>
/// <param name="id"></param>
/// <returns>Ok</returns>
/// <returns>NoContent</returns>
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteUser([FromRoute] long id)
{
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
if (!ModelState.IsValid)
{
return BadRequest(new ApiErrorResponse(ModelState));
}
//Instantiate the business object handler
UserBiz biz = UserBiz.GetBiz(ct, HttpContext);
var dbObject = await ct.User.SingleOrDefaultAsync(z => z.Id == id);
if (dbObject == null)
{
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
}
if (!Authorized.HasDeleteRole(HttpContext.Items, biz.BizType))
{
return StatusCode(403, new ApiNotAuthorizedResponse());
}
if (!await biz.DeleteAsync(dbObject))
{
if (!await biz.DeleteAsync(id))
return BadRequest(new ApiErrorResponse(biz.Errors));
}
return NoContent();
}