public async Task <bool> AddItemAsync(cedula newItem, String correo, String telefono) { newItem.correo = correo; newItem.telefono = telefono; _context.Ced.Add(newItem); var saveResult = await _context.SaveChangesAsync(); return(saveResult == 1); }
public async Task <ActionResult> Añadir(String Cedula, String correo, String telefono) { cedula newItem = new cedula(); using (var client = new HttpClient()) { client.BaseAddress = new Uri(baseUrl); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("aplication/json")); HttpResponseMessage res = await client.GetAsync("api/test/consulta/" + Cedula); if (res.IsSuccessStatusCode) { string resp = res.Content.ReadAsStringAsync().Result; if (resp != "0") { newItem = JsonConvert.DeserializeObject <cedula>(resp); } else { return(RedirectToAction("NoExiste", "Cedula")); } } else { return(RedirectToAction("ErrorPage", "Cedula")); } } if (newItem.Ok != false) { if (!ModelState.IsValid) { return(RedirectToAction("Index")); } var successful = await cedulaServicies.AddItemAsync(newItem, correo, telefono); if (!successful) { return(BadRequest("No se ha podido añadir")); } } return(RedirectToAction("Index")); }