public virtual PartialViewResult Edit(CommentEditModel model) { var editCommentId = FullContext.Value.EntityId.Value; var commentsTarget = FullContext.GetCommentsTarget(); var targetEntityId = commentsTarget.EntityId.Value; if (!ModelState.IsValid) { return(OverView(editCommentId)); } var comment = _commentsService.Get(editCommentId); if (!_commentsService.CanEdit(comment, _intranetUserService.GetCurrentUserId())) { return(OverView(editCommentId)); } var editDto = MapToEditDto(model, editCommentId); var command = new EditCommentCommand(FullContext, editDto); _commandPublisher.Publish(command); switch (commentsTarget.Type.ToInt()) { case int type when ContextExtensions.HasFlagScalar(type, ContextType.Activity | ContextType.PagePromotion): var activityCommentsInfo = GetActivityComments(targetEntityId); return(OverView(activityCommentsInfo)); default: return(OverView(comment.ActivityId)); } }
public async Task <CommentsOverviewModel> Edit(CommentEditModel model) { var comment = await _commentsService.GetAsync(model.Id); if (!_commentsService.CanEdit(comment, await _intranetMemberService.GetCurrentMemberIdAsync())) { return(await _commentsHelper.OverViewAsync(model.Id)); } var editDto = MapToEditDto(model, model.Id); var command = new EditCommentCommand(model.EntityId, model.EntityType, editDto); _commandPublisher.Publish(command); await OnCommentEditedAsync(model.Id, model.EntityType); switch (model.EntityType) { case IntranetEntityTypeEnum type when type.Is(IntranetEntityTypeEnum.News, IntranetEntityTypeEnum.Social, IntranetEntityTypeEnum.Events): var activityCommentsInfo = GetActivityComments(model.EntityId); return(await _commentsHelper.OverViewAsync(activityCommentsInfo.Id, activityCommentsInfo.Comments, activityCommentsInfo.IsReadOnly)); default: return(await _commentsHelper.OverViewAsync(comment.ActivityId)); } }
public virtual CommentViewModel GetCommentView(CommentModel comment, Guid currentMemberId, IIntranetMember creator) { var likes = _likesService.GetLikeModels(comment.Id).ToArray(); var memberId = _intranetMemberService.GetCurrentMemberId(); var model = comment.Map <CommentViewModel>(); model.ModifyDate = _commentsService.WasChanged(comment) ? comment.ModifyDate.ToDateTimeFormat() : null; model.CanEdit = _commentsService.CanEdit(comment, currentMemberId); model.CanDelete = _commentsService.CanDelete(comment, currentMemberId); model.Creator = creator.ToViewModel(); model.ElementOverviewId = GetOverviewElementId(comment.ActivityId); model.CommentViewId = _commentsService.GetCommentViewId(comment.Id); model.CreatorProfileUrl = creator == null ? null : _profileLinkProvider.GetProfileLink(creator); model.LinkPreview = comment.LinkPreview.Map <LinkPreviewModel>(); model.LikedByCurrentUser = likes.Any(el => el.UserId == memberId); model.Likes = likes; model.LikeModel = GetLikesViewModel(comment.Id, memberId, likes); return(model); }