Skip to content

Instantly share code, notes, and snippets.

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