// 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)); }
private void bt_edit_Click(object sender, EventArgs e) { if (DataGrid_cars.Rows.Count > 0) { RentalCar rentalCar = new RentalCar() { Available = (bool)(DataGrid_cars.SelectedRows[0]).Cells[0].Value, AvailableFrom = (DateTime)(DataGrid_cars.SelectedRows[0]).Cells[1].Value, PricePerDay = (int)(DataGrid_cars.SelectedRows[0]).Cells[2].Value, Brand = (string)(DataGrid_cars.SelectedRows[0]).Cells[3].Value, Model = (string)(DataGrid_cars.SelectedRows[0]).Cells[4].Value, LicensePlate = (string)(DataGrid_cars.SelectedRows[0]).Cells[5].Value, Type = (string)(DataGrid_cars.SelectedRows[0]).Cells[6].Value, }; if (rentalCar.Available) { int index = 0; for (int i = 0; i < cars.Count; i++) { if (cars[i].LicensePlate == rentalCar.LicensePlate) { index = i; break; } } RentalCar editing_car = cars[index]; EditCarForm editCarForm = new EditCarForm(editing_car, cars, DataGrid_cars, pnCarsMenu); editCarForm.TopLevel = false; editCarForm.Dock = DockStyle.Fill; pnChildForm.Controls.Add(editCarForm); editCarForm.BringToFront(); pnChildForm.BringToFront(); editCarForm.Show(); } else { MsgBox msgBox = new MsgBox("Editing error", "The selected car is not available"); msgBox.ShowDialog(); } } else { MsgBox msgBox = new MsgBox("Editing error", "You have not chosen the car you want to rent"); msgBox.ShowDialog(); } }
public async Task <ActionResult> Edit(int id, [Bind] EditCarForm formulaire) { if (ModelState.IsValid) { Car car = new Car { IdCar = formulaire.IdCar, ChassisNumber = formulaire.ChassisNumber, IdModel = Convert.ToInt32(formulaire.ModelName), Version = formulaire.Version, Year = formulaire.Year, ChassisType = formulaire.ChassisType, Condition = formulaire.Condition, Mileage = formulaire.Mileage, Power = formulaire.Power, Cylinder = formulaire.Cylinder, Location = formulaire.Location, Fuel = formulaire.Fuel, Transmition = formulaire.Transmition, Color = formulaire.Color, MetalPainting = formulaire.MetalPainting, ServiceBook = formulaire.ServiceBook, LeftHand = formulaire.LeftHand }; using (var client = new HttpClient()) { client.BaseAddress = new Uri(Baseurl); client.DefaultRequestHeaders.Clear(); StringContent content = new StringContent(JsonConvert.SerializeObject(car)); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpResponseMessage Res = await client.PutAsync($"Car/Update", content); if (!Res.IsSuccessStatusCode) /*error handling*/ { } } return(RedirectToAction("Index")); } else { return(View()); } }
public async Task <EditCarForm> GetCarDetails(string id) { Car ModelGlobal = default(Car); EditCarForm ModelLocal = default(EditCarForm); 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($"Car/Get/{id}"); if (Res.IsSuccessStatusCode) { var EmpResponse = Res.Content.ReadAsStringAsync().Result; ModelGlobal = JsonConvert.DeserializeObject <Car>(EmpResponse); ModelLocal = AutoMapper <Car, EditCarForm> .AutoMap(ModelGlobal); } } return(ModelLocal); }
// GET: Car/Edit/5 public async Task <ActionResult> Edit(string id) { //return View(await GetCarDetails(id)); List <Model> modelList = null; List <SelectListItem> getmodelformList = new List <SelectListItem>(); EditCarForm model = new EditCarForm(); model = await GetCarDetails(id); 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.ModelList = getmodelformList; return(View(model)); }