private void UpdateTaskDetail(PlannerTask task)
        {
            SelectedCategory = null;
            if (task.Title.Equals(_neuAufgabe))
            {
                return;
            }
            PlannerAppliedCategories appliedCategories = task.AppliedCategories;

            System.Reflection.PropertyInfo[] propertyInfos = appliedCategories.GetType().GetProperties();
            foreach (System.Reflection.PropertyInfo propertyInfo in propertyInfos)
            {
                if (propertyInfo.PropertyType == typeof(bool?))
                {
                    if (propertyInfo.GetValue(appliedCategories) == null)
                    {
                        continue;
                    }
                    else if ((bool)propertyInfo.GetValue(appliedCategories) == true)
                    {
                        foreach (CustomCategory i in CustomCategoryGroups)
                        {
                            if (i.Name == propertyInfo.Name)
                            {
                                SelectedCategory = i;
                                return;
                            }
                        }
                    }
                }
            }
            return;
        }
        public async Task <IList <PlannerTask> > CreatePreReadTaskForEachUser(string planId, string bucketId, string taskTitle, DriveItem uploadFile, DateTime dueDateTime, IEnumerable <string> assigneeIds)
        {
            var retValue = new List <PlannerTask>();

            foreach (var assigneeId in assigneeIds)
            {
                var plannerAssignments = new PlannerAssignments();
                plannerAssignments.AddAssignee(assigneeId);

                //Category1 is pre-read task
                var plannerCategories = new PlannerAppliedCategories {
                    Category1 = true
                };

                var plannerTask = new PlannerTask()
                {
                    PlanId            = planId,
                    BucketId          = bucketId,
                    Title             = taskTitle,
                    AppliedCategories = plannerCategories,
                    DueDateTime       = dueDateTime,
                    Assignments       = plannerAssignments,
                };

                var task = await GraphClient.Planner.Tasks.Request().AddAsync(plannerTask);

                var taskDetail = await GraphClient.Planner.Tasks[task.Id].Details.Request().GetAsync();

                var references = new PlannerExternalReferences();
                references.AddReference(uploadFile.WebUrl, uploadFile.Name);

                var updateTaskDetail = await GraphClient.Planner.Tasks[task.Id].Details
                                       .Request()
                                       .Header("If-Match", taskDetail.GetEtag())
                                       .UpdateAsync(new PlannerTaskDetails()
                {
                    References = references
                });
                retValue.Add(task);
            }
            return(retValue);
        }
        private PlannerAppliedCategories CreateAppliedCategories(CustomCategory selectedCategory)
        {
            PlannerAppliedCategories appliedCategories = new PlannerAppliedCategories();

            System.Reflection.PropertyInfo[] propertyInfos = appliedCategories.GetType().GetProperties();
            foreach (System.Reflection.PropertyInfo propertyInfo in propertyInfos)
            {
                if (propertyInfo.PropertyType == typeof(bool?))
                {
                    if (propertyInfo.Name.Equals(selectedCategory.Name))
                    {
                        propertyInfo.SetValue(appliedCategories, selectedCategory.Value);
                    }
                    else
                    {
                        propertyInfo.SetValue(appliedCategories, false);
                    }
                }
            }
            return(appliedCategories);
        }
        private void ChangeIssue()
        {
            HochladenAsync(Attachments, _selectedBucket.Name, _selectedCategory.Description, _selectedGroup.Id);
            PlannerAppliedCategories appliedCategories = CreateAppliedCategories(_selectedCategory);
            Conversation             conversation      = CreateConversation(UploadPath, _selectedTask.Title);
            var         taskDetailsETag             = _graphClient.Planner.Tasks[_selectedTask.Id].Details.Request().GetAsync().Result.GetEtag();
            var         currentConversationthreadId = _graphClient.Planner.Tasks[_selectedTask.Id].Request().GetAsync().Result.ConversationThreadId;
            PlannerTask plannerTask = new PlannerTask()
            {
                PercentComplete   = SelectedPercentComplete.Value,
                DueDateTime       = _selectedDueDate,
                AppliedCategories = appliedCategories
            };

            if (currentConversationthreadId != null)
            {
                _graphClient.Groups[_selectedGroup.Id].Threads[currentConversationthreadId].Reply(conversation.Threads[0].Posts[0]).Request().PostAsync();
            }
            else
            {
                var neuConversationThreadId = _graphClient.Groups[_selectedGroup.Id].Conversations.Request().AddAsync(conversation).Result.Id;
                plannerTask.ConversationThreadId = neuConversationThreadId;//neue Thread zugewiesen
            }

            _graphClient.Planner.Tasks[_selectedTask.Id].Request()
            .Header("If-Match", _selectedTask.GetEtag())
            .Header("Prefer", "return=representation")
            .UpdateAsync(plannerTask);
            var currentTaskDetailsEtag            = _graphClient.Planner.Tasks[_selectedTask.Id].Details.Request().GetAsync().Result.GetEtag();
            PlannerTaskDetails plannerTaskDetails = new PlannerTaskDetails()
            {
                Description = _description
            };

            _graphClient.Planner.Tasks[_selectedTask.Id].Details.
            Request()
            .Header("If-Match", currentTaskDetailsEtag)
            .UpdateAsync(plannerTaskDetails);
            System.Windows.MessageBox.Show(string.Format("task {0} changed.", _selectedTask.Title));
        }
        private void CreateIssue()
        {
            HochladenAsync(Attachments, SelectedBucket.Name, SelectedCategory.Description, _selectedGroup.Id);

            PlannerAppliedCategories appliedCategories = CreateAppliedCategories(_selectedCategory);
            Conversation             conversation      = CreateConversation(UploadPath, _selectedTask.Title);
            var         newConversationId = _graphClient.Groups[_selectedGroup.Id].Conversations.Request().AddAsync(conversation).Result.Id;
            PlannerTask plannerTask       = new PlannerTask()
            {
                PlanId               = _selectedPlan.Id,
                BucketId             = _selectedBucket.Id,
                Title                = _taskTitle,
                ConversationThreadId = newConversationId,
                PercentComplete      = SelectedPercentComplete.Value,
                DueDateTime          = _selectedDueDate,
                AppliedCategories    = appliedCategories
            };
            var    createdTask            = _graphClient.Planner.Tasks.Request().AddAsync(plannerTask).Result;
            string createdTaskDetailsEtag = "";

            while (createdTask != null && createdTaskDetailsEtag.Equals(""))
            {
                try
                { createdTaskDetailsEtag = _graphClient.Planner.Tasks[createdTask.Id].Details.Request().GetAsync().Result.GetEtag(); }
                catch (Exception e)
                {
                    Thread.Sleep(500);
                }
            }

            PlannerTaskDetails plannerTaskDetails = new PlannerTaskDetails()
            {
                Description = _description
            };

            _graphClient.Planner.Tasks[createdTask.Id].Details.Request()
            .Header("If-Match", createdTaskDetailsEtag)
            .UpdateAsync(plannerTaskDetails);
            System.Windows.MessageBox.Show(string.Format("task {0} created.", createdTask.Title));
        }