Beispiel #1
0
        /// <summary>
        /// Creates or replaces the provided conversation item, based on the id.
        /// </summary>
        /// <param name="issueId">The issue on which the operation will be executed at.</param>
        /// <param name="conversationItemId">The id of the conversation.</param>
        /// <param name="conversationItem">The conversation that will be created or replaced if already existing.</param>
        public async Task CreateOrReplaceConversationItemAsync(string issueId, string conversationItemId, IssueConversationDTO conversationItem)
        {
            ObjectId conversationItemOid = Validators.ValidateObjectId(conversationItemId, "Provided conversation id is no valid ObjectId.");

            var issue = await _issueRepository.GetIssueByIdAsync(issueId);

            await AssertUserCanWriteConversation(issue);

            if (conversationItemOid.Equals(conversationItem.Id) is false)
            {
                throw new HttpStatusException(StatusCodes.Status400BadRequest, "Id missmatch.");
            }

            var issueConversationModel = new IssueConversation()
            {
                Id            = conversationItem.Id,
                CreatorUserId = Validators.ValidateObjectId(conversationItem.Creator?.Id.ToString(), "The conversation item is missing a valid userId."),
                Data          = conversationItem.Data,
                // Conversation from the outside  is always a message and
                // can therefore not contain requirements
                Requirements = null,
                Type         = IssueConversation.MessageType,
            };

            await _issueRepository.CreateOrUpdateConversationItemAsync(issueId, issueConversationModel);
        }