public ActionResult VehiclesToAssign(int contractID, int contractorID) { EditAssignVehicleViewModel model = new EditAssignVehicleViewModel(); model.ContractID = contractID; ViewBag.VehicleID = new SelectList(vehicleRepository.UnAssignedVehicles(contractID, contractorID), "VehicleID", "IdentificationNumber"); return(View(model)); }
public async Task <ActionResult> VehiclesToAssign(EditAssignVehicleViewModel model) { if (ModelState.IsValid) { VehicleContract contract = (VehicleContract)model.GetContract(); try { await vehicleRepository.CreateContractAsync(contract); return(RedirectToAction("AssignedVehicles", "Contractors", new { contractID = model.ContractID })); } catch (Exception e) { var errors = string.Join(",", e.Message); ModelState.AddModelError(string.Empty, errors); } } ViewBag.VehicleID = new SelectList(vehicleRepository.UnAssignedVehicles(model.ContractID, base.CurrentContractorID), "VehicleID", "IdentificationNumber"); // If we got this far, something failed, redisplay form return(View(model)); }