public async Task <bool> AddProjectCategory(Category company) { using (var client = new AuthorizedHttpClient(_client)) { string post = JsonConvert.SerializeObject(company); var response = await client.PostAsync("categories.json", new StringContent("{\"category\":" + post + "}", Encoding.UTF8)); } return(false); }
/// <summary> /// Adds a milestone to the given project /// </summary> /// <param name="milestone"></param> /// <param name="projectId"></param> /// <returns></returns> public async Task <bool> AddMilestone(Milestone milestone, int projectId) { using (var client = new AuthorizedHttpClient(_client)) { string post = JsonConvert.SerializeObject(milestone); var response = await client.PostAsync("/projects/" + projectId + "/milestones.json", new StringContent("{\"milestone\":" + post + "}", Encoding.UTF8)); } return(false); }
public async Task <bool> SendMessage(string Body, string roomID) { using (var client = new AuthorizedHttpClient(this.client.ApiKey, this.client.Domain)) { string post = JsonConvert.SerializeObject(new ChatMessage() { body = Body }); var response = await client.PostAsync($"/chat/v3/rooms/{roomID}/messages.json", new StringContent("{\"message\":" + post + "}", Encoding.UTF8, "application/json")); } 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)); }