예제 #1
0
        public IActionResult GetTask(int id, bool includeRelatedProjects = false)
        {
            var task = _taskInfoRepository.GetTask(id, includeRelatedProjects);

            if (task == null)
            {
                return(NotFound());
            }

            if (includeRelatedProjects)
            {
                var taskResult = new TaskDto
                {
                    Id          = task.Id,
                    Name        = task.Name,
                    Description = task.Description
                };

                foreach (var relatedProject in task.RelatedProjects)
                {
                    taskResult.RelatedProjects.Add(
                        new RelatedProjectsDto
                    {
                        Id          = relatedProject.Id,
                        Name        = relatedProject.Name,
                        Description = relatedProject.Description
                    });
                }

                return(Ok(taskResult));
            }

            return(Ok(new TaskWithoutRelatedProjectsDto
            {
                Id = task.Id,
                Name = task.Name,
                Description = task.Description
            }));

            //var task = TasksDataStore.Current.Tasks.FirstOrDefault(t => t.Id == id);

            //if (task == null)
            //{
            //    return NotFound();
            //}

            //return Ok(task);
        }