public async Task <ActionResult> AddComment(string courseId, Guid slideId, string commentText, string parentCommentId) { var parentCommentIdInt = -1; if (parentCommentId != null) { int.TryParse(parentCommentId, out parentCommentIdInt); } if (!CanAddCommentHere(User, courseId, parentCommentIdInt != -1)) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } if (!CanAddCommentNow(User, courseId)) { return(Json(new { status = "too-fast", message = "Вы комментируете слишком быстро. Подождите немного...", })); } if (commentText.Length > CommentsPolicy.MaxCommentLength) { return(Json(new { status = "too-long", message = "Слишком длинный комментарий. Попробуйте сократить мысль.", })); } var comment = await commentsRepo.AddComment(User, courseId, slideId, parentCommentIdInt, commentText); await commentsBot.PostToChannel(comment); var canReply = CanAddCommentHere(User, courseId, true); return(PartialView("_Comment", new CommentViewModel { Comment = comment, LikesCount = 0, IsLikedByUser = false, Replies = new List <CommentViewModel>(), IsCommentVisibleForUser = true, CanEditAndDeleteComment = true, CanModerateComment = User.HasAccessFor(courseId, CourseRole.Instructor), CanReply = canReply, CurrentUser = userManager.FindById(User.Identity.GetUserId()), })); }
public async Task <ActionResult> AddComment(string courseId, Guid slideId, bool forInstructorsOnly, string commentText, string parentCommentId) { var parentCommentIdInt = -1; if (parentCommentId != null) { int.TryParse(parentCommentId, out parentCommentIdInt); } if (!CanAddCommentHere(User, courseId, parentCommentIdInt != -1)) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } if (!CanAddCommentNow(User, courseId)) { return(Json(new { status = "too-fast", message = "Вы комментируете слишком быстро. Подождите немного...", })); } if (commentText.Length > CommentsPolicy.MaxCommentLength) { return(Json(new { status = "too-long", message = "Слишком длинный комментарий. Попробуйте сократить мысль.", })); } if (forInstructorsOnly && !CanViewAndAddCommentsForInstructorsOnly(User, courseId)) { forInstructorsOnly = false; } var comment = await commentsRepo.AddComment(User, courseId, slideId, parentCommentIdInt, forInstructorsOnly, commentText); if (comment.IsApproved) { await NotifyAboutNewComment(comment); } var canReply = CanAddCommentHere(User, courseId, isReply: true); var userId = User.Identity.GetUserId(); var canViewAuthorSubmissions = coursesRepo.HasCourseAccess(userId, courseId, CourseAccessType.ViewAllStudentsSubmissions) || User.HasAccessFor(courseId, CourseRole.CourseAdmin); var canViewProfiles = systemAccessesRepo.HasSystemAccess(userId, SystemAccessType.ViewAllProfiles) || User.IsSystemAdministrator(); return(PartialView("_Comment", new CommentViewModel { Comment = comment, LikesCount = 0, IsLikedByUser = false, Replies = new List <CommentViewModel>(), IsCommentVisibleForUser = true, CanEditAndDeleteComment = true, CanModerateComment = User.HasAccessFor(courseId, CourseRole.Instructor), CanReply = canReply, CurrentUser = userManager.FindById(User.Identity.GetUserId()), CanViewAuthorProfile = canViewProfiles, CanViewAuthorSubmissions = canViewAuthorSubmissions, })); }