/// <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); }
public InicioView() { InitializeComponent(); inicioViewModel = (InicioViewModel)this.DataContext; panel.IsEnabled = false; inicioViewModel.PanelLoading = true; cmbTipo.ItemsSource = inicioViewModel.observableCollectionTipoAlerta; Thread t = new Thread(new ThreadStart(() => { Dispatcher.Invoke(new Action(() => { inicioViewModel.cargaCombo(); })); ServerServiceAlerta serverServiceAlerta = new ServerServiceAlerta(); ServerResponseAlerta serverResponseAlerta = serverServiceAlerta.GetAll(); if (200 == serverResponseAlerta.error.code) { foreach (var item in serverResponseAlerta.listaAlerta) { if (7 >= item.vencimiento) { item.urlImage = "/Images/ico_rojo.png"; } else { item.urlImage = "/Images/ico_amarillo.png"; } Dispatcher.Invoke(new Action(() => { observableCollectionAlerta.Add(item); })); } } else { Dispatcher.Invoke(new Action(() => { msgError(serverResponseAlerta.error.message); })); } Dispatcher.Invoke(new Action(() => { panel.IsEnabled = true; })); Dispatcher.Invoke(new Action(() => { inicioViewModel.PanelLoading = false; })); Dispatcher.Invoke(new Action(() => { lstAle.ItemsSource = observableCollectionAlerta; })); })); t.Start(); }
/** *------------------------------------------------------------------------------ * Metodos para controlar los botones *------------------------------------------------------------------------------ **/ private void btnBuscar_Click(object sender, RoutedEventArgs e) { panel.IsEnabled = false; inicioViewModel.PanelLoading = true; Object selectedTipo = cmbTipo.SelectedItem; string tipo = "null"; string cliente = "null"; string matricula = "null"; if (null != selectedTipo && 0 < cmbTipo.SelectedIndex) { tipo = selectedTipo.ToString(); foreach (var item in inicioViewModel.ListaTipoAlerta) { if (item.nombre.Equals(tipo)) { tipo = item.id; } } } if (!txtCliente.Text.Equals("")) { cliente = txtCliente.Text.ToString(); } if (!txtMatricula.Text.Equals("")) { matricula = txtMatricula.Text.ToString(); } Thread t = new Thread(new ThreadStart(() => { ServerServiceAlerta serverServiceAlerta = new ServerServiceAlerta(); ServerResponseAlerta serverResponseAlerta = serverServiceAlerta.GetAllFilter(tipo, cliente, matricula); if (200 == serverResponseAlerta.error.code) { //Limpiar la lista para recuperar la informacion de la busqueda Dispatcher.Invoke(new Action(() => { observableCollectionAlerta.Clear(); })); foreach (var item in serverResponseAlerta.listaAlerta) { if (7 >= item.vencimiento) { item.urlImage = "/Images/ico_rojo.png"; } else { item.urlImage = "/Images/ico_amarillo.png"; } Dispatcher.Invoke(new Action(() => { observableCollectionAlerta.Add(item); })); } } else { Dispatcher.Invoke(new Action(() => { msgError(serverResponseAlerta.error.message); })); } Dispatcher.Invoke(new Action(() => { panel.IsEnabled = true; })); Dispatcher.Invoke(new Action(() => { inicioViewModel.PanelLoading = false; })); Dispatcher.Invoke(new Action(() => { lstAle.ItemsSource = observableCollectionAlerta; })); })); t.Start(); }