// GET: Car/Delete/5 public async Task <ActionResult> Delete(string id) { //return View(await GetCarDetails(id)); List <Model> modelList = null; List <SelectListItem> getmodelformList = new List <SelectListItem>(); EditCarForm temp = new EditCarForm(); temp = await GetCarDetails(id); DeleteCarForm model = new DeleteCarForm { ChassisNumber = temp.ChassisNumber, ChassisType = temp.ChassisType, IdCar = temp.IdCar, IdModel = temp.IdModel, Location = temp.Location, Mileage = temp.Mileage, ModelName = temp.ModelName, Version = temp.Version, Year = temp.Year }; 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"); if (Res.IsSuccessStatusCode) { var EmpResponse = Res.Content.ReadAsStringAsync().Result; modelList = JsonConvert.DeserializeObject <List <Model> >(EmpResponse); } foreach (Model Model in modelList) { getmodelformList.Add(new SelectListItem { Selected = (Model.IdModel == model.IdModel), Text = Model.Name, Value = Model.IdModel.ToString() }); } } model.ModelName = (from b in getmodelformList orderby b.Text where b.Value == model.IdModel.ToString() select b.Text).FirstOrDefault(); return(View(model)); }
public async Task <ActionResult> Delete(int id, [Bind] DeleteCarForm formulaire) { if (ModelState.IsValid) { 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.DeleteAsync($"Car/Delete/{id}"); if (!Res.IsSuccessStatusCode) /*error handling*/ } { } return(RedirectToAction("Index")); } else { return(View()); } }
private void delCarBtn_Click(object sender, EventArgs e) { DeleteCarForm showCarForm = new DeleteCarForm(); showCarForm.Show(); }