public IActionResult AddRemoveTechnicians(int id) { AddRemoveTechniciansViewModel addRemoveTechniciansViewModel = new AddRemoveTechniciansViewModel { Id = id, AvailableTechnicians = this.technicianService.GetAllNamesOfTechniciansNotWorkingOnAGivenTask(id).GetAwaiter().GetResult().ToArray(), TechniciansWorkingOnRepairTask = this.technicianService.GetAllNamesOfTechniciansWorkingOnAGivenTask(id).ToArray() }; return(this.View(addRemoveTechniciansViewModel)); }
public async Task <IActionResult> AddRemoveTechnicians(AddRemoveTechniciansViewModel addRemoveTechniciansViewModel, int id) { if (ModelState.IsValid == false) { return(this.View(addRemoveTechniciansViewModel)); } foreach (string nameOfTechnicianToAdd in addRemoveTechniciansViewModel.TechniciansToAdd) /*Here the order is VERY IMPORTANT. Adding of technicians * must be the first operation since the removing of * technicians checks whether there are any technicians * left to work on the task. If there are none, the status * of the task is changed to PENDING. Hence, if the adding * is done after the removing and the changing of the * status there is a conflict (we have a PENDING Repair Task * that has a Technician assigned to it).*/ { await this.repairTaskService.AddTechnicianToRepairTaskAsync(nameOfTechnicianToAdd, id); } foreach (string nameOfTechnicianToRemove in addRemoveTechniciansViewModel.TechniciansToRemove) { await this.repairTaskService.RemoveTechnicianFromRepairTaskAsync(nameOfTechnicianToRemove, id); } return(this.RedirectToAction(StringConstants.ActionNameRepairTaskDetails, new { id })); }