public ActionResult Article(int id = 0, int notifiId = 0) { if (id < 1) { return(HttpNotFound()); } if (notifiId > 0) { if (notificationRepo.View(User.Identity.GetUserId <int>(), notifiId)) { notifiCountCache.Update(User.Identity.GetUserId <int>(), -1); } } var article = repo.GetItem(id); Models.UrlHelper.validateURL(article); if (article == null) { return(HttpNotFound()); } var viewArticle = new ArticleForView(article); if (User.Identity.IsAuthenticated) { if (article.UserId == User.Identity.GetUserId <int>()) { viewArticle.Editable = true; } viewArticle.UserId = User.Identity.GetUserId <int>(); } else { viewArticle.UserId = 0; } ViewBag.MaxCommentLength = int.Parse(ConfigurationManager.AppSettings["MaxCommentLength"]); return(View(viewArticle)); }
public void Send(int articleId = 0, int replyCommentId = 0, string text = "") { text = text.Trim(); if (!commentsHelper.ValidateText(text)) { return; } if (replyCommentId < 0) { return; } var commentDepth = 0; var userIdentityId = Context.User.Identity.GetUserId <int>(); var name = Context.User.Identity.Name.Split('@')[0]; if (replyCommentId != 0) { var replyComment = commentsRepository.GetCommentInfo(replyCommentId); if (replyComment == null || replyComment.ArticleId != articleId) { return; } commentDepth = replyComment.Depth + 1; if (userIdentityId != replyComment.UserId) { Clients.Group("user-" + replyComment.UserId.ToString()).Notify(replyCommentId, name, text, articleId); notoficationsRepository.Save(new Notification() { CommentId = replyCommentId, FromWho = name, ArticleId = articleId, Message = text, UserId = replyComment.UserId }); notifiCountCache.Update(replyComment.UserId, +1); } } else { var authorId = articleRepository.GetUserId(articleId); if (authorId == 0) { return; } if (authorId != userIdentityId) { Clients.Group("user-" + authorId.ToString()).Notify(0, name, text, articleId); notoficationsRepository.Save(new Notification() { CommentId = 0, FromWho = name, ArticleId = articleId, Message = text, UserId = authorId }); notifiCountCache.Update(authorId, +1); } } Comment comment = new Comment(); comment.UserId = userIdentityId; comment.ArticleId = articleId; comment.Text = text; comment.UserName = Context.User.Identity.Name.Split('@')[0]; comment.Depth = commentDepth; comment.Created = DateTime.Now; comment.ReplyCommentId = replyCommentId; comment.Deleted = false; var id = commentsRepository.Save(comment); Clients.Group("article-" + articleId.ToString()).addMessage(id, userIdentityId, comment.UserName, comment.Text, comment.Created.ToString("yyyy-MM-dd HH:mm:ss"), replyCommentId); }