//TODO This method works incorrectly when trying to remove worker from active list. When checkbox is //checked, worker is selected. But when we make checkbox unchecked, the worker doesn't become unselected. public IActionResult SetWorkers(SetWorkersViewModel model) { var chosenWorkers = model.Workers .Where(m => m.IsSelected) .Select(x => _userRepository.Get(x.Id).EmployeeInfo.Id) .Select(x => _employeeRepository.Get(x)) .ToList(); var order = _orderRepository.Get(model.OrderId); order.Workers = chosenWorkers; _orderRepository.Save(order); //TODO fix: exception when trying to save order without changing it's workers return(RedirectToAction("AllOrders", "Order")); }
public IActionResult SetWorkers(long orderId) { var unchosenWorkers = _userRepository .GetAllEmployees() .Where(user => user.EmployeeInfo.ProcessedOrders.TrueForAll(order => order.Id != orderId)) .Select(user => _mapper.Map <SelectableWorkerViewModel>(user)) .ToList(); var chosenWorkers = _userRepository .GetAllEmployees() .Where(user => user.EmployeeInfo.ProcessedOrders.Any(order => order.Id == orderId)) .Select(user => _mapper.Map <SelectableWorkerViewModel>(user)) .Where(viewModel => viewModel.IsSelected = true) .ToList(); var allWorkers = unchosenWorkers.Concat(chosenWorkers).ToList(); var model = new SetWorkersViewModel(); model.Workers = allWorkers; model.OrderId = orderId; return(View(model)); }