Exemple #1
0
        public async Task <IActionResult> AddIssueDetailComment([FromBody] AddIssueDetailCommentFormModel issueForm)
        {
            var resp = await _issueService.AddIssueDetailCommentAsync(HttpContext.GetUser(), issueForm);

            return(Ok(GetRequestResult(resp)));
        }
        public async Task <IssueDetailCommentViewModel> AddIssueDetailCommentAsync(User user, AddIssueDetailCommentFormModel issueForm)
        {
            try
            {
                var issueDetail = await _context.IssueDetails.FindAsync(issueForm.IssueDetailId);

                if (issueDetail is null)
                {
                    throw new ExperienceManagementGlobalException(IssueServiceErrors.IssueDetailNotFoundError);
                }

                var issueDetailComment = new IssueDetailComment()
                {
                    Comment       = issueForm.Comment,
                    CreationDate  = DateTime.Now,
                    IssueDetailId = issueDetail.Id,
                    UserId        = user.Id
                };
                await _context.IssueDetailComments.AddAsync(issueDetailComment);

                await _context.SaveChangesAsync();

                return(new IssueDetailCommentViewModel()
                {
                    Comment = issueDetailComment.Comment,
                    CreationDate = issueDetailComment.CreationDate,
                    IssueDetailId = issueDetailComment.IssueDetailId,
                    Id = issueDetailComment.Id,
                    UserId = issueDetailComment.UserId,
                    UserName = issueDetailComment.User.Username
                });
            }
            catch (Exception ex)
            {
                throw new ExperienceManagementGlobalException(IssueServiceErrors.AddIssueDetailCommentError, ex);
            }
        }