Exemplo n.º 1
0
        public async Task <ActionResult <HistoricoViewModel> > GetById(int id)
        {
            const string endpointName = nameof(GetById);
            string       header       = $"GET | {UserTokenOptions.GetClaimTypesNameValue(User.Identity)} | {controllerName}: {endpointName}";

            try
            {
                logger.LogInformation((int)LogEventEnum.Events.GetItem,
                                      $"{header} - {MessageLog.Start.Value}");

                HistoricoViewModel entity = await service.GetById(id, UserTokenOptions.GetClaimTypesNameValue(User.Identity));

                if (entity is null)
                {
                    logger.LogInformation((int)LogEventEnum.Events.GetItemNotFound,
                                          $"{header} - {MessageError.NotFoundSingle.Value}");

                    return(NotFound(new { message = MessageError.NotFoundSingle.Value }));
                }

                logger.LogInformation((int)LogEventEnum.Events.GetItem,
                                      $"{header} - {MessageLog.Stop.Value}");

                return(Ok(entity));
            }
            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 }));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetById(int id)
        {
            try
            {
                var getByIdHistorico = await _service.GetById(id);

                return(Ok(getByIdHistorico));
            }
            catch (ArgumentException e)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"${e.Message}"));
            }
        }