public async Task <IActionResult> Edit(int id) { Aircraft aircraft = await _aircraft.GetAircraftByIdAsync(id); EditAircraftViewModel viewModel = _mapper.Map <EditAircraftViewModel>(aircraft); List <Manufacturer> manufacturers = await _manufacturers.GetManufacturersAsync(); viewModel.SetManufacturers(manufacturers); return(View(viewModel)); }
public async Task <IActionResult> Edit(EditAircraftViewModel viewModel) { IActionResult result; if (ModelState.IsValid) { int manufactured = DateTime.Now.Year - viewModel.Age; await _aircraft.UpdateAircraftAsync(viewModel.Id, viewModel.Registration, viewModel.SerialNumber, manufactured, viewModel.ManufacturerId, viewModel.ModelId); result = RedirectToAction("Index", new { manufacturerId = viewModel.ManufacturerId, modelId = viewModel.ModelId }); } else { List <Manufacturer> manufacturers = await _manufacturers.GetManufacturersAsync(); viewModel.SetManufacturers(manufacturers); result = View(viewModel); } return(result); }