Exemplo n.º 1
0
        private UbicacionCLS GetUbicacion(int id)
        {
            HttpClient httpClient = new HttpClient();

            httpClient.BaseAddress = new Uri(baseURL);
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session["token"].ToString());

            HttpResponseMessage response = httpClient.GetAsync($"api/Ubicacions/{id}").Result;
            string       data            = response.Content.ReadAsStringAsync().Result;
            UbicacionCLS item            = JsonConvert.DeserializeObject <UbicacionCLS>(data);

            return(item);
        }
Exemplo n.º 2
0
        public ActionResult DetailUbicacion(int id)
        {
            GetInidcadores();

            var item = GetUbicacion(id);

            UbicacionCLS ubicaicon = new UbicacionCLS();

            ubicaicon.IdUbicacion = item.IdUbicacion;
            ubicaicon.Nombre      = item.Nombre;
            ubicaicon.Tipo        = item.Tipo;

            return(View(ubicaicon));
        }
Exemplo n.º 3
0
        public ActionResult Eliminar(UbicacionCLS oUbicacion)
        {
            HttpClient httpClient = new HttpClient();

            httpClient.BaseAddress = new Uri(baseURL);
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session["token"].ToString());

            HttpResponseMessage response = httpClient.DeleteAsync($"api/Ubicacions/{oUbicacion.IdUbicacion}").Result;

            if (response.IsSuccessStatusCode)
            {
                return(RedirectToAction("Index"));
            }

            throw new Exception("Error al eliminar");
        }
Exemplo n.º 4
0
        public ActionResult Guardar(string Nombre, string Tipo)
        {
            try
            {
                UbicacionCLS ubicaicon = new UbicacionCLS();

                ubicaicon.IdUbicacion = 0;
                ubicaicon.Nombre      = Nombre;
                ubicaicon.Tipo        = Tipo;

                HttpClient httpClient = new HttpClient();
                httpClient.BaseAddress = new Uri(baseURL);
                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", HttpContext.Session["token"].ToString());

                string      clienteJson = JsonConvert.SerializeObject(ubicaicon);
                HttpContent body        = new StringContent(clienteJson, Encoding.UTF8, "application/json");


                HttpResponseMessage response = httpClient.PostAsync("api/Ubicacions", body).Result;
                if (response.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Index"));
                }


                throw new Exception("Error al guardar");
            }

            catch (Exception ex)
            {
                return(Json(
                           new
                {
                    success = false,
                    message = ex.InnerException
                }, JsonRequestBehavior.AllowGet));
            }
        }