Beispiel #1
0
        public static Comment CreateCommentForDiscussion([NotNull]
                                                         CommentDiscussion commentDiscussion,
                                                         int currentUserId,
                                                         DateTime createdAt,
                                                         [NotNull]
                                                         string commentText,
                                                         bool isVisibleToPlayer,
                                                         [CanBeNull]
                                                         Comment parentComment,
                                                         CommentExtraAction?extraAction = null)
        {
            if (commentDiscussion == null)
            {
                throw new ArgumentNullException(nameof(commentDiscussion));
            }

            if (commentText == null)
            {
                throw new ArgumentNullException(nameof(commentText));
            }

            var comment = new Comment
            {
                CommentId           = -1,
                ProjectId           = commentDiscussion.ProjectId,
                AuthorUserId        = currentUserId,
                CommentDiscussionId = commentDiscussion.CommentDiscussionId,
                CommentText         = new CommentText()
                {
                    CommentId = -1,
                    Text      = new MarkdownString(commentText),
                },
                IsCommentByPlayer = !commentDiscussion.HasMasterAccess(currentUserId),
                IsVisibleToPlayer = isVisibleToPlayer,
                Parent            = parentComment,
                ExtraAction       = extraAction,
                CreatedAt         = createdAt,
                LastEditTime      = createdAt,
            };

            commentDiscussion.Comments.Add(comment);
            if (!isVisibleToPlayer)
            {
                commentDiscussion.RequestMasterAccess(currentUserId);
            }
            //TODO: check access for discussion for players (claims & forums)
            return(comment);
        }
        public async Task <ActionResult> CreateComment(AddCommentViewModel viewModel)
        {
            CommentDiscussion discussion = await ForumRepository.GetDiscussion(viewModel.ProjectId, viewModel.CommentDiscussionId);

            discussion.RequestAnyAccess(CurrentUserId);

            if (discussion == null)
            {
                return(NotFound());
            }

            try

            {
                if (viewModel.HideFromUser)
                {
                    _ = discussion.RequestMasterAccess(CurrentUserId);
                }

                var claim = discussion.GetClaim();
                if (claim != null)
                {
                    await ClaimService.AddComment(discussion.ProjectId,
                                                  claim.ClaimId,
                                                  viewModel.ParentCommentId,
                                                  !viewModel.HideFromUser,
                                                  viewModel.CommentText,
                                                  (FinanceOperationAction)viewModel.FinanceAction);
                }
                else
                {
                    var forumThread = discussion.GetForumThread();
                    if (forumThread != null)
                    {
                        await ForumService.AddComment(discussion.ProjectId, forumThread.ForumThreadId, viewModel.ParentCommentId,
                                                      !viewModel.HideFromUser, viewModel.CommentText);
                    }
                }

                return(CommentRedirectHelper.RedirectToDiscussion(Url, discussion));
            }
            catch
            {
                //TODO: Message that comment is not added
                return(CommentRedirectHelper.RedirectToDiscussion(Url, discussion));
            }
        }