Esempio n. 1
0
        /// <summary>
        /// Creates a new conversation for the provided issueId.
        /// </summary>
        /// <param name="issueId">The issue which will gets appended with the provided conversation.</param>
        /// <param name="conversationItem">The new conversation item.</param>
        /// <returns>The inserted conversation item.</returns>
        public async Task <IssueConversationDTO> CreateNewIssueConversationAsync(string issueId, IssueConversationDTO conversationItem)
        {
            var issue = await _issueRepository.GetIssueByIdAsync(issueId);

            await AssertUserCanWriteConversation(issue);

            await _issueService.AssertNotArchived(issue);

            var conversationItems = issue.ConversationItems;

            // if ConversationItems are null = empty, create a new list, which will gets appended.
            if (conversationItems is null)
            {
                conversationItems = new List <IssueConversation>();
            }

            // TODO: after auth code impl. check if the user who creating this request is identical to the "conversationItem.Creator.Id" -> a client cannot create a conversation for other than himself.

            IssueConversation newConversation = new IssueConversation()
            {
                Id            = ObjectId.GenerateNewId(),
                CreatorUserId = _httpContextAccessor.HttpContext.User.GetUserId(),
                Data          = conversationItem.Data,
                Requirements  = new List <string>(),
                Type          = conversationItem.Type
            };

            // append the conversationItems with the new conversation item.
            conversationItems.Add(newConversation);

            // send Message to Author
            await CreateMessageForAuthor(issue);

            // update the issue and the conversationItems withit.
            await _issueRepository.UpdateAsync(issue);

            return(await MapIssueConversationDTOAsync(issue.Id, newConversation));
        }