示例#1
0
        public List <Project> GetAllUnapprovedProjects(int userId)
        {
            var projects         = _projectDAO.GetAllProjectsByMember(userId).Where(p => p.CreatedUser.Id == userId);
            var selectedProjects = new List <Project>();

            foreach (var project in projects)
            {
                var  member         = project.Members.FirstOrDefault(m => m.User.Id == userId);
                bool projectHasTask = false;
                var  epicsToRemove  = new List <Epic>();
                foreach (var epic in project.Epics)
                {
                    bool epicHasTask         = false;
                    var  userStoriesToRemove = new List <UserStory>();
                    foreach (var userStory in epic.UserStories)
                    {
                        if (userStory.State != UserStoryState.IN_PROGRESS)
                        {
                            userStoriesToRemove.Add(userStory);

                            continue;
                        }
                        bool userStoryHasTask = false;
                        var  tasksToRemove    = new List <Task>();
                        foreach (var task in userStory.Tasks)
                        {
                            if ((task.IsDone) && !task.IsApproved)
                            {
                                userStoryHasTask = true;
                            }
                            else
                            {
                                tasksToRemove.Add(task);
                            }
                        }
                        foreach (var task in tasksToRemove)
                        {
                            userStory.Tasks.Remove(task);
                        }
                        if (userStoryHasTask)
                        {
                            epicHasTask = true;
                        }
                        else
                        {
                            userStoriesToRemove.Add(userStory);
                        }
                    }
                    foreach (var userStory in userStoriesToRemove)
                    {
                        epic.UserStories.Remove(userStory);
                    }
                    if (epicHasTask)
                    {
                        projectHasTask = true;
                    }
                    else
                    {
                        epicsToRemove.Add(epic);
                    }
                }
                foreach (var epic in epicsToRemove)
                {
                    project.Epics.Remove(epic);
                }
                if (projectHasTask)
                {
                    selectedProjects.Add(project);
                }
            }

            return(selectedProjects);
        }