/// <summary> /// Guarda o modifica la imagen /// </summary> /// <param name="imagenVehiculo"></param> /// <returns>ServerResponseImagenVehiculo</returns> public ServerResponseImagenVehiculo SaveDocument(ImagenVehiculo imagenVehiculo) { ServerResponseImagenVehiculo serverResponseImagenVehiculo = null; try { OauthToken oauthToken = ServerService.obtenerToken(); if (null != oauthToken) { var url = Constantes.SERVIDOR + VEHICULO + "savedoc"; var httpRequest = (HttpWebRequest)WebRequest.Create(url); httpRequest.Method = "POST"; httpRequest.Headers["Authorization"] = "Bearer " + oauthToken.access_token; httpRequest.ContentType = "application/json"; var data = JsonSerializer.Serialize <ImagenVehiculo>(imagenVehiculo); using (var streamWriter = new StreamWriter(httpRequest.GetRequestStream())) { streamWriter.Write(data); } var httpResponse = (HttpWebResponse)httpRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); serverResponseImagenVehiculo = JsonSerializer.Deserialize <ServerResponseImagenVehiculo>(result); } //Console.WriteLine(httpResponse.StatusCode); } else { serverResponseImagenVehiculo = new ServerResponseImagenVehiculo(); ErrorBean error = new ErrorBean(); error.code = MessageExceptions.SERVER_ERROR; error.message = MessageExceptions.MSSG_SERVER_ERROR; serverResponseImagenVehiculo.error = error; } } catch (System.Exception) { serverResponseImagenVehiculo = new ServerResponseImagenVehiculo(); ErrorBean error = new ErrorBean(); error.code = MessageExceptions.SERVER_ERROR; error.message = MessageExceptions.MSSG_SERVER_ERROR; serverResponseImagenVehiculo.error = error; } return(serverResponseImagenVehiculo); }
/// <summary> /// Devuelve todos los datos /// </summary> /// <returns>ServerResponseAlerta</returns> public ServerResponseAlerta GetAll() { ServerResponseAlerta serverResponseAlerta; try { OauthToken oauthToken = ServerService.obtenerToken(); if (null != oauthToken) { var url = Constantes.SERVIDOR + ALERTA + "all"; var httpRequest = (HttpWebRequest)WebRequest.Create(url); httpRequest.Method = "GET"; httpRequest.Accept = "application/json"; httpRequest.Headers["Authorization"] = "Bearer " + oauthToken.access_token; var httpResponse = (HttpWebResponse)httpRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); serverResponseAlerta = JsonSerializer.Deserialize <ServerResponseAlerta>(result); } //Console.WriteLine(httpResponse.StatusCode); } else { serverResponseAlerta = new ServerResponseAlerta(); ErrorBean error = new ErrorBean(); error.code = MessageExceptions.SERVER_ERROR; error.message = MessageExceptions.MSSG_SERVER_ERROR; serverResponseAlerta.error = error; } } catch (System.Exception) { serverResponseAlerta = new ServerResponseAlerta(); ErrorBean error = new ErrorBean(); error.code = MessageExceptions.SERVER_ERROR; error.message = MessageExceptions.MSSG_SERVER_ERROR; serverResponseAlerta.error = error; } return(serverResponseAlerta); }
/// <summary> /// Devuelve los datos con los filtros: matricula, plazas, capacidad y dispoiblilidad /// </summary> /// <param name="matricula"></param> /// <param name="plazas"></param> /// <param name="capacidad"></param> /// <param name="dispoiblilidad"></param> /// <returns>ServerResponseAlerta</returns> public ServerResponseVehiculo GetAllFilter(string matricula, string plazas, string capacidad, string dispoiblilidad) { ServerResponseVehiculo serverResponseVehiculo; try { OauthToken oauthToken = ServerService.obtenerToken(); if (null != oauthToken) { var url = Constantes.SERVIDOR + VEHICULO + "allFilter/" + matricula + "/" + plazas + "/" + capacidad + "/" + dispoiblilidad; var httpRequest = (HttpWebRequest)WebRequest.Create(url); httpRequest.Method = "GET"; httpRequest.Accept = "application/json"; httpRequest.Headers["Authorization"] = "Bearer " + oauthToken.access_token; var httpResponse = (HttpWebResponse)httpRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); serverResponseVehiculo = JsonSerializer.Deserialize <ServerResponseVehiculo>(result); } //Console.WriteLine(httpResponse.StatusCode); } else { serverResponseVehiculo = new ServerResponseVehiculo(); ErrorBean error = new ErrorBean(); error.code = MessageExceptions.SERVER_ERROR; error.message = MessageExceptions.MSSG_SERVER_ERROR; serverResponseVehiculo.error = error; } } catch (System.Exception) { serverResponseVehiculo = new ServerResponseVehiculo(); ErrorBean error = new ErrorBean(); error.code = MessageExceptions.SERVER_ERROR; error.message = MessageExceptions.MSSG_SERVER_ERROR; serverResponseVehiculo.error = error; } return(serverResponseVehiculo); }
/// <summary> /// Devuelve los datos con los filtros: Nombre, Email y Rol /// </summary> /// <param name="nombre"></param> /// <param name="email"></param> /// <param name="rol"></param> /// <returns>ServerResponseUsuario</returns> public ServerResponseUsuario GetAllFilter(string nombre, string email, string rol) { ServerResponseUsuario serverResponseUsuario; try { OauthToken oauthToken = ServerService.obtenerToken(); if (null != oauthToken) { var url = Constantes.SERVIDOR + USUARIO + "allFilter/" + nombre + "/" + email + "/" + rol; var httpRequest = (HttpWebRequest)WebRequest.Create(url); httpRequest.Method = "GET"; httpRequest.Accept = "application/json"; httpRequest.Headers["Authorization"] = "Bearer " + oauthToken.access_token; var httpResponse = (HttpWebResponse)httpRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); serverResponseUsuario = JsonSerializer.Deserialize <ServerResponseUsuario>(result); } //Console.WriteLine(httpResponse.StatusCode); } else { serverResponseUsuario = new ServerResponseUsuario(); ErrorBean error = new ErrorBean(); error.code = MessageExceptions.SERVER_ERROR; error.message = MessageExceptions.MSSG_SERVER_ERROR; serverResponseUsuario.error = error; } } catch (System.Exception) { serverResponseUsuario = new ServerResponseUsuario(); ErrorBean error = new ErrorBean(); error.code = MessageExceptions.SERVER_ERROR; error.message = MessageExceptions.MSSG_SERVER_ERROR; serverResponseUsuario.error = error; } return(serverResponseUsuario); }
public static String errorDescripctionToJSON(Exception ex) { String strUrl = HttpContext.Current.Request.Url.ToString(); String strSource = ex.Source; String strMessage = ex.Message; String strStack = ExceptionUtils.GenerateFormattedStackTrace(ExceptionUtils.GenerateExceptionStack(ex)).Trim(); JavaScriptSerializer js = new JavaScriptSerializer(); ErrorBean errorBean = new ErrorBean(); errorBean.url = strUrl; errorBean.source = strSource; errorBean.message = strMessage; errorBean.stack = strStack; return(js.Serialize(errorBean)); }
/// <summary> /// Con el id "null" guarda un nuevo objeto y, en caso contrario, modifica el objeto de la BD /// </summary> /// <param name="caducidad">objeto de BD</param> /// <param name="id"></param> /// <returns>ServerResponseCaducidad</returns> public ServerResponseCaducidad Save(CaducidadDTO caducidadDTO, string id) { ServerResponseCaducidad serverResponseCaducidad; try { OauthToken oauthToken = ServerService.obtenerToken(); if (null != oauthToken) { var url = Constantes.SERVIDOR + CADUCIDAD + "save/" + id; var httpRequest = (HttpWebRequest)WebRequest.Create(url); httpRequest.Method = "POST"; httpRequest.Headers["Authorization"] = "Bearer " + oauthToken.access_token; httpRequest.ContentType = "application/json"; Caducidad caducidad = transformCaducidadDTOToCaducidad(caducidadDTO); if (null != caducidad) { var data = JsonSerializer.Serialize <Caducidad>(caducidad); using (var streamWriter = new StreamWriter(httpRequest.GetRequestStream())) { streamWriter.Write(data); } var httpResponse = (HttpWebResponse)httpRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); serverResponseCaducidad = JsonSerializer.Deserialize <ServerResponseCaducidad>(result); } //Console.WriteLine(httpResponse.StatusCode); } else { serverResponseCaducidad = new ServerResponseCaducidad(); ErrorBean error = new ErrorBean(); error.code = MessageExceptions.SERVER_ERROR; error.message = MessageExceptions.MSSG_SERVER_ERROR; serverResponseCaducidad.error = error; } } else { serverResponseCaducidad = new ServerResponseCaducidad(); ErrorBean error = new ErrorBean(); error.code = MessageExceptions.SERVER_ERROR; error.message = MessageExceptions.MSSG_SERVER_ERROR; serverResponseCaducidad.error = error; } } catch (System.Exception) { serverResponseCaducidad = new ServerResponseCaducidad(); ErrorBean error = new ErrorBean(); error.code = MessageExceptions.SERVER_ERROR; error.message = MessageExceptions.MSSG_SERVER_ERROR; serverResponseCaducidad.error = error; } return(serverResponseCaducidad); }
/// <summary> /// Con el id "null" guarda un nuevo objeto y, en caso contrario, modifica el objeto de la BD /// </summary> /// <param name="mantenimientoDTO">objeto de BD</param> /// <param name="id"></param> /// <returns>ServerResponseMantenimiento</returns> public ServerResponseMantenimiento Save(MantenimientoDTO mantenimientoDTO, string id) { ServerResponseMantenimiento serverResponseMantenimiento; try { OauthToken oauthToken = ServerService.obtenerToken(); if (null != oauthToken) { var url = Constantes.SERVIDOR + MANTENIMIENTO + "save/" + id; var httpRequest = (HttpWebRequest)WebRequest.Create(url); httpRequest.Method = "POST"; httpRequest.Headers["Authorization"] = "Bearer " + oauthToken.access_token; httpRequest.ContentType = "application/json"; Mantenimiento mantenimiento = transformMantenimientoDTOToMantenimiento(mantenimientoDTO); if (null != mantenimiento) { var data = JsonSerializer.Serialize <Mantenimiento>(mantenimiento); using (var streamWriter = new StreamWriter(httpRequest.GetRequestStream())) { streamWriter.Write(data); } var httpResponse = (HttpWebResponse)httpRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); serverResponseMantenimiento = JsonSerializer.Deserialize <ServerResponseMantenimiento>(result); } //Console.WriteLine(httpResponse.StatusCode); } else { serverResponseMantenimiento = new ServerResponseMantenimiento(); ErrorBean error = new ErrorBean(); error.code = MessageExceptions.SERVER_ERROR; error.message = MessageExceptions.MSSG_SERVER_ERROR; serverResponseMantenimiento.error = error; } } else { serverResponseMantenimiento = new ServerResponseMantenimiento(); ErrorBean error = new ErrorBean(); error.code = MessageExceptions.SERVER_ERROR; error.message = MessageExceptions.MSSG_SERVER_ERROR; serverResponseMantenimiento.error = error; } } catch (System.Exception) { serverResponseMantenimiento = new ServerResponseMantenimiento(); ErrorBean error = new ErrorBean(); error.code = MessageExceptions.SERVER_ERROR; error.message = MessageExceptions.MSSG_SERVER_ERROR; serverResponseMantenimiento.error = error; } return(serverResponseMantenimiento); }