public async Task <ActionResult <IEnumerable <HistoricoViewModel> > > GetAll() { const string endpointName = nameof(GetAll); string header = $"GET | {UserTokenOptions.GetClaimTypesNameValue(User.Identity)} | {controllerName}: {endpointName}"; try { logger.LogInformation((int)LogEventEnum.Events.GetItem, $"{header} - {MessageLog.Start.Value}"); IEnumerable <HistoricoViewModel> entities = await service.GetAll(UserTokenOptions.GetClaimTypesNameValue(User.Identity)); if (entities.ToList().Count <= 0) { logger.LogInformation((int)LogEventEnum.Events.GetItemNotFound, $"{header} - {MessageError.NotFound.Value}"); return(NotFound(new { message = MessageError.NotFound.Value })); } logger.LogInformation((int)LogEventEnum.Events.GetItem, $"{header} - {MessageLog.Stop.Value}"); return(Ok(entities)); } catch (Exception ex) { logger.LogError((int)LogEventEnum.Events.GetItemError, ex, $"{header} - {MessageLog.Error.Value} | Exception: {ex.Message}"); return(StatusCode(StatusCodes.Status500InternalServerError, new { message = MessageError.InternalError.Value, error = ex.Message })); } }
public HttpResponseMessage GetAll() { var historico = _historicoService.GetAll(); if (historico.Any()) { return(Request.CreateResponse(HttpStatusCode.OK, historico)); } return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "No historico found.")); }
public async Task <IActionResult> GetAll() { try { var getAllHistorico = await _service.GetAll(); return(Ok(getAllHistorico)); } catch (ArgumentException e) { return(this.StatusCode(StatusCodes.Status500InternalServerError, $"${e.Message}")); } }