public async Task <ActionResult> Edit(int id, [Bind] EditModelForm formulaire) { if (ModelState.IsValid) { Model model = new Model { IdModel = id, IdBrand = Convert.ToInt32(formulaire.BrandName), Name = formulaire.Name }; using (var client = new HttpClient()) { client.BaseAddress = new Uri(Baseurl); client.DefaultRequestHeaders.Clear(); StringContent content = new StringContent(JsonConvert.SerializeObject(model)); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpResponseMessage Res = await client.PutAsync($"Model/Update", content); if (!Res.IsSuccessStatusCode) /*error handling*/ } { } return(RedirectToAction("Index")); } else { return(View()); } }
// GET: Model/Edit/5 public async Task <ActionResult> Edit(string id) { List <SelectListItem> getbrandformList = new List <SelectListItem>(); List <GetBrandForm> getbrandList = await BrandController.GetBrandList(); EditModelForm model = new EditModelForm(); model = await GetDetails(id); foreach (GetBrandForm Brand in getbrandList) { getbrandformList.Add(new SelectListItem { Text = Brand.Name, Value = Brand.IdBrand.ToString() } ); } model.BrandList = getbrandformList; return(View(model)); }
public async Task <EditModelForm> GetDetails(string id) { Model ModelGlobal = default(Model); EditModelForm ModelLocal = default(EditModelForm); 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($"Model/Get/{id}"); if (Res.IsSuccessStatusCode) { var EmpResponse = Res.Content.ReadAsStringAsync().Result; ModelGlobal = JsonConvert.DeserializeObject <Model>(EmpResponse); ModelLocal = AutoMapper <Model, EditModelForm> .AutoMap(ModelGlobal); } } return(ModelLocal); }