public JsonResult GetTasks(int id) { var viewModel = new TaskSelectViewModel(); foreach (var task in _taskDAO.GetAllByTaskDefinitionIdOrdered(id)) { var taskText = task.Title; var taskValue = task.Id.ToString(CultureInfo.InvariantCulture) + "-" + task.Role.RoleType + "-" + task.TaskDefinition.SystemName; var selectListItem = new SelectListItem { Text = taskText, Value = taskValue }; if (viewModel.TaskId == task.Id) { selectListItem.Selected = true; } viewModel.Tasks.Add(selectListItem); } // Hack for helideck tasks if (viewModel.Tasks.Count == 0) { foreach (var task in _taskDAO.GetAllHelideckByTaskDefinitionIdOrdered(id)) { var taskText = task.Title; var taskValue = task.Id.ToString(CultureInfo.InvariantCulture) + "-" + task.Role.RoleType + "-" + task.TaskDefinition.SystemName; var selectListItem = new SelectListItem { Text = taskText, Value = taskValue }; if (viewModel.TaskId == task.Id) { selectListItem.Selected = true; } viewModel.Tasks.Add(selectListItem); } } return(Json(viewModel)); }