public static Amigo ToAmigo(this AmigoDto dto)
 {
     return(new Amigo
     {
         FirstName = dto.FirstName,
         LastName = dto.LastName
     });
 }
Exemple #2
0
        // 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));
        }
Exemple #3
0
 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());
     }
 }
Exemple #4
0
 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());
     }
 }