Exemplo n.º 1
0
        public async Task <Unit> Handle(UpdateSubCommentCommand request, CancellationToken cancellationToken)
        {
            var subComment = await _context.SubComments.FindAsync(request.Id);

            subComment.UpdateComment(subComment, request.Message);

            _context.SubComments.Update(subComment);

            await _context.SaveChangesAsync(cancellationToken);

            // ------------------------------
            // Send email to mentioned users
            var emails = request.Message.FindEmails();

            if (emails.Count == 0)
            {
                return(Unit.Value);
            }

            var mainComment = await _context.MainComments.FindAsync(subComment.MainCommentId);

            var notification = new SendCommentEmail()
            {
                PrimaryEntityId = mainComment.RecordId,
                UserName        = subComment.AuthorName,
                Recipients      = emails,
                AuthorName      = subComment.AuthorName,
                Message         = subComment.Message
            };

            await _mediator.Publish(notification);

            return(Unit.Value);
        }
Exemplo n.º 2
0
        public async Task <Unit> Handle(CreateSubCommentCommand request, CancellationToken cancellationToken)
        {
            var userClaims = _userAccessor.GetUser();

            var userId = Guid.Parse(userClaims.FindFirst(ClaimTypes.NameIdentifier).Value);

            var user = await _context.ApplicationUsers.FindAsync(userId);

            var subComment = new SubComment(request.MainCommentId, user, request.Message);

            await _context.SubComments.AddAsync(subComment, cancellationToken);

            await _context.SaveChangesAsync(cancellationToken);

            // ------------------------------
            // Send email to mentioned users
            var emails = request.Message.FindEmails();

            if (emails.Count == 0)
            {
                return(Unit.Value);
            }

            var mainComment = await _context.MainComments.FindAsync(subComment.MainCommentId);

            var notification = new SendCommentEmail()
            {
                PrimaryEntityId = mainComment.RecordId,
                UserName        = subComment.AuthorName,
                Recipients      = emails,
                AuthorName      = subComment.AuthorName,
                Message         = subComment.Message,
            };

            await _mediator.Publish(notification);

            return(Unit.Value);
        }