public void PerformGetById <T>(HttpListenerContext context, GetResourceById <T> getResource, string parameter) { if (_verify != null && !_verify(context.Request)) { WriteError(context.Response, HttpStatusCode.Unauthorized, "Authorization failed"); return; } if (int.TryParse(parameter, out int id)) { if (getResource.Invoke(id, out T value)) { WriteToResponse(context.Response, value); } else { WriteError(context.Response, HttpStatusCode.NotFound, "resource with provided id not found"); } } else { WriteError(context.Response, HttpStatusCode.BadRequest, parameter + " unexpected"); } }
public async Task <IActionResult> GetResourceByIdAsync(int id) { var command = new GetResourceById(id); var result = await _mediator.Send(command); if (result != null) { return(Ok(result)); } else { return(NoContent()); } }