private async Task <Comment> AddPaymentCommentAsync( CommentDiscussion discussion, PaymentType paymentType, ClaimPaymentRequest request) { Comment comment = CommentHelper.CreateCommentForDiscussion( discussion, CurrentUserId, Now, request.CommentText ?? "", true, null); comment.Finance = new FinanceOperation { OperationType = FinanceOperationType.Online, PaymentTypeId = paymentType.PaymentTypeId, MoneyAmount = request.Money, OperationDate = request.OperationDate, ProjectId = request.ProjectId, ClaimId = request.ClaimId, Created = Now, Changed = Now, State = FinanceOperationState.Proposed, }; UnitOfWork.GetDbSet <Comment>().Add(comment); await UnitOfWork.SaveChangesAsync(); return(comment); }
public static void RequestAnyAccess(this CommentDiscussion discussion, int currentUserId) { if (!discussion.HasAnyAccess(currentUserId)) { throw new NoAccessToProjectException(discussion, currentUserId); } }
private ActionResult ReturnToParent(CommentDiscussion discussion, string extra = null) { if (extra == null) { extra = ""; } else { extra = "#" + extra; } var claim = discussion.GetClaim(); if (claim != null) { var actionLink = Url.Action("Edit", "Claim", new { claim.ClaimId, discussion.ProjectId }); return(Redirect(actionLink + extra)); } var forumThread = discussion.GetForumThread(); if (forumThread != null) { var actionLink = Url.Action("ViewThread", new { discussion.ProjectId, forumThread.ForumThreadId }); return(Redirect(actionLink + extra)); } return(HttpNotFound()); }
public CommentViewModel(CommentDiscussion parent, Comment comment, int currentUserId, int deepLevel) { DeepLevel = deepLevel; IsVisibleToPlayer = comment.IsVisibleToPlayer; HasMasterAccess = comment.Project.HasMasterAccess(currentUserId); CanModerateFinance = comment.Project.HasMasterAccess(currentUserId, acl => acl.CanManageMoney) || comment.Finance?.PaymentType?.UserId == currentUserId; IsCommentByPlayer = comment.IsCommentByPlayer; Author = comment.Author; AuthorAvatar = AvatarIdentification.FromOptional(comment.Author.SelectedAvatarId); AuthorEmail = comment.Author.Email; CreatedTime = comment.CreatedAt; Finance = comment.Finance; CommentText = comment.CommentText.Text.ToHtmlString(); CommentId = comment.CommentId; ProjectId = comment.ProjectId; CommentDiscussionId = comment.CommentDiscussionId; IsRead = comment.IsReadByUser(currentUserId); ChildComments = parent.Comments.Where(c => c.ParentCommentId == comment.CommentId) .Select(c => new CommentViewModel(parent, c, currentUserId, deepLevel + 1)) .OrderBy(c => c.CreatedTime); ExtraAction = comment.ExtraAction == null ? null : (CommentExtraAction?)comment.ExtraAction.Value; IsVisible = comment.IsVisibleTo(currentUserId); }
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)); } }
public static bool HasPlayerAccess(this CommentDiscussion commentDiscussion, int currentUserId) { var forumThread = commentDiscussion.GetForumThread(); var claim = commentDiscussion.GetClaim(); if (forumThread != null) { return(forumThread.HasPlayerAccess(currentUserId)); } if (claim != null) { return(claim.HasPlayerAccesToClaim(currentUserId)); } throw new InvalidOperationException(); }
public static ActionResult RedirectToDiscussion(IUrlHelper Url, CommentDiscussion discussion, int?commentId = null) { var extra = commentId != null ? $"#comment{commentId}" : null; var claim = discussion.GetClaim(); if (claim != null) { var actionLink = Url.Action("Edit", "Claim", new { claim.ClaimId, discussion.ProjectId }); return(new RedirectResult(actionLink + extra)); } var forumThread = discussion.GetForumThread(); if (forumThread != null) { var actionLink = Url.Action("ViewThread", new { discussion.ProjectId, forumThread.ForumThreadId }); return(new RedirectResult(actionLink + extra)); } return(new NotFoundResult()); }
public static List <CommentViewModel> ToCommentTreeViewModel(this CommentDiscussion discussion, int currentUserId) { return(discussion.Comments.Where(comment => comment.ParentCommentId == null) .Select(comment => new CommentViewModel(discussion, comment, currentUserId)).OrderBy(c => c.CreatedTime).ToList()); }
public static IEnumerable <Comment> GetMasterAnswers(this CommentDiscussion claim) => claim.Comments.Where(comment => !comment.IsCommentByPlayer && comment.IsVisibleToPlayer);
public static ForumThread GetForumThread(this CommentDiscussion commentDiscussion) { return(commentDiscussion.Project.ForumThreads.SingleOrDefault( ft => ft.CommentDiscussionId == commentDiscussion.CommentDiscussionId)); }
public static Claim GetClaim(this CommentDiscussion commentDiscussion) { return(commentDiscussion.Project.Claims.SingleOrDefault( c => c.CommentDiscussionId == commentDiscussion.CommentDiscussionId)); }
public static bool HasAnyAccess(this CommentDiscussion discussion, int currentUserId) { return(discussion.HasMasterAccess(currentUserId) || discussion.HasPlayerAccess(currentUserId)); }