/// <summary>
        /// Devuelve todos los datos
        /// </summary>
        /// <returns>ServerResponseTipoAlerta</returns>
        public ServerResponseTipoAlerta GetAll()
        {
            ServerResponseTipoAlerta serverResponseTipoAlerta;

            try
            {
                OauthToken oauthToken = ServerService.obtenerToken();

                if (null != oauthToken)
                {
                    var url = Constantes.SERVIDOR + TIPO_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();

                        serverResponseTipoAlerta = JsonSerializer.Deserialize <ServerResponseTipoAlerta>(result);
                    }

                    //Console.WriteLine(httpResponse.StatusCode);
                }
                else
                {
                    serverResponseTipoAlerta = new ServerResponseTipoAlerta();

                    ErrorBean error = new ErrorBean();
                    error.code    = MessageExceptions.SERVER_ERROR;
                    error.message = MessageExceptions.MSSG_SERVER_ERROR;

                    serverResponseTipoAlerta.error = error;
                }
            }
            catch (System.Exception)
            {
                serverResponseTipoAlerta = new ServerResponseTipoAlerta();

                ErrorBean error = new ErrorBean();
                error.code    = MessageExceptions.SERVER_ERROR;
                error.message = MessageExceptions.MSSG_SERVER_ERROR;

                serverResponseTipoAlerta.error = error;
            }

            return(serverResponseTipoAlerta);
        }
Esempio n. 2
0
        public void cargaCombo()
        {
            if (null == _listaTipoAlerta)
            {
                Thread t = new Thread(new ThreadStart(() =>
                {
                    observableCollectionTipoAlerta.Add("Seleccionar");

                    ServerServiceTipoAlerta serverServiceTipoAlerta   = new ServerServiceTipoAlerta();
                    ServerResponseTipoAlerta serverResponseTipoAlerta = serverServiceTipoAlerta.GetAll();

                    if (200 == serverResponseTipoAlerta.error.code)
                    {
                        _listaTipoAlerta = serverResponseTipoAlerta.listaTipoAlerta;

                        foreach (var item in serverResponseTipoAlerta.listaTipoAlerta)
                        {
                            observableCollectionTipoAlerta.Add(item.nombre);
                        }
                    }
                    else
                    {
                        observableCollectionTipoAlerta.Add("Seleccionar");
                    }
                }));

                t.Start();
            }
            else
            {
                observableCollectionTipoAlerta.Add("Seleccionar");

                foreach (var item in _listaTipoAlerta)
                {
                    observableCollectionTipoAlerta.Add(item.nombre);
                }
            }
        }