public static Amigo ToAmigo(this AmigoDto dto) { return(new Amigo { FirstName = dto.FirstName, LastName = dto.LastName }); }
// GET: Amigo/Edit/5 public ActionResult Edit(int id) { HttpResponseMessage response = client.GetAsync($"/api/amigos/{id}").Result; AmigoDto amigo = response.Content.ReadAsAsync <AmigoDto>().Result; if (amigo == null) { return(HttpNotFound()); } return(View(amigo)); }
public ActionResult Edit(int id, AmigoDto amigo) { try { HttpResponseMessage response = client.PutAsJsonAsync <AmigoDto>($"/api/amigos/{id}", amigo).Result; if (response.StatusCode == HttpStatusCode.NoContent) { return(RedirectToAction("Index")); } else { ViewBag.Error = "Error while editing the note"; return(View()); } } catch { return(View()); } }
public ActionResult Create(AmigoDto amigoDto) { try { HttpResponseMessage response = client.PostAsJsonAsync <AmigoDto>("/api/amigos", amigoDto).Result; if (response.StatusCode == HttpStatusCode.Created) { return(RedirectToAction("Index")); } else { ViewBag.Error = "Error while creating"; return(View()); } } catch { return(View()); } }