public async Task <IActionResult> Create([Bind("Isbn,Titulo,Autor,Sinopsis,Descontinuado,Paginas,Revision,Ano,Precio,Stock,Ideditorial,Idpais,Idcategoria,Imagen")] MtoCatLibros libro) { //"api/MtoCatLibros" HttpClient cliente = _api.Initial(); HttpResponseMessage res; if (ModelState.IsValid) { var resultado = await cliente.PostAsJsonAsync <MtoCatLibros>("api/MtoCatLibros", libro); } return(View()); }
public static async Task <HttpResponseMessage> ActualizarLibro(MtoCatLibros libro) { await RunAsync(); var miContenido = JsonConvert.SerializeObject(libro); var buffer = System.Text.Encoding.UTF8.GetBytes(miContenido); var byteContent = new ByteArrayContent(buffer); byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var response = client.PutAsync($"api/MtoCatLibros/{ libro.Idlibro}", byteContent).Result; // return URI of the created resource. return(response); }
public async Task <IActionResult> Create([Bind("Idlibro,Isbn,Titulo,Autor,Sinopsis,Descontinuado,Paginas,Revision,Ano,Precio,Stock,Ideditorial,Idpais,Idcategoria,Imagen")] MtoCatLibros libro) { //"api/MtoCatLibros" HttpResponseMessage res; if (ModelState.IsValid) { var myContent = JsonConvert.SerializeObject(libro); var buffer = System.Text.Encoding.UTF8.GetBytes(myContent); var byteContent = new ByteArrayContent(buffer); var resultado = await cliente.PutAsJsonAsync <MtoCatLibros>($"https://localhost:44341/api/MtoCatLibros/" + libro.Idlibro, libro); if (!resultado.IsSuccessStatusCode) { return(Redirect("~/Error/Error")); } } return(Redirect("~/TodosLibros/DevolverLista")); }