public ActionResult Create(int?asset, [Bind(Include = "SelectedPackId")] InsuranceNewViewModel ins) { if (ModelState.IsValid) { Insurance insurance = new Insurance(); Pack CF = new Pack(); CF.id = Int32.Parse(ins.SelectedPackId); insurance.Pack = CF; HttpClient httpClient = new HttpClient(); httpClient.PostAsJsonAsync <Pack>("http://localhost:8081/Dari/servlet/client/" + a + "/boughtassets/" + asset + "/addinsurance", CF).ContinueWith(postTask => postTask.Result.EnsureSuccessStatusCode()); return(RedirectToAction("Index", new { client = a })); } return(View(ins)); }
// GET: Insurances/Create public ActionResult Create() { HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = httpClient.GetAsync("http://localhost:8081/Dari/servlet/insuranceagencies/get").Result; if (response.IsSuccessStatusCode) { List <InsuranceAgency> Agencies = response.Content.ReadAsAsync <List <InsuranceAgency> >().Result; List <SelectListItem> packs = new List <SelectListItem>(); for (int i = 0; i < Agencies.Count; i++) { int j = 0; for (j = 0; j < Agencies.ElementAt(i).packs.Count; j++) { packs.Add(new SelectListItem { Value = Agencies.ElementAt(i).packs.ElementAt(j).id.ToString(), Text = Agencies.ElementAt(i).packs.ElementAt(j).afficher() }); } } var countrytip = new SelectListItem() { Value = null, Text = "--- select pack ---" }; packs.Insert(0, countrytip); SelectList liste = new SelectList(packs, "Value", "Text"); var insurance = new InsuranceNewViewModel() { Packs = liste }; return(View(insurance)); } else { ViewBag.result = "error"; return(View(new List <Insurance>())); } }