Пример #1
0
 public IActionResult GetAllEmpresas()
 {
     try{
         Console.WriteLine("[GetAllEmpresas] -> listar todas las empresas");
         List <Empresa> result = empresasService.ListAllEmpresas();
         if (result == null || result.Count() == 0)
         {
             Console.WriteLine("[GetAllEmpresas] -> no hay resultados");
             RestResponse r = RestUtils.GenerateResponseOkEmpty();
             r.Header.Message = RestUtils.RESPONSE_NOTFOUND_MSG;
             return(NotFound(r));
         }
         Console.WriteLine("[GetAllEmpresas] -> request exitosa");
         //RestResponse response = RestUtils.GenerateResponseOkWithData(result);
         RestResponse response = RestUtils.GenerateResponseOkEmpty();
         foreach (Empresa e in result)
         {
             response.Data.Add(e);
         }
         return(Ok(response));
     }catch (Exception exception) {
         Console.WriteLine("[GetAllEmpresas] -> " + RestUtils.RESPONSE_INTERNAL_ERROR_MSG);
         RestResponse response = RestUtils.GenerateResponseErrorWith(
             new ResponseError(
                 exception.Message,
                 exception.GetType().ToString()
                 )
             );
         response.Header.Message = RestUtils.RESPONSE_INTERNAL_ERROR_MSG;
         return(StatusCode(
                    StatusCodes.Status500InternalServerError,
                    response
                    ));
     }
 }