public async Task <ActionResult> Edit(int id, [Bind] EditBuyerForm formulaire) { if (ModelState.IsValid) { Buyer buyer = new Buyer { IdBuyer = id, FirstName = formulaire.FirstName, LastName = formulaire.LastName, Email = formulaire.Email, Phone = formulaire.Phone, Street = formulaire.Street, Number = formulaire.Number.ToString(), Zip = formulaire.Zip, Locality = formulaire.Locality, Country = formulaire.Country, Account = formulaire.Account }; using (var client = new HttpClient()) { client.BaseAddress = new Uri(Baseurl); client.DefaultRequestHeaders.Clear(); StringContent content = new StringContent(JsonConvert.SerializeObject(buyer)); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpResponseMessage Res = await client.PutAsync($"Buyer/Update", content); if (!Res.IsSuccessStatusCode) /*error handling*/ { } } return(RedirectToAction("Index")); } else { return(View(formulaire)); } }
public async Task <EditBuyerForm> GetDetails(string id) { Buyer ModelGlobal = default(Buyer); EditBuyerForm ModelLocal = default(EditBuyerForm); using (var client = new HttpClient()) { client.BaseAddress = new Uri(Baseurl); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage Res = await client.GetAsync($"Buyer/Get/{id}"); if (Res.IsSuccessStatusCode) { var EmpResponse = Res.Content.ReadAsStringAsync().Result; ModelGlobal = JsonConvert.DeserializeObject <Buyer>(EmpResponse); ModelLocal = AutoMapper <Buyer, EditBuyerForm> .AutoMap(ModelGlobal); } } return(ModelLocal); }