예제 #1
0
        public async Task <IEnumerable <ItemGroupDto> > GetAllForUserAsync(bool includeTasks = true)
        {
            var userId = _currentUserService.GetCurrentUser().Id;
            var groups = await _itemGroupRepository.GetGroupsForUserAsync(userId);

            var groupDtos = new List <ItemGroupDto>();

            foreach (var group in groups)
            {
                var taskDtos = new List <TaskDto>();

                if (includeTasks)
                {
                    var tasks = await _taskRepository.GetTasksInGroupAsync(group.Id);

                    foreach (var task in tasks)
                    {
                        taskDtos.Add(new(task.Id, task.Name, task.Created, task.IsComplete, task.GroupId, task.Deadline));
                    }
                }

                groupDtos.Add(new (group.Id, group.Name, group.Description, group.ImageUri, taskDtos));
            }

            return(groupDtos);
        }