// GET: Credits/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = httpClient.GetAsync("http://localhost:8081/Dari/servlet/banks/get").Result; if (response.IsSuccessStatusCode) { List <Bank> Banks = response.Content.ReadAsAsync <List <Bank> >().Result; List <SelectListItem> formulas = new List <SelectListItem>(); for (int i = 0; i < Banks.Count; i++) { int j = 0; for (j = 0; j < Banks.ElementAt(i).CreditFormulas.Count; j++) { formulas.Add(new SelectListItem { Value = Banks.ElementAt(i).CreditFormulas.ElementAt(j).id.ToString(), Text = Banks.ElementAt(i).CreditFormulas.ElementAt(j).afficher() }); } } var countrytip = new SelectListItem() { Value = null, Text = "--- select formula ---" }; formulas.Insert(0, countrytip); SelectList liste = new SelectList(formulas, "Value", "Text"); var credit = new CreditEditViewModel() { Formulas = liste, Id = (int)id }; return(View(credit)); } else { return(HttpNotFound()); } }
public ActionResult Edit([Bind(Include = "Id, SelectedFormulaId")] CreditEditViewModel c) { if (ModelState.IsValid) { Credit credit = new Credit(); credit.id = c.Id; CreditFormula CF = new CreditFormula(); CF.id = Int32.Parse(c.SelectedFormulaId); credit.creditformula = CF; HttpClient httpClient = new HttpClient(); httpClient.PostAsJsonAsync <CreditFormula>("http://localhost:8081/Dari/servlet/clients/" + a + "/credits/" + credit.id + "/modify", CF).ContinueWith(postTask => postTask.Result.EnsureSuccessStatusCode()); return(RedirectToAction("Index", new { client = a })); } return(View(c)); }