/// <summary> /// Create an attachment /// </summary> public void CreateAttachment(JiraIssueResponse issue, List <MultipartAttachment> attachment) { String boundary = String.Format("------{0:N}", Guid.NewGuid()); this.Client.Post <List <MultipartAttachment>, Object>(String.Format("api/2/issue/{0}/attachments", issue.Key), String.Format("multipart/form-data; boundary={0}", boundary), attachment); }
public async Task <IActionResult> AddStory([FromBody] AddJiraStory data) { if (String.IsNullOrEmpty(data.IssueId)) { return(StatusCode(422)); } var room = await _dbContext.Rooms.Include(r => r.Stories).FirstOrDefaultAsync(r => r.Id == data.RoomId); if (room == null) { return(StatusCode(422, new { error = "The room does not exist" })); } if (room.Stories.Count >= 10) { return(Forbid()); } var jiraStory = await _dbContext.Stories.FirstOrDefaultAsync(s => s.JiraIssueId == data.IssueId && s.RoomId == data.RoomId); if (jiraStory != null) { return(StatusCode(422, new { error = "You've already added this story" })); } var client = _clientFactory.CreateClient(); var request = new HttpRequestMessage(HttpMethod.Get, $"https://{data.JiraDomain}/rest/api/3/issue/{data.IssueId}?fields=description,summary,customfield_10026&expand=renderedFields"); request.Headers.Add("Authorization", $"Basic {data.JiraToken}"); var response = await client.SendAsync(request); if (!response.IsSuccessStatusCode) { return(StatusCode(404)); } var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true, }; var content = await response.Content.ReadAsStringAsync(); JiraIssueResponse issue = JsonSerializer.Deserialize <JiraIssueResponse>(content, options); int point; if (issue.Fields.Customfield_10026 == null) { point = -1; } else { point = issue.Fields.Customfield_10026 > 0 ? (int)issue.Fields.Customfield_10026 : -1; } var story = new Story { Title = issue.Fields.Summary, Content = issue.RenderedFields.Description, Point = point, IsJiraStory = true, JiraIssueId = data.IssueId, }; room.Stories.Add(story); await _dbContext.SaveChangesAsync(); return(StatusCode(201, new { storyId = story.Id, issueId = data.IssueId })); }