/// <summary> /// Devuelve todos los datos /// </summary> /// <returns>ServerResponseRol</returns> public ServerResponseRol GetAll() { ServerResponseRol serverResponseRol; try { OauthToken oauthToken = ServerService.obtenerToken(); if (null != oauthToken) { var url = Constantes.SERVIDOR + ROL + "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(); serverResponseRol = JsonSerializer.Deserialize <ServerResponseRol>(result); } //Console.WriteLine(httpResponse.StatusCode); } else { serverResponseRol = new ServerResponseRol(); ErrorBean error = new ErrorBean(); error.code = MessageExceptions.SERVER_ERROR; error.message = MessageExceptions.MSSG_SERVER_ERROR; serverResponseRol.error = error; } } catch (System.Exception) { serverResponseRol = new ServerResponseRol(); ErrorBean error = new ErrorBean(); error.code = MessageExceptions.SERVER_ERROR; error.message = MessageExceptions.MSSG_SERVER_ERROR; serverResponseRol.error = error; } return(serverResponseRol); }
public void cargaCombo() { if (null == _listaRol) { Thread t = new Thread(new ThreadStart(() => { observableCollectionRol.Add("Seleccionar"); ServerServiceRol serverServiceRol = new ServerServiceRol(); ServerResponseRol serverResponseRol = serverServiceRol.GetAll(); if (200 == serverResponseRol.error.code) { _listaRol = serverResponseRol.listaRol; foreach (var item in serverResponseRol.listaRol) { observableCollectionRol.Add(item.nombre); } } else { observableCollectionRol.Add("Seleccionar"); } })); t.Start(); } else { observableCollectionRol.Add("Seleccionar"); foreach (var item in _listaRol) { observableCollectionRol.Add(item.nombre); } } }