public IActionResult AssignTractor(AssignTractorViewModel assignTractorViewModel) { if (ModelState.IsValid) { //Employee employee = new Employee() //{ // EmployeeID = assignTractorViewModel.EmployeeID, // TractorID = assignTractorViewModel.TractorID //}; Employee driver = empRepo.GetEmployeeWithId(assignTractorViewModel.EmployeeID); Tractor truck = truRepo.GetTractorWithId(assignTractorViewModel.TractorID); //this is where you need to update DriverTractorAssignmentHistory or do it in the repo.AssignTractor for abstraction purposes empRepo.AssignTractor(driver.EmployeeID, truck.TractorID); // changes the availability of tractor once assigned truRepo.ChangeStatusWithId(driver.TractorID.GetValueOrDefault()); //adds it to drivertractor history dtRepo.AddHistory(driver, truck); return(Redirect("/Employee")); } ; return(View(assignTractorViewModel)); }
public IActionResult AssignTractor(int id) { Employee driverToAssignTractor = empRepo.GetEmployeeWithId(id); //Make sure this method is being drawn from the Tractor Repo and no the Employee Repo List <Tractor> availableTractors = truRepo.GetAvailableTractor(); AssignTractorViewModel assignTractorViewModel = new AssignTractorViewModel(driverToAssignTractor, availableTractors); return(View(assignTractorViewModel)); }