Пример #1
0
        public async Task UpdateTasksAsync()
        {
            // Get a group plan.
            var plans = await _graphService.GetGroupPlansAsync(Group);

            var plan = plans.FirstOrDefault();

            // If a group plan doesn't exist, create it.
            if (plan == null)
            {
                plan = await _graphService.AddGroupPlanAsync(Group,
                                                             new PlanModel
                {
                    Title = Group.DisplayName,
                    Owner = Group.Id
                });
            }

            // Get the task bucket.
            var buckets = await _graphService.GetPlanBucketsAsync(plan);

            var taskBucket = buckets.FirstOrDefault(b => b.Name.Equals(Constants.TaskBucketName));

            // If the task bucket doesn't exist, create it.
            if (taskBucket == null)
            {
                taskBucket = await _graphService.AddBucketAsync(new BucketModel
                {
                    Name   = Constants.TaskBucketName,
                    PlanId = plan.Id
                });
            }

            // Get the tasks and add the ones that aren't completed.
            var tasks = await _graphService.GetBucketTasksAsync(taskBucket);

            Tasks.AddRange(tasks.Where(t => t.PercentComplete < 100));
            OnTasksChanged();

            // Store values.
            _groupPlan  = plan;
            _taskBucket = taskBucket;
        }