Пример #1
0
        public void CreateItemCompleteUncompleteAsync_Success()
        {
            var client = TodoistClientFactory.Create();

            var transaction = client.CreateTransaction();

            var item   = new Item("demo task");
            var itemId = transaction.Items.AddAsync(item).Result;

            transaction.Items.CompleteAsync(new CompleteItemArgument(itemId));

            transaction.CommitAsync().Wait();

            var itemInfo = client.Items.GetAsync(item.Id).Result;

            Assert.True(itemInfo.Item.IsChecked == true);

            client.Items.UnArchiveAsync(itemId).Wait();
            client.Items.UncompleteAsync(itemId).Wait();

            var childOrder = 3;

            client.Items.ReorderAsync(new ReorderEntry(item.Id, childOrder)).Wait();
            var anotherItem = client.Items.GetAsync().Result.First(i => i.Id != item.Id);

            client.Items.MoveAsync(ItemMoveArgument.CreateMoveToParent(item.Id, anotherItem.Id))
            .Wait();

            itemInfo = client.Items.GetAsync(item.Id).Result;
            Assert.Equal(anotherItem.Id.PersistentId, itemInfo.Item.ParentId);
            Assert.Equal(childOrder, itemInfo.Item.ChildOrder);

            client.Items.CompleteAsync(new CompleteItemArgument(itemId)).Wait();
            itemInfo = client.Items.GetAsync(item.Id).Result;
            Assert.True(itemInfo.Item.IsChecked);

            client.Items.UncompleteAsync(itemId).Wait();
            itemInfo = client.Items.GetAsync(item.Id).Result;
            Assert.False(itemInfo.Item.IsChecked);

            client.Items.DeleteAsync(item.Id).Wait();
        }
Пример #2
0
        public async void AddNotesTask(string projectName, DateTime lectureDate)
        {
            //Loads all projects and searches for the selected project
            var projects = await client.Projects.GetAsync();

            foreach (var proj in projects)
            {
                if (proj.Name == projectName)
                {
                    //Create a transaction to lower the times we request and send data to the server
                    var transaction = client.CreateTransaction();

                    //Adding the main task
                    var quickAddItem = new QuickAddItem("Renskrivning föreläsning " + projectName + " " + lectureDate.Day + " / " + lectureDate.Month
                                                        + " @Renskrivning #" + projectName);


                    var task = await client.Items.QuickAddAsync(quickAddItem);

                    //Adds subsaks and moves them under the main task
                    var sub1ID = await transaction.Items.AddAsync(new Item("Scanna orginal", proj.Id));

                    await transaction.Items.MoveAsync(ItemMoveArgument.CreateMoveToParent(sub1ID, task.Id));

                    var sub2ID = await transaction.Items.AddAsync(new Item("Renskriv", proj.Id));

                    await transaction.Items.MoveAsync(ItemMoveArgument.CreateMoveToParent(sub2ID, task.Id));

                    //var sub3ID = await transaction.Items.AddAsync(new Item("Samanfatta", proj.Id));
                    //await transaction.Items.MoveAsync(ItemMoveArgument.CreateMoveToParent(sub3ID, task.Id));

                    //Sends the rest of the data to server
                    await transaction.CommitAsync();

                    MessageBox.Show("Added \"Renskrivning föreläsning " + projectName + " " + lectureDate.Day + "/" + lectureDate.Month + "\"");
                }
            }
        }
Пример #3
0
        public async void AddReadingTask(string projectName, string bookName, DateTime startDate, DateTime dueDate, int lastChapter, int firstChapter)
        {
            //Gets all projects and finds the choosen
            var projects = await client.Projects.GetAsync();

            foreach (var proj in projects)
            {
                if (proj.Name == projectName)
                {
                    //Creates a transaction to cut down on times we contact server
                    var transaction = client.CreateTransaction();

                    //Adds main task
                    var quickAddItem = new QuickAddItem("Läs \"" + bookName + "\" @Läsning #" + projectName);
                    var task         = await client.Items.QuickAddAsync(quickAddItem);

                    task.DueDate = new DueDate(dueDate.Day + "/" + dueDate.Month);
                    await client.Items.UpdateAsync(task);

                    //Calculates how many days we have per chapter
                    int chaptersToRead = lastChapter - (firstChapter - 1);
                    int daysToDeadline = BusinessDaysUntil(startDate.Date, dueDate.Date);
                    int daysPerChapter = daysToDeadline / chaptersToRead;

                    var nextDueDate = startDate;

                    for (int i = firstChapter; i <= lastChapter; i++)
                    {
                        //Moves the duedate forward
                        nextDueDate = nextDueDate.AddDays(daysPerChapter + (i % 2) * (daysToDeadline % lastChapter));

                        //Ignores saturdays and sundays
                        if (nextDueDate.DayOfWeek == System.DayOfWeek.Saturday)
                        {
                            nextDueDate = nextDueDate.AddDays(2);
                        }
                        else if (nextDueDate.DayOfWeek == System.DayOfWeek.Sunday)
                        {
                            nextDueDate = nextDueDate.AddDays(1);
                        }


                        //Adds the chapter as a subtask with suptasks of its own
                        var quickAddSub = new QuickAddItem("Kapitel " + i);
                        var subtask     = await client.Items.QuickAddAsync(quickAddSub);

                        subtask.DueDate = new DueDate(nextDueDate.Day + "/" + nextDueDate.Month);
                        await client.Items.UpdateAsync(subtask);

                        await transaction.Items.MoveAsync(ItemMoveArgument.CreateMoveToParent(subtask.Id, task.Id));

                        var readTaskID = await transaction.Items.AddAsync(new Item("Läsa", proj.Id));

                        await transaction.Items.MoveAsync(ItemMoveArgument.CreateMoveToParent(readTaskID, subtask.Id));

                        var summaryTaskID = await transaction.Items.AddAsync(new Item("Sammanfatta", proj.Id));

                        await transaction.Items.MoveAsync(ItemMoveArgument.CreateMoveToParent(summaryTaskID, subtask.Id));
                    }

                    //Sends the unsynced changes to the server
                    await transaction.CommitAsync();

                    MessageBox.Show("Added \"Läs " + bookName + "\"");
                }
            }
        }