Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@celsojr
Last active April 19, 2020 18:36
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/1a0c6babae9810e17221378d6da4aede to your computer and use it in GitHub Desktop.
Save celsojr/1a0c6babae9810e17221378d6da4aede to your computer and use it in GitHub Desktop.
See the blog post here: https://celsojr.com/wp/archives/576
// POST api/v1/author/{authorId}/undo
/// <summary>
/// Undo a deleted action on Author
/// </summary>
/// <remarks>Undo a deleted action on Author</remarks>
/// <param name="authorId"></param>
[HttpPost("{authorId:length(24)}/undo", Name = nameof(UndoDeletedAuthor))]
[ProducesResponseType(StatusCodes.Status410Gone)]
[ProducesResponseType(StatusCodes.Status201Created)]
public async Task<IActionResult> UndoDeletedAuthor(string authorId)
{
if (!_memoryCache.TryGetValue(authorId, out Author author))
{
return new StatusCodeResult(StatusCodes.Status410Gone);
}
_unitOfWork.Library.AddAuthor(author);
await _unitOfWork.Commit();
var authorToReturn = _mapper.Map<AuthorDto>(author);
return CreatedAtAction(nameof(GetAuthor), new { authorId }, authorToReturn);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment