public IActionResult GetRelatedProjects(int taskId) { try { //var task = TasksDataStore.Current.Tasks.FirstOrDefault(t => t.Id == taskId); if (!_taskInfoRepository.TaskExists(taskId)) { _logger.LogInformation($"Task with id {taskId} wasnt found when accessing the related projects."); return(NotFound()); } var relatedProjectsResult = new List <RelatedProjectsDto>(); var relatedProjects = _taskInfoRepository.GetRelatedProjects(taskId); foreach (var relatedProject in relatedProjects) { relatedProjectsResult.Add(new RelatedProjectsDto { Id = relatedProject.Id, Name = relatedProject.Name, Description = relatedProject.Description }); } return(Ok(relatedProjectsResult)); } catch (Exception e) { _logger.LogCritical($"Exception while getting points of interest for task with id: {taskId}.", e); return(StatusCode(500, "A problem happened while handling your request")); } }