Skip to content

Instantly share code, notes, and snippets.

@celsojr
Last active May 9, 2020
Embed
What would you like to do?
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