Exemplo n.º 1
0
        public HttpResponseMessage GetCotizacion(string id)
        {
            HttpResponseMessage Response = this.Request.CreateResponse(HttpStatusCode.OK);

            try
            {
                var moneda = monedas.FirstOrDefault((p) => p.Id.ToUpper() == id.ToUpper());
                if (moneda == null)
                {
                    Response.StatusCode = HttpStatusCode.NotFound;
                    return(Response);
                }

                Moneda monedaStrategy = new Moneda();

                string cotizacion = "";

                switch (id.ToUpper())
                {
                case "PESOS":
                    monedaStrategy.Pesos();
                    break;

                case "DOLAR":
                    monedaStrategy.Dolar();
                    break;

                case "REAL":
                    monedaStrategy.Real();
                    break;

                default:
                    break;
                }

                cotizacion = monedaStrategy.ObtenerCotizacion();

                Response.Content = new ObjectContent(typeof(String), cotizacion, JSONMediaFormatter, "application/json");

                return(Response);
            }
            catch (Exception ex)
            {
                if (ex.Message == "Unauthorized")
                {
                    Response.StatusCode = HttpStatusCode.Unauthorized;
                    //Response.Content = new ObjectContent(typeof(String), ex.Message, JSONMediaFormatter, "application/json");
                }
                return(Response);
            }
        }