/// <summary> /// Add event to user´s calendar /// http://developer.teamwork.com/events#create_event /// </summary> /// <param name="data"></param> /// <returns></returns> public async Task <int> AddCalendarEntry(EventCreate data) { try { using (var client = new AuthorizedHttpClient(_client)) { var settings = new JsonSerializerSettings() { ContractResolver = new NullToEmptyStringResolver() }; string post = JsonConvert.SerializeObject(data, settings); var response = await client.PostWithReturnAsync("calendarevents.json", new StringContent("{\"event\":" + post + "}", Encoding.UTF8)); if (response.StatusCode == HttpStatusCode.OK) { var id = response.ContentObj; int returnval; if (int.TryParse(id.ToString(), out returnval)) { return(returnval); } } } return(-1); } catch (Exception) { return(-1); } }
/// <summary> /// Add a Task to the tasklist /// http://developer.teamwork.com/todolistitems#add_a_task /// </summary> /// <param name="todo">The Task</param> /// <param name="taskListId">Tasklist to add the task to</param> /// <returns>Milestone ID</returns> public async Task <TodoItem> AddTodoItem(TodoItem todo, int taskListId) { using (var client = new AuthorizedHttpClient(this.client.ApiKey, this.client.Domain)) { var settings = new JsonSerializerSettings() { ContractResolver = new NullToEmptyStringResolver() }; string post = JsonConvert.SerializeObject(todo, settings); var newList = await client.PostWithReturnAsync("/tasklists/" + taskListId + "/tasks.json", new StringContent("{\"todo-item\": " + post + "}", Encoding.UTF8)); var id = newList.Headers.First(p => p.Key == "id"); if (id.Value != null) { var listresponse = await client.GetAsync <TaskResponse>("/tasks/" + int.Parse((string)id.Value.First()) + ".json", null, RequestFormat.Json); if (listresponse != null && listresponse.ContentObj != null) { var response = (TaskResponse)listresponse.ContentObj; return(response.TodoItem); } } return(null); } }
public async Task <BaseResponse <int> > AddCompany(Company company) { using (var client = new AuthorizedHttpClient(this.client.ApiKey, this.client.Domain)) { string post = JsonConvert.SerializeObject(company); return(await client.PostWithReturnAsync("/companies.json", new StringContent("{\"company\": " + post + "}", Encoding.UTF8))); } }
public async Task <BaseResponse <int> > AddPerson(Person company) { using (var client = new AuthorizedHttpClient(_client)) { string post = JsonConvert.SerializeObject(company); return(await client.PostWithReturnAsync("/people.json", new StringContent("{\"person\": " + post + "}", Encoding.UTF8))); } }
/// <summary> /// Add a new Tag /// </summary> /// <returns></returns> public async Task <BaseResponse <int> > AddTagAsync(Tag theTag) { using (var client = new AuthorizedHttpClient(_client)) { string post = JsonConvert.SerializeObject(theTag); return (await client.PostWithReturnAsync("/tags.json", new StringContent("{\"tag\": " + theTag + "}", Encoding.UTF8))); } }
/// <summary> /// Create a new Project /// http://developer.teamwork.com/projects /// </summary> /// <param name="project">New Project Object</param> /// <returns>Project ID</returns> public async Task <BaseResponse <int> > AddProject(Newproject project) { using (var client = new AuthorizedHttpClient(_client)) { string post = JsonConvert.SerializeObject(project); return (await client.PostWithReturnAsync("projects.json", new StringContent("{\"project\": " + post + "}", Encoding.UTF8))); } }
/// <summary> /// Add a Milestone to the given project /// http://developer.teamwork.com/milestones#create_a_single_m /// </summary> /// <param name="milestone">Milestone ID (int)</param> /// <param name="projectId">Project ID (int)</param> /// <returns>Milestone ID</returns> public async Task <BaseResponse <int> > AddMilestone(Milestone milestone, int projectId) { using (var client = new AuthorizedHttpClient(_client)) { string post = JsonConvert.SerializeObject(milestone); return (await client.PostWithReturnAsync("/projects/" + projectId + "/milestones.json", new StringContent("{\"milestone\": " + post + "}", Encoding.UTF8))); } }
/// <summary> /// Add a Tasklist to the given project /// http://developer.teamwork.com/tasklists#create_list /// </summary> /// <param name="list"></param> /// <param name="projectId">Project ID (int)</param> /// <returns>Milestone ID</returns> public async Task <int> AddTodoListReturnOnlyID(TodoList list, int projectId) { using (var client = new AuthorizedHttpClient(_client)) { string post = JsonConvert.SerializeObject(list); var newList = await client.PostWithReturnAsync("/projects/" + projectId + "/todo_lists.json", new StringContent("{\"todo-list\": " + post + "}", Encoding.UTF8)); var id = newList.Headers.First(p => p.Key == "id"); if (id.Value != null) { return(int.Parse((string)id.Value.First())); } return(-1); } }
/// <summary> /// Add a message to the project /// http://developer.teamwork.com/messages#create_a_message /// </summary> /// <param name="message">The Task</param> /// <param name="projectID">Tasklist to add the task to</param> /// <returns>Milestone ID</returns> public async Task <bool> AddMessageNoCallback(NewPost message, int projectID) { try { using (var client = new AuthorizedHttpClient(_client)) { string post = JsonConvert.SerializeObject(message); await client.PostWithReturnAsync("/projects/" + projectID + "/posts.json", new StringContent("{\"post\": " + post + "}", Encoding.UTF8)); return(true); } } catch (Exception) { return(false); } }
/// <summary> /// Upload a file to a given project /// </summary> /// <param name="projectID"></param> /// <param name="description"></param> /// <param name="filepath"></param> /// <param name="filename"></param> /// <param name="isPrivate">default false</param> /// <param name="categoryID">default 0</param> /// <returns></returns> public async Task <BaseResponse <bool> > UploadFileToProject(int projectID, string description, string filepath, string filename, bool isPrivate = false, int categoryID = 0) { using (var client = new AuthorizedHttpClient(_client)) { using (var content = new MultipartFormDataContent()) { FileStream fs = File.OpenRead(filepath); var streamContent = new StreamContent(fs); streamContent.Headers.Add("Content-Type", "application/octet-stream"); streamContent.Headers.Add("Content-Disposition", "form-data; name=\"file\"; filename=\"" + Path.GetFileName(filepath) + "\""); content.Add(streamContent, "file", Path.GetFileName(filepath)); HttpResponseMessage message = await client.PostAsync("pendingfiles.json", content); if (message.StatusCode != HttpStatusCode.OK) { using (Stream responseStream = await message.Content.ReadAsStreamAsync()) { string jsonMessage = new StreamReader(responseStream).ReadToEnd(); var result = JsonConvert.DeserializeObject <FileUploadResponse>(jsonMessage); var file = new TeamWorkFile() { CategoryId = categoryID.ToString(CultureInfo.InvariantCulture), CategoryName = "", Description = description, Name = filename, PendingFileRef = result.pendingFile.Reference, Isprivate = isPrivate == false ? "0" : "1" }; var response = await client.PostWithReturnAsync("/projects/" + projectID + "/files.json", new StringContent("{\"file\": " + JsonConvert.SerializeObject(file) + "}", Encoding.UTF8)); if (response.StatusCode == HttpStatusCode.OK) { return(new BaseResponse <bool>(true, HttpStatusCode.OK)); } } } } } return(new BaseResponse <bool>(false, HttpStatusCode.InternalServerError)); }
/// <summary> /// Add a message to the project /// http://developer.teamwork.com/messages#create_a_message /// </summary> /// <param name="message">The Task</param> /// <param name="projectID">Tasklist to add the task to</param> /// <returns>Milestone ID</returns> public async Task <TodoItem> AddMessage(Post message, int projectID) { using (var client = new AuthorizedHttpClient(_client)) { string post = JsonConvert.SerializeObject(message); var newList = await client.PostWithReturnAsync("/projects/" + projectID + "/posts.json", new StringContent("{\"post\": " + post + "}", Encoding.UTF8)); var id = newList.Headers.First(p => p.Key == "id"); if (id.Value != null) { var listresponse = await client.GetAsync <PostResponse>("/posts/" + int.Parse((string)id.Value.First()) + ".json", null, RequestFormat.Json); if (listresponse != null && listresponse.ContentObj != null) { var response = (TaskResponse)listresponse.ContentObj; return(response.TodoItem); } } return(null); } }