Exemplo n.º 1
0
            private string GetNotificationEmailBody(MaterialComment parentComment, int commentId, string authorUserName, string commentText)
            {
                var host = _accessor.HttpContext.Request.Host;

                var link = parentComment.Type.ToString().ToLowerInvariant();

                var callbackUrl = $"https://{host}/{link}/{parentComment.MaterialId ?? parentComment.MatchId}#com{commentId}";

                return($"Пользователь {authorUserName} оставил <a href=\"{callbackUrl}\">ответ</a> на ваш комментарий: \"{commentText}\".");
            }
Exemplo n.º 2
0
            private async Task SendNotificationToEmailAsync(MaterialComment parentComment, int commentId, string authorUserName, string commentText)
            {
                const string newAnswer = "Новый ответ на ваш комментарий";
                var          user      = await _mediator.Send(new GetUserDetailQuery.Request {
                    Id = parentComment.AuthorId
                });

                if (user != null)
                {
                    await _messageService.SendEmailAsync(user.Email, newAnswer, GetNotificationEmailBody(parentComment, commentId, authorUserName, commentText));
                }
            }
Exemplo n.º 3
0
        public ActionResult AddComment(MaterialComment comment)
        {
            var userId = User.Identity.GetUserId();

            comment.DateAdd  = DateTime.Now;
            comment.AuthorId = userId;
            db.MaterialComments.Add(comment);
            db.SaveChanges();
            var allComments = db.MaterialComments.ToList();
            int id          = allComments.Last().Id;

            return(RedirectToAction("Comment", new { commentId = id }));
        }
Exemplo n.º 4
0
            private async Task SendNotificationAsync(MaterialComment parentComment, int commentId, string authorUserName, string commentText)
            {
                var notification = new CreateNotificationCommand.Request
                {
                    DateTime  = DateTimeOffset.Now,
                    UserId    = parentComment.AuthorId,
                    Type      = (NotificationType)parentComment.Type,
                    EntityId  = parentComment.MaterialId ?? parentComment.MatchId,
                    CommentId = commentId,
                    Text      = $"Пользователь {authorUserName} оставил ответ на ваш комментарий: \"{commentText}\"."
                };
                var notificationDto = await _mediator.Send(notification);

                _signalRHubAggregator.SendToUser(HubEndpointConstants.NewNotifyEndpoint, notificationDto, parentComment.AuthorId);
            }
Exemplo n.º 5
0
        private CommentDto GetComment(MaterialComment comment)
        {
            CommentDto commentDto = new CommentDto();

            if (comment != null)
            {
                var user = db.Users.Find(comment.AuthorId);
                commentDto.Id        = comment.Id;
                commentDto.DateAdd   = comment.DateAdd;
                commentDto.Text      = comment.Text;
                commentDto.FirstName = user.FirstName;
                commentDto.SurName   = user.SurName;
            }

            return(commentDto);
        }
Exemplo n.º 6
0
        public async Task <string> CommentMaterial(MaterialCommentInputModel model)
        {
            //TODO: Validate model
            var userId = httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;

            MaterialComment comment = new MaterialComment()
            {
                Text       = model.Text,
                AuthorId   = userId,
                MaterialId = model.MaterialId
            };

            db.MaterialComments.Add(comment);
            await db.SaveChangesAsync();

            var result = $"You have successfully made a comment!";

            return(result);
        }