/// <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); }
private void cargarFotoPermiso() { Thread t = new Thread(new ThreadStart(() => { ServerServiceVehiculo serverServiceVehiculo = new ServerServiceVehiculo(); ServerResponseImagenVehiculo serverResponseImagenVehiculo = serverServiceVehiculo.FindDocument( gestionVehiculoViewModel.vehiculo.nombreImagenPermiso); if (200 == serverResponseImagenVehiculo.error.code && null != serverResponseImagenVehiculo.imagenVehiculo) { Dispatcher.Invoke(new Action(() => { gestionVehiculoViewModel.imagenPermisoVehiculo = serverResponseImagenVehiculo.imagenVehiculo; })); } else { Dispatcher.Invoke(new Action(() => { txtPermiso.Text = ""; })); } })); t.Start(); }
private void cargarFoto(string imagen) { panel.IsEnabled = false; gestionMantenimientosViewModel.PanelLoading = true; Thread t = new Thread(new ThreadStart(() => { ServerServiceVehiculo serverServiceVehiculo = new ServerServiceVehiculo(); ServerResponseImagenVehiculo serverResponseImagenVehiculo = serverServiceVehiculo.FindDocument(imagen); if (200 == serverResponseImagenVehiculo.error.code && null != serverResponseImagenVehiculo.imagenVehiculo) { Dispatcher.Invoke(new Action(() => { gestionMantenimientosViewModel.imagenVehiculo = serverResponseImagenVehiculo.imagenVehiculo; })); Dispatcher.Invoke(new Action(() => { imgVehiculo.Source = (BitmapSource) new ImageSourceConverter().ConvertFrom(serverResponseImagenVehiculo.imagenVehiculo.documento); })); } Dispatcher.Invoke(new Action(() => { panel.IsEnabled = true; })); Dispatcher.Invoke(new Action(() => { gestionMantenimientosViewModel.PanelLoading = false; })); })); t.Start(); }
private void btnAceptar_Click(object sender, RoutedEventArgs e) { if (modo == Constantes.NUEVO) { var dialog = new CustomMessageBox { Caption = "Nuevo", InstructionHeading = "¿Está seguro que quiere guardar el vehiculo?", InstructionText = "Esta acción guardará la información del vehiculo", }; dialog.SetButtonsPredefined(EnumPredefinedButtons.OkCancel); var result = dialog.ShowDialog(); if (result.HasValue && result.Value && dialog.CustomCustomDialogResult == EnumDialogResults.Button1) { if (cambiosVehiculo()) { txtError.Text = ""; panel.IsEnabled = false; gestionVehiculoViewModel.PanelLoading = true; Thread t = new Thread(new ThreadStart(() => { ServerServiceVehiculo serverServiceVehiculo = new ServerServiceVehiculo(); ServerResponseVehiculo serverResponseVehiculo = serverServiceVehiculo.Save(vehiculoModif, "null"); if (200 == serverResponseVehiculo.error.code) { string msgErrorImg = null; if (null != imagenVehiculoModif) { imagenVehiculoModif.nombreImagen = vehiculoModif.nombreImagen; ServerResponseImagenVehiculo serverResponseImagenVehiculo = serverServiceVehiculo.SaveDocument(imagenVehiculoModif); if (200 != serverResponseImagenVehiculo.error.code && null != serverResponseImagenVehiculo.imagenVehiculo) { msgErrorImg = serverResponseImagenVehiculo.error.message; } } if (null != imagenPermisoVehiculoModif) { imagenPermisoVehiculoModif.nombreImagen = vehiculoModif.nombreImagenPermiso; ServerResponseImagenVehiculo serverResponseImagenVehiculo = serverServiceVehiculo.SaveDocument(imagenPermisoVehiculoModif); if (200 != serverResponseImagenVehiculo.error.code && null != serverResponseImagenVehiculo.imagenVehiculo) { msgErrorImg = serverResponseImagenVehiculo.error.message; } } if (null == msgErrorImg) { Dispatcher.Invoke(new Action(() => { mostrarAutoCloseMensaje("Nuevo", "Se ha guardado el vehiculo correctamente."); })); } else { Dispatcher.Invoke(new Action(() => { msgError(msgErrorImg); })); } Dispatcher.Invoke(new Action(() => { gestionVehiculoViewModel.vehiculo = vehiculoModif; })); Dispatcher.Invoke(new Action(() => { volver(); })); } else { Dispatcher.Invoke(new Action(() => { msgError(serverResponseVehiculo.error.message); })); } Dispatcher.Invoke(new Action(() => { panel.IsEnabled = true; })); Dispatcher.Invoke(new Action(() => { gestionVehiculoViewModel.PanelLoading = false; })); })); t.Start(); } } } else { var dialog = new CustomMessageBox { Caption = "Modificar", InstructionHeading = "¿Está seguro que quiere modificar el vehiculo?", InstructionText = "Esta acción modificará la información del vehiculo", }; dialog.SetButtonsPredefined(EnumPredefinedButtons.OkCancel); var result = dialog.ShowDialog(); if (result.HasValue && result.Value && dialog.CustomCustomDialogResult == EnumDialogResults.Button1) { if (cambiosVehiculo()) { txtError.Text = ""; panel.IsEnabled = false; gestionVehiculoViewModel.PanelLoading = true; Thread t = new Thread(new ThreadStart(() => { ServerServiceVehiculo serverServiceVehiculo = new ServerServiceVehiculo(); ServerResponseVehiculo serverResponseVehiculo = serverServiceVehiculo.Save(vehiculoModif, vehiculoModif.id); if (200 == serverResponseVehiculo.error.code) { string msgErrorImg = null; if (null != imagenVehiculoModif) { imagenVehiculoModif.nombreImagen = vehiculoModif.nombreImagen; ServerResponseImagenVehiculo serverResponseImagenVehiculo = serverServiceVehiculo.SaveDocument(imagenVehiculoModif); if (200 != serverResponseImagenVehiculo.error.code && null != serverResponseImagenVehiculo.imagenVehiculo) { msgErrorImg = serverResponseImagenVehiculo.error.message; } } if (null != imagenPermisoVehiculoModif) { imagenPermisoVehiculoModif.nombreImagen = vehiculoModif.nombreImagenPermiso; ServerResponseImagenVehiculo serverResponseImagenVehiculo = serverServiceVehiculo.SaveDocument(imagenPermisoVehiculoModif); if (200 != serverResponseImagenVehiculo.error.code && null != serverResponseImagenVehiculo.imagenVehiculo) { msgErrorImg = serverResponseImagenVehiculo.error.message; } } if (null == msgErrorImg) { Dispatcher.Invoke(new Action(() => { mostrarAutoCloseMensaje("Modificar", "Se ha modificado el vehiculo correctamente."); })); } else { Dispatcher.Invoke(new Action(() => { msgError(msgErrorImg); })); } Dispatcher.Invoke(new Action(() => { gestionVehiculoViewModel.vehiculo = vehiculoModif; })); Dispatcher.Invoke(new Action(() => { volver(); })); } else { Dispatcher.Invoke(new Action(() => { msgError(serverResponseVehiculo.error.message); })); } Dispatcher.Invoke(new Action(() => { panel.IsEnabled = true; })); Dispatcher.Invoke(new Action(() => { gestionVehiculoViewModel.PanelLoading = false; })); })); t.Start(); } } } }