public async Task <IActionResult> Create([Bind("IdValoracion,Valoracion,Comentario,IdUsuario,IdTienda")] data.ValoracionTienda valoracionTienda) { if (ModelState.IsValid) { using (var cl = new HttpClient()) { cl.BaseAddress = new Uri(baseurl); var content = JsonConvert.SerializeObject(valoracionTienda); var buffer = System.Text.Encoding.UTF8.GetBytes(content); var byteContent = new ByteArrayContent(buffer); byteContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); var postTask = cl.PostAsync("api/ValoracionTienda", byteContent).Result; if (postTask.IsSuccessStatusCode) { return(RedirectToAction(nameof(Index))); } } } ViewData["IdTienda"] = new SelectList(getAllTiendas(), "IdTienda", "DescripcionTienda", valoracionTienda.IdTienda); ViewData["IdUsuario"] = new SelectList(getAllAspNetUsers(), "Id", "Id", valoracionTienda.IdUsuario); return(View(valoracionTienda)); }
private data.ValoracionTienda GetById(int?id) { data.ValoracionTienda aux = new data.ValoracionTienda(); using (var cl = new HttpClient()) { cl.BaseAddress = new Uri(baseurl); cl.DefaultRequestHeaders.Clear(); cl.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage res = cl.GetAsync("api/ValoracionTienda/" + id).Result; if (res.IsSuccessStatusCode) { var auxres = res.Content.ReadAsStringAsync().Result; aux = JsonConvert.DeserializeObject <data.ValoracionTienda>(auxres); } } return(aux); }