Ejemplo n.º 1
0
        public static RestResponse GenerateResponseOkWithData(Object data)
        {
            RestResponse response = GenerateResponseOkEmpty();

            response.AddObjectToData(data);
            return(response);
        }
Ejemplo n.º 2
0
 public IActionResult GetSectoresByEmpresa(int id)
 {
     try{
         Console.WriteLine("[GetSectoresByEmpresa] -> listar sectores de la empresa id: " + id);
         List <Sector> result   = sectoresService.ListarSectoresPorEmpresa(id);
         RestResponse  response = RestUtils.GenerateResponseOkEmpty();
         if (result == null || result.Count() == 0)
         {
             Console.WriteLine("[GetSectoresByEmpresa] -> no hay resultados");
             response.Header.Message = RestUtils.RESPONSE_NOTFOUND_MSG;
             return(NotFound(response));
         }
         Console.WriteLine("[GetSectoresByEmpresa] -> request exitosa");
         response.Header.Message = RestUtils.RESPONSE_OK_MSG;
         response.AddObjectToData(result);
         return(Ok(response));
     }catch (Exception exception) {
         Console.WriteLine("[GetSectoresByEmpresa] -> " + 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
                    ));
     }
 }
Ejemplo n.º 3
0
 public IActionResult GetEmpresaBy(int id)
 {
     try{
         Console.WriteLine("[GetEmpresaBy] -> buscar empresa con id: " + id);
         Empresa      result   = empresasService.FindEmpresaBy(id);
         RestResponse response = RestUtils.GenerateResponseOkEmpty();
         if (result == null)
         {
             Console.WriteLine("[GetEmpresaBy] -> no hay resultados");
             response.Header.Message = RestUtils.RESPONSE_NOTFOUND_MSG;
             return(NotFound(response));
         }
         Console.WriteLine("[GetEmpresaBy] -> request exitosa");
         response.Header.Message = RestUtils.RESPONSE_OK_MSG;
         response.AddObjectToData(result);
         return(Ok(response));
     }catch (Exception exception) {
         Console.WriteLine("[GetEmpresaBy] -> " + 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
                    ));
     }
 }
Ejemplo n.º 4
0
        public static RestResponse GenerateResponseOkWithListData(List <Object> data)
        {
            RestResponse   response = new RestResponse();
            ResponseHeader header   = new ResponseHeader();

            header.ResultCode = RESPONSE_OK_CODE;
            header.Message    = RESPONSE_OK_MSG;
            response.Header   = header;
            foreach (Object o in data)
            {
                response.AddObjectToData(o);
            }
            return(response);
        }
 public IActionResult GetDocumentsBySector(int?idEmpresa, int?idSector)
 {
     try{
         // se valida header
         if (idEmpresa == null || idEmpresa.Value == 0 || idSector == null || idSector.Value == 0)
         {
             Console.WriteLine("[GetDocumentsBySector] -> falta 'idEmpresa' o 'idSector' en la request");
             RestResponse responseErr = RestUtils.GenerateResponseErrorWith(
                 new ResponseError(
                     RestUtils.RESPONSE_BADREQUEST_CODE,
                     "Falta header 'usuario' en la request"
                     )
                 );
             responseErr.Header.Message = RestUtils.RESPONSE_BADREQUEST_MSG;
             return(BadRequest(responseErr));
         }
         RestResponse response = RestUtils.GenerateResponseOkEmpty();
         // busqueda de documentos
         Console.WriteLine("[GetDocumentsBySector] -> se van a buscar los documentos de la empresa con id: " + idEmpresa + " y sector " + idSector);
         List <DocumentoDTO> result = documentosService.FindDocumentosBySector(idEmpresa.Value, idSector.Value);
         // validacion de resultados
         if (result == null || result.Count() == 0)
         {
             Console.WriteLine("[GetDocumentsBySector] -> no se encontraron resultados");
         }
         else
         {
             Console.WriteLine("[GetDocumentsBySector] -> imprimiendo resultados");
             foreach (DocumentoDTO d in result)
             {
                 response.AddObjectToData(d);
             }
         }
         return(Ok(response));
     } catch (Exception exception) {
         RestResponse response = RestUtils.GenerateResponseErrorWith(
             new ResponseError(
                 exception.Message,
                 exception.GetType().ToString()
                 )
             );
         // errores generales
         Console.WriteLine("[GetDocumentsBySector] ->" + RestUtils.RESPONSE_INTERNAL_ERROR_MSG);
         response.Header.Message = RestUtils.RESPONSE_INTERNAL_ERROR_MSG;
         return(StatusCode(
                    StatusCodes.Status500InternalServerError,
                    response
                    ));
     }
 }
 public IActionResult GetDocumento(string docNumber)
 {
     try{
         // se validan headers
         if (docNumber == null || docNumber == "")
         {
             Console.WriteLine("[GetDocumento] -> Faltan parametros en la request");
             RestResponse responseErr = RestUtils.GenerateResponseErrorWith(
                 new ResponseError(
                     RestUtils.RESPONSE_BADREQUEST_CODE,
                     "Faltan parametros en la request"
                     )
                 );
             responseErr.Header.Message = RestUtils.RESPONSE_BADREQUEST_MSG;
             return(BadRequest(responseErr));
         }
         // se ejecuta busqueda
         Console.WriteLine("[GetDocumento] -> Buscar documento numero: " + docNumber);
         List <DocumentoDTO> result   = documentosService.FindDocumentoWith(docNumber);
         RestResponse        response = RestUtils.GenerateResponseOkEmpty();
         // se validan resultados
         if (result == null || result.Count() == 0)
         {
             Console.WriteLine("[GetDocumento] -> no hay resultados");
             response.Header.Message = RestUtils.RESPONSE_NOTFOUND_MSG;
             return(NotFound(response));
         }
         Console.WriteLine("[GetDocumento] -> request exitosa");
         foreach (DocumentoDTO d in result)
         {
             response.AddObjectToData(d);
         }
         return(Ok(response));
     } catch (Exception exception) {
         RestResponse response = RestUtils.GenerateResponseErrorWith(
             new ResponseError(
                 exception.Message,
                 exception.GetType().ToString()
                 )
             );
         // errores generales
         Console.WriteLine("[GetDocumento] ->" + RestUtils.RESPONSE_INTERNAL_ERROR_MSG);
         response.Header.Message = RestUtils.RESPONSE_INTERNAL_ERROR_MSG;
         return(StatusCode(
                    StatusCodes.Status500InternalServerError,
                    response
                    ));
     }
 }
 public IActionResult InsertDocumento(
     int?idEmpresa,
     int?idSector,
     [FromBody] DocumentoDTO body
     )
 {
     try{
         // se validan headers
         if (idEmpresa == null || idEmpresa.Value == 0 || idSector == null || idSector.Value == 0)
         {
             Console.WriteLine("[InsertDocumento] -> Falta 'idEmpresa' o 'idSector' en la request");
             RestResponse responseErr = RestUtils.GenerateResponseErrorWith(
                 new ResponseError(
                     RestUtils.RESPONSE_BADREQUEST_CODE,
                     "Falta 'idEmpresa' o 'idSector' en la request"
                     )
                 );
             responseErr.Header.Message = RestUtils.RESPONSE_BADREQUEST_MSG;
             return(BadRequest(responseErr));
         }
         Console.WriteLine("[InsertDocumento] -> request: " + body.ToString());
         // se valida body
         InputValidation(body);
         body = documentosService.AddNewDocument(body, idEmpresa.Value, idSector.Value);
         // se validan resultados
         if (body == null)
         {
             RestResponse responseErr = RestUtils.GenerateResponseErrorWith(
                 new ResponseError(
                     RestUtils.RESPONSE_INTERNAL_ERROR_MSG,
                     "Operacion fallida, no se completo proceso"
                     )
                 );
             responseErr.Header.Message = RestUtils.RESPONSE_ERROR_CODE;
             return(StatusCode(
                        StatusCodes.Status500InternalServerError,
                        responseErr
                        ));
         }
         RestResponse response = RestUtils.GenerateResponseOkEmpty();
         response.AddObjectToData(body);
         return(Ok(response));
     } catch (Exception exception) {
         RestResponse response = RestUtils.GenerateResponseErrorWith(
             new ResponseError(
                 exception.Message,
                 exception.GetType().ToString()
                 )
             );
         if (typeof(WrongInputException).IsInstanceOfType(exception))
         {
             Console.WriteLine("[InsertDocumento] ->" + exception.Message);
             response.Header.Message = exception.Message;
             return(StatusCode(
                        StatusCodes.Status400BadRequest,
                        response
                        ));
         }
         // errores generales
         Console.WriteLine("[InsertDocumento] ->" + RestUtils.RESPONSE_INTERNAL_ERROR_MSG);
         response.Header.Message = RestUtils.RESPONSE_INTERNAL_ERROR_MSG;
         return(StatusCode(
                    StatusCodes.Status500InternalServerError,
                    response
                    ));
     }
 }