示例#1
0
        public async Task <ActionResult <IEnumerable <CompraViewModel> > > 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 <CompraViewModel> 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 }));
            }
        }