public async Task <GetTopicDetailsOperationResponse> Execute(GetTopicDetailsOperationRequest request) { var teamTree = await _authorizationContext.GetTeamTree(); var topic = await _topicRepository.GetByIdAsync(request.TopicId); if (teamTree != null) { var employees = teamTree .GetAllEmployees(); var subordinates = employees .Select(employee => MapEmployee(employee, topic)) .Where(employee => employee.ProgressStatus != ProgressStatus.NotPlanned) .ToList(); var directSubordinates = teamTree.GetDirectSubordinates() .Select(employee => MapEmployee(employee, topic)) .Where(employee => employee.ProgressStatus != ProgressStatus.NotPlanned) .ToList(); var mappedTeams = employees .Select(employee => employee.ManagedTeam) .Where(team => team != null) .DistinctBy(team => team.Id) .Select(team => MapTeam(team, topic)) .Where(team => team.ProgressStatus != ProgressStatus.NotPlanned) .ToList(); return(new GetTopicDetailsOperationResponse { Id = topic.Id, Subject = topic.Subject, Description = topic.Description, ParentId = topic.ParentTopic?.Id, ParentSubject = topic.ParentTopic?.Subject, Subordinates = subordinates, DirectSubordinates = directSubordinates, Teams = mappedTeams }); } var employee = await _authorizationContext.CurrentEmployee(); return(new GetTopicDetailsOperationResponse { Id = topic.Id, Subject = topic.Subject, Description = topic.Description, ParentId = topic.ParentTopic?.Id, ParentSubject = topic.ParentTopic?.Subject, Subordinates = new List <GetTopicDetailsOperationResponse.Employee> { MapEmployee(employee, topic) }, DirectSubordinates = new List <GetTopicDetailsOperationResponse.Employee> { MapEmployee(employee, topic) }, Teams = new List <GetTopicDetailsOperationResponse.Team>() }); }
public async Task <IActionResult> Topic([Required] Guid id) { var request = new GetTopicDetailsOperationRequest { TopicId = id }; GetTopicDetailsOperationResponse response; try { response = await _getTopicDetailsOperation.Execute(request); } catch { return(NotFound(new ErrorModel($"No topic '{id}' exists"))); } return(Ok(new TopicModel(response))); }