public IActionResult Reply(int commentId) { try { var comment = this.dbContext.Comments.FirstOrDefault(x => x.Id == commentId); if (comment == null) { return(this.RedirectToAction("All")); } var user = this.dbContext.Users.FirstOrDefault(x => x.Id == comment.UserId); var @event = this.dbContext.Events.FirstOrDefault(x => x.Id == comment.EventId); var replyComment = new ReplyCommentViewModel { EventId = comment.EventId, EventName = @event.Title, Messege = comment.Messege, PostedOn = comment.PostedOn, UserId = comment.UserId, Username = comment.Username }; var reply = new ReplyViewModel { Img = user.Img, ReplyComment = replyComment, UserId = comment.UserId, CommentId = comment.Id, Username = comment.Username }; return(this.View(reply)); } catch (Exception) { return(this.View("Error")); } }
public void InsertNew(ReplyCommentViewModel entity) { replyCommentProvider.InsertNew(new ReplyCommentDTO { Id = entity.Id, MainCommentId = entity.MainCommentId, ReplyContent = entity.ReplyContent, UserName = entity.UserName }); }
public IActionResult ReplyAdd(ReplyCommentViewModel comment) { context.Comments.Add(new Comment() { CreateAt = DateTime.Now, Email = comment.Email, Name = comment.Name, ParentId = comment.ParentId, Text = comment.Text }); context.SaveChanges(); return(Ok()); }
public List <ReplyCommentViewModel> GetAll() { List <ReplyCommentViewModel> comments = new List <ReplyCommentViewModel>(); foreach (var comment in replyCommentProvider.GetAll()) { var newComment = new ReplyCommentViewModel(); newComment.Id = comment.Id; newComment.ReplyContent = comment.ReplyContent; newComment.MainCommentId = comment.MainCommentId; newComment.UserName = comment.UserName; comments.Add(newComment); } return(comments); }