public void MoveItemsToProject_Success() { var client = TodoistClientFactory.Create(); var item = new Item("demo task"); client.Items.AddAsync(item).Wait(); item.DueDate = new DueDate("every fri"); client.Items.UpdateAsync(item).Wait(); var project = new Project(Guid.NewGuid().ToString()); client.Projects.AddAsync(project); var itemInfo = client.Items.GetAsync(item.Id).Result; Assert.True(project.Id != itemInfo.Project.Id); client.Items.MoveAsync(ItemMoveArgument.CreateMoveToProject(itemInfo.Item.Id, project.Id)).Wait(); itemInfo = client.Items.GetAsync(item.Id).Result; Assert.True(project.Id == itemInfo.Project.Id); client.Projects.DeleteAsync(project.Id).Wait(); client.Items.DeleteAsync(item.Id).Wait(); }
/// <summary> /// Moves task to a different location asynchronous. /// </summary> /// <param name="moveArgument">The move entry.</param> /// <returns> /// Returns <see cref="T:System.Threading.Tasks.Task" />.The task object representing the asynchronous operation. /// </returns> /// <exception cref="ArgumentNullException"><paramref name="moveArgument" /> is <see langword="null" /></exception> /// <exception cref="HttpRequestException">API exception.</exception> /// <exception cref="AggregateException">Command execution exception.</exception> public Task MoveAsync(ItemMoveArgument moveArgument) { if (moveArgument == null) { throw new ArgumentNullException(nameof(moveArgument)); } return(ExecuteCommandAsync(new Command(CommandType.MoveItem, moveArgument))); }
public void UpdateOrders_Success() { var client = TodoistClientFactory.Create(); var item = client.Items.QuickAddAsync(new QuickAddItem("Demo task every fri")).Result; var firstProject = client.Projects.GetAsync().Result.First(); client.Items.MoveAsync(ItemMoveArgument.CreateMoveToProject(item.Id, firstProject.Id)).Wait(); client.Items.UpdateDayOrdersAsync(new OrderEntry(item.Id, 2)); client.Items.DeleteAsync(item.Id).Wait(); }
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(); }
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 + "\""); } } }
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 + "\""); } } }