Skip to content

Instantly share code, notes, and snippets.

@celsojr
Last active May 9, 2020 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save celsojr/0fd99a9eaae989c4fe3ff366349b6685 to your computer and use it in GitHub Desktop.
Save celsojr/0fd99a9eaae989c4fe3ff366349b6685 to your computer and use it in GitHub Desktop.
See the blog post here: https://celsojr.com/wp/archives/576
// DELETE api/v1/author/{authorId}
/// <summary>
/// Deletes an Author
/// </summary>
/// <remarks>Deletes an Author</remarks>
/// <param name="authorId"></param>
[HttpDelete("{authorId:length(24)}", Name = nameof(DeleteAuthor))]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(DeleteModel<>), StatusCodes.Status200OK)]
public async Task<IActionResult> DeleteAuthor(string authorId)
{
var author = await _unitOfWork.Library.GetAuthorById(authorId);
if (author == null)
{
return NotFound();
}
var undoObject = new DeleteModel<string> { ResourceId = authorId };
_memoryCache.Set(authorId, author, undoObject.ExpireTime);
_unitOfWork.Library.RemoveAuthor(authorId);
await _unitOfWork.Commit();
return Ok(undoObject);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment