public async Task LoadSubtasks(long id, bool firstLoad = true) { if (firstLoad) { AddOperation(); } var response = await new AsanaRespository().GetSubtasks(id, AsanaRespository.SelectTasksFields(false)); ExecuteWithComplete(async() => { if (AsanaClient.ProcessResponse(response, true)) { var DbSubtasks = await getDb().GetSubTasks(id); var i = 0; foreach (var subtask in response.Data) { subtask.Order = i; var dbTask = DbSubtasks.FirstOrDefault( x => x.id == subtask.id); if (dbTask != null) { dbTask.IsFoundInDb = true; } var task = await new StorageService().Find <AsanaTask>(id); MapperService.Map(subtask, task.projectid, task.workspaceid); subtask.parentId = task.id; await getDb().Save(subtask); i++; } foreach (var subtask in DbSubtasks.Where(x => !x.IsFoundInDb && !x.IsForSync)) { await getDb().Delete(subtask); } } }, () => { if (firstLoad) { RemoveOperation(); } SubTasksLoaded(id, EventArgs.Empty); }); }
public async Task LoadTagTasks(long tagId, bool isFirstLoad = true) { if (isFirstLoad) { AddOperation(); } var tasks = await new AsanaRespository().GetTasksByTag(tagId, AsanaRespository.SelectTasksFields(true)); ExecuteWithComplete(async() => { if (AsanaClient.ProcessResponse(tasks, !_isUserActionRequest)) { var dbTasks = await getDb().GetTaskTagsByTag(tagId); foreach (var task in tasks.Data) { var dbTask = dbTasks.FirstOrDefault(x => x.TaskId == task.id); if (dbTask != null) { dbTask.IsFoundInDb = true; } else { await getDb().Insert(new AsanaTagTask { TaskId = task.id, TagId = tagId, id = Guid.NewGuid().GetHashCode() }); } } foreach (var asanaTagTask in dbTasks.Where(x => !x.IsFoundInDb)) { await getDb().Delete(asanaTagTask); } } }, () => { if (isFirstLoad) { RemoveOperation(); } }); }
public async Task LoadUserTasks(long userId, long workspaceId) { var fields = AsanaRespository.SelectTasksFields(); fields.Add("projects"); AddOperation(); var tasks = await new AsanaRespository().GetUserTasks(userId, workspaceId, fields); ExecuteWithComplete(async() => { if (AsanaClient.ProcessResponse(tasks, !_isUserActionRequest)) { var userTasks = (await getDb().GetTasksByUser(userId)).Where(x => x.workspaceid == workspaceId); foreach (var u in tasks.Data) { var dbTask = userTasks.FirstOrDefault(x => x.id == u.id); if (dbTask != null) { dbTask.IsFoundInDb = true; } MapperService.Map(u, workspaceId); await getDb().Save(u); } foreach (var task in userTasks.Where(x => !x.IsFoundInDb)) { task.assigneeid = 0; await getDb().Save(task); } } }, () => { RemoveOperation(); }); }
public async Task LoadProjectTasks(long workspaceId, long id, bool firstLoad = true) { if (firstLoad) { AddOperation(); } var tasks = await new AsanaRespository().GetTasks(id, AsanaRespository.SelectTasksFields(false, true)); ExecuteWithComplete(async() => { if (AsanaClient.ProcessResponse(tasks, !_isUserActionRequest)) { int i = 0; var project = await getDb().Find <AsanaProject>(id); var dbTasks = await getDb().GetTasks(id); foreach (var task in tasks.Data) { task.Order = i; var dbTask = dbTasks.FirstOrDefault(x => x.id == task.id); if (dbTask != null) { dbTask.IsFoundInDb = true; } MapperService.Map(task, id, workspaceId); await getDb().Save(task); i++; } foreach (var task in dbTasks.Where(x => !x.IsFoundInDb && !x.IsForSync)) { await DeleteTask(task); } project.LastLoadDate = DateTime.Now; if (firstLoad) { var projectTasks = (await getDb().GetTasks(id)).Where(x => !x.IsCompleted); foreach (var task in projectTasks) { await LoadSubtasks(task.id, firstLoad); } } } }, () => { if (firstLoad) { RemoveOperation(); } ProjectTasksLoaded(id, EventArgs.Empty); }); }