Пример #1
0
 public IActionResult DeleteEmpresaWith(int idEmpresa)
 {
     try{
         // validacion de parametro
         if (idEmpresa < 1)
         {
             Console.WriteLine("[DeleteEmpresaWith] -> idEmpresa invalido");
             return(BadRequest(
                        RestUtils.GenerateResponseErrorWith(
                            new ResponseError(RestUtils.RESPONSE_BADREQUEST_CODE, "idEmpresa invalido")
                            )
                        ));
         }
         Console.WriteLine("[DeleteEmpresaWith] -> se va a eliminar empresa con id: " + idEmpresa);
         EmpresaDTO result = empresasService.DeleteEmpresa(idEmpresa);
         if (result == null)
         {
             Console.WriteLine("[DeleteEmpresaWith] -> no se encontro empresa a eliminar");
             return(NotFound(
                        RestUtils.GenerateResponseErrorWith(
                            new ResponseError(RestUtils.RESPONSE_NOTFOUND_MSG, "No se encontro empresa con id " + idEmpresa)
                            )
                        ));
         }
         Console.WriteLine("[DeleteEmpresaWith] -> operacion exitosa");
         return(Ok(RestUtils.GenerateResponseOkWithData(result)));
     }catch (Exception exception) {
         Console.WriteLine("[UpdateEmpresa] -> " + 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
                    ));
     }
 }