private static async Task <(bool Success, string Content)> CreateIssue(RedmineIssueWrapper issue) { //var issuesEndPoint = "issues.json"; // Read values from config // https://docs.microsoft.com/en-us/azure/azure-functions/functions-how-to-use-azure-function-app-settings // https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp#environment-variables var config = new CreateRedmineIssueConfiguration(); var headers = new List <KeyValuePair <string, string> >(new KeyValuePair <string, string>[] { new KeyValuePair <string, string>(config.RedmineApiTokenHeaderName, config.RedmineApiTokenValue) }); HttpClientInstance.Init(config.RedmineBaseUrl, headers); var _client = HttpClientInstance.Instance; var resp = await _client.PostAsync(config.RedmineIssuesEndPoint, new StringContent(issue.SerializeToJson(), System.Text.Encoding.UTF8, "application/json")); var success = resp.IsSuccessStatusCode; string ret; if (success) { ret = await resp.Content.ReadAsStringAsync(); } else { ret = resp.ReasonPhrase + ". "; var content = await resp.Content.ReadAsStringAsync(); if (!String.IsNullOrWhiteSpace(content)) { try { dynamic json = JObject.Parse(content); ret += json?.errors[0]; } catch { } } } return(Success : success, Content : ret); }
private static async Task <(bool Success, string ResponseMessage, RedmineFullIssue CreatedIssue)> CreateIssue(DtoIssue issue) { // TODO: Call CreateRedmineIssue HttpClientInstance.Init(_config.CreateRedmineIssueUrl, null); var _client = HttpClientInstance.Instance; var resp = await _client.PostAsJsonAsync(_config.CreateRedmineIssueEndPoint, issue); var success = resp.IsSuccessStatusCode; string json = null; if (success) { json = await resp.Content.ReadAsStringAsync(); if (!String.IsNullOrWhiteSpace(json)) { try { var ret = JsonConvert.DeserializeObject <RedmineFullIssue>(json); return(Success : success, ResponseMessage : "Successful", CreatedIssue : ret); } catch (Exception ex) { success = false; return(Success : success, ResponseMessage : ex.Message, CreatedIssue : null); } } else { success = false; return(Success : success, ResponseMessage : "Empty Content from Redmine.", CreatedIssue : null); } } else { var error = await resp.Content.ReadAsStringAsync(); return(Success : success, ResponseMessage : error, CreatedIssue : null); } }