async Task <Tuple <int, int> > SetProjectInfo(AsanaProject project) { //TODO: move to class int count = await GetStorageService().GetAsyncConnection().Table <AsanaTask>().Where(x => x.projectid == project.id && x.completed == false && x.parentId == null && x.IsPriorityHeading == false).CountAsync(); int overdue = await GetStorageService().GetAsyncConnection().Table <AsanaTask>().Where(x => x.projectid == project.id && x.completed == false && x.parentId == null && x.due_on != null && x.due_on <= DateTime.Today && x.IsPriorityHeading == false).CountAsync(); return(new Tuple <int, int>(count, overdue)); }
async Task DeleteProject(AsanaProject project) { var tasks = await getDb().GetTasks(project.id); foreach (var task in tasks) { await DeleteTask(task); } await getDb().Delete(project); }
public async Task <AsanaResponse <AsanaProject> > UpdateProject(AsanaProject projectToUpdate) { return(await UseRequest <AsanaProject>( string.Format("projects/{0}", projectToUpdate.id), request => { var fields = new List <string> { "name", "notes", "archived" }; request.AddObject(projectToUpdate, fields.ToArray()); request.Method = Method.PUT; })); }
public AsanaProjectProgress GetProgress(string projectId) { AsanaProjectProgress retProgress = new AsanaProjectProgress(); AsanaProject asanaProject = GetProject(projectId); retProgress.ProjectLink = asanaProject.ProjectLink; retProgress.ProjectName = asanaProject.ProjectName; List <bool> completedStates = asanaProject.Tasks.Where(c => c.SectionID == SECTION_ID_TO_DO || c.SectionID == SECTION_ID_IN_PROGRESS || c.SectionID == SECTION_ID_COMPLETED) .Select(c => c.TaskComplete).ToList(); completedStates.AddRange(asanaProject.Tasks.SelectMany(c => c.Subtasks.Select(st => st.SubtaskComplete))); retProgress.ProjectProgress = (double)completedStates.Where(c => c == true).Count() / (double)completedStates.Count; return(retProgress); }
private AsanaProject GetProjectByName(string projectName) { AsanaProject activeProject = null; _asanaRef.GetProjectsInWorkspace(_workspace, o => { foreach (AsanaProject project in o) { Debug.WriteLine("Found Project: " + project.Name); if (project.Name.Equals(projectName, StringComparison.OrdinalIgnoreCase)) { activeProject = project; Debug.WriteLine("Active project: " + activeProject.Name); } } }).Wait(); return(activeProject); }
public async Task <AsanaResponse <AsanaProject> > CreateProject(long workspaceId, AsanaProject newProject) { return(await UseRequest <AsanaProject>( GetWorkspaceProjectsUrl(workspaceId), request => { newProject.workspaceid = workspaceId; request.Method = Method.POST; var fields = new List <string> { "name", "notes", "archived" }; request.AddObject(newProject, fields.ToArray()); })); }
public Task <AsanaProject> Update(AsanaProject project) { throw new NotImplementedException(); }
public AsanaProject GetProject(string projectId) { AsanaProject retProject = new AsanaProject(); //Project HttpWebRequest request = NewGetRequest(string.Format("{0}/{1}", "https://app.asana.com/api/1.0/projects", projectId)); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { string content = string.Empty; using (Stream stream = response.GetResponseStream()) { using (StreamReader sr = new StreamReader(stream)) { content = sr.ReadToEnd(); } } AsanaApiProject apiProject = JsonConvert.DeserializeObject <AsanaApiProject>(content); retProject.Tasks = new List <AsanaTaskSummary>(); retProject.ProjectID = apiProject.data.id.ToString(); retProject.ProjectLink = string.Format("{0}/{1}", "https://app.asana.com/api/1.0/projects", apiProject.data.id); retProject.ProjectName = apiProject.data.name; //Tasks request = NewGetRequest(string.Format("{0}/{1}/{2}", "https://app.asana.com/api/1.0/projects", projectId, "tasks")); response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { content = string.Empty; using (Stream stream = response.GetResponseStream()) { using (StreamReader sr = new StreamReader(stream)) { content = sr.ReadToEnd(); } } AsanaApiTasks apiTasks = JsonConvert.DeserializeObject <AsanaApiTasks>(content); foreach (J_Ref task in apiTasks.data) { //Task request = NewGetRequest(string.Format("{0}/{1}", "https://app.asana.com/api/1.0/tasks", task.id)); response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { content = string.Empty; using (Stream stream = response.GetResponseStream()) { using (StreamReader sr = new StreamReader(stream)) { content = sr.ReadToEnd(); } } AsanaApiTask apiTask = JsonConvert.DeserializeObject <AsanaApiTask>(content); AsanaTaskSummary retTask = new AsanaTaskSummary(); retTask.Subtasks = new List <AsanaSubtaskSummary>(); retTask.TaskID = task.id.ToString(); retTask.TaskLink = string.Format("{0}/{1}", "https://app.asana.com/api/1.0/tasks", task.id); retTask.TaskName = apiTask.data.name; retTask.TaskComplete = apiTask.data.completed; if (apiTask.data.memberships.Count > 0) { retTask.SectionName = apiTask.data.memberships[0].section.name; retTask.SectionID = apiTask.data.memberships[0].section.id.ToString(); } //Subtasks request = NewGetRequest(string.Format("{0}/{1}/{2}", "https://app.asana.com/api/1.0/tasks", task.id, "subtasks")); response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { content = string.Empty; using (Stream stream = response.GetResponseStream()) { using (StreamReader sr = new StreamReader(stream)) { content = sr.ReadToEnd(); } } AsanaApiSubtasks apiSubtasks = JsonConvert.DeserializeObject <AsanaApiSubtasks>(content); foreach (J_Ref subtask in apiSubtasks.data) { //Subtask request = NewGetRequest(string.Format("{0}/{1}", "https://app.asana.com/api/1.0/tasks", subtask.id)); response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { content = string.Empty; using (Stream stream = response.GetResponseStream()) { using (StreamReader sr = new StreamReader(stream)) { content = sr.ReadToEnd(); } } AsanaApiSubtask apiSubtask = JsonConvert.DeserializeObject <AsanaApiSubtask>(content); AsanaSubtaskSummary retSubtask = new AsanaSubtaskSummary(); retSubtask.SubtaskLink = string.Format("{0}/{1}", "https://app.asana.com/api/1.0/tasks", subtask.id); retSubtask.SubtaskID = subtask.id.ToString(); retSubtask.SubtaskName = apiSubtask.data.name; retSubtask.SubtaskComplete = apiSubtask.data.completed; retTask.Subtasks.Add(retSubtask); } } } retProject.Tasks.Add(retTask); } } } } return(retProject); }
public async Task <AsanaResponse <AsanaProject> > CreateProject(long workspaceId, AsanaProject newProject) { return(await UseRequest <AsanaProject>( GetWorkspaceProjectsUrl(workspaceId), (request, container) => { request.Method = HttpMethod.Post; container.Add("name", newProject.name); container.Add("notes", newProject.notes); container.Add("archived", newProject.archived); })); }