public async Task <ActionResult> CreateComment([Bind(Include = "CommentId,ThreadId,UserId,CommentText,DateCreated")] CommentReplyViewModel comment) { HtmlToText convert = new HtmlToText(); Comment com = new Comment(); com.ThreadId = comment.ThreadId; com.CommentText = comment.CommentText; com.UserId = User.Identity.GetUserId(); com.DateCreated = DateTime.UtcNow; if (ModelState.IsValid) { _applicationDbContext.Comments.Add(com); await _applicationDbContext.SaveChangesAsync(); return(Json(new { success = true })); } else { //return RedirectToAction("DisplayReplySection", new { Controller = "Report", action = "DisplayReplySection", title = comment.PageTitle, page = comment.ReportId}); } return(View()); }
public async Task <bool> ReplyComment(CommentReplyViewModel replyViewModel) { using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { try { var post = await _unitOfWork.Repository <Post>().Query().Where(cm => cm.Id == replyViewModel.PostId).SingleOrDefaultAsync(); var comment = new Comment { ParentId = replyViewModel.ParentId, Post = post, CommentStatus = CommentStatus.Pending, Content = replyViewModel.CommentBody, User = await _userService.GetCurrentUserAsync() }; await _unitOfWork.Repository <Comment>().AddAsync(comment); transaction.Complete(); return(true); } catch (Exception) { _unitOfWork.Rollback(); return(false); } } }
public async Task <IActionResult> ReplyComment([FromBody] CommentReplyViewModel replyViewModel) { var result = await _commentRepository.ReplyComment(replyViewModel); if (result) { return(Ok()); } return(BadRequest()); }
public ActionResult PostCommentReply(CommentReplyViewModel obj) { int userid = 1; AnCommentReply reply = new AnCommentReply(); reply.UserId = userid; reply.CommentReplyText = obj.AnCommentReply; if (reply.CommentReplyText == null) { return(RedirectToAction("Error")); } reply.CommentId = obj.ACommentId; db.AnCommentReplys.Add(reply); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <bool> ReplyComment(CommentReplyViewModel replyViewModel) { using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { try { var existingComment = await _unitOfWork.Repository <Comment>().Query().Where(cm => cm.Id == replyViewModel.Comment.Id).SingleOrDefaultAsync(); var reciever = existingComment.User.Email; var userReply = await _userService.GetCurrentUserAsync(); var comment = new Comment { CommentStatus = CommentStatus.Pending, Content = replyViewModel.CommentBody, User = userReply, Post = existingComment.Post, ParentComment = existingComment }; _dbContext.Set <Comment>().Attach(comment); await _unitOfWork.Repository <Comment>().AddAsync(comment); var emailOptions = new EmailOptions { UserComment = reciever, UserReply = userReply.Email, Url = $"Post/{existingComment.Post.Id}" }; await _emailSender.SendEmailAsync(reciever, null, emailOptions, EmailType.ReplyComment); transaction.Complete(); return(true); } catch (Exception ex) { _unitOfWork.Rollback(); return(false); } } }
public ActionResult DisplayReplySection(int page, int randRid) { var UserId = User.Identity.GetUserId(); var loggedUserByUserId = _applicationDbContext.Users.SingleOrDefault(i => i.Id == UserId); if (loggedUserByUserId.Career == "General") { CommentReplyViewModel replyModel = new CommentReplyViewModel(); HtmlToText convert = new HtmlToText(); var threadById = _applicationDbContext.Threads.Where(m => m.ThreadId == page).SingleOrDefault(); var ReportByID = _applicationDbContext.Reports.Where(m => m.ReportId == randRid).SingleOrDefault(); string rawPageTitle = convert.Convert(ReportByID.ReportText).Substring(0, 90); int indexP = rawPageTitle.LastIndexOf(' '); string titleOutput = rawPageTitle.Substring(0, indexP); string PageTitle = ReportByID.CompanyorIndividual + " : " + titleOutput; string sm_PageTitle = Regex.Replace(PageTitle, "[^A-Za-z0-9]", "-"); //string myString = threadById.ThreadText; replyModel.ThreadId = threadById.ThreadId; replyModel.ThreadText = convert.Convert(threadById.ThreadText); replyModel.PageTitle = sm_PageTitle; replyModel.ReportId = ReportByID.ReportId; replyModel.RandomId = Guid.NewGuid().ToString(); return(PartialView("_ReplyModal", replyModel)); } else { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); return(RedirectToAction("Login", "Account")); } }
public async Task <ActionResult> Create([Bind(Include = "CommentId,ThreadId,UserId,CommentText,DateCreated")] CommentReplyViewModel comment) { HtmlToText convert = new HtmlToText(); Comment com = new Comment(); com.ThreadId = comment.ThreadId; com.CommentText = comment.CommentText; com.UserId = User.Identity.GetUserId(); com.DateCreated = DateTime.UtcNow; if (ModelState.IsValid) { _applicationDbContext.Comments.Add(com); await _applicationDbContext.SaveChangesAsync(); return(Json(new { success = true })); } else { } return(View()); }