public async Task <IActionResult> GetCommentByPostId(long postId, int pageIndex = 1, int pageDataCount = 5) { ListModel <ListPostCommentDTO> Comments = await CommentSvc.GetByPostIdAsync(postId, pageIndex, pageDataCount); if (Comments == null) { return(Json(new AjaxResult { Status = "error", ErrorMsg = CommentSvc.ErrorMsg })); } List <long> userIds = Comments.Datas.Select(e => e.CommentUserId).ToList(); var users = await UserSvc.GetByIdsAsync(userIds); if (users == null) { return(Json(new AjaxResult { Status = "error", ErrorMsg = UserSvc.ErrorMsg })); } PostDetailCommentModel model = new PostDetailCommentModel(); model.Comments = Comments.Datas; model.TotalCount = Comments.TotalCount; model.Users = users; return(Json(new AjaxResult { Status = "ok", Data = model })); }
public ActionResult Edit(CommentEditModel model) { CommentSvc.Update(model.id, model.phonenum, model.email, model.context); return(Json(new AjaxResult { status = "ok" })); }
public ActionResult Delete(long id) { CommentSvc.MarkDeleted(id); return(Json(new AjaxResult { status = "ok" })); }
public ActionResult BatchDelete(long[] selectedIds) { foreach (var id in selectedIds) { CommentSvc.MarkDeleted(id); } return(Json(new AjaxResult { status = "ok" })); }
public async Task <IActionResult> Comment(AddCommentModel model) { long userId = Convert.ToInt64(HttpContext.Session.GetString(ConstList.USERID)); model.CommentUserId = userId; var replyUserId = await UserSvc.GetByIdAsync(model.ReplyUserId); if (replyUserId == null) { return(Json(new AjaxResult { Status = "error", ErrorMsg = "您所回复的用户不存在" })); } if (await CommentSvc.AddNewAsync(model) < 1) { return(Json(new AjaxResult { Status = "error", ErrorMsg = CommentSvc.ErrorMsg })); } ListUserDTO commentUser = await UserSvc.GetByIdAsync(userId); ListContentPostDTO post; if (RedisHelper.Exists($"postDetail_{model.PostId}")) { post = JsonConvert.DeserializeObject <ListContentPostDTO>(await RedisHelper.GetAsync($"postDetail_{model.PostId}")); } else { post = await PostSvc.GetByIdAsync(model.PostId); await RedisHelper.SetAsync($"postDetail_{model.PostId}", post); } MessageModel msg = new MessageModel(); msg.CommentUserName = commentUser.NickName; msg.PostId = model.PostId; msg.ReplyUserId = model.ReplyUserId; msg.PostTitle = post.Title; await RedisHelper.SAddAsync($"msg_{model.ReplyUserId}", msg); return(Json(new AjaxResult { Status = "ok" })); }
public async Task <IActionResult> Home(long userId) { var user = await UserSvc.GetByIdAsync(userId); if (user == null) { return(Json(new AjaxResult { Data = "/Error/Error404" + "", Status = "redirect" })); } var posts = await PostSvc.GetQuestionPostByUserIdAsync(user.Id); var comments = await CommentSvc.GetByCommentUserIdAsync(userId); if (posts == null || comments == null) { return(Json(new AjaxResult { Data = "/Error/Error500" + "", Status = "redirect" })); } ListUserHomeModel model = new ListUserHomeModel(); var postIds = posts.Select(e => e.Id).ToList(); foreach (var item in postIds) { long look = await RedisHelper.IncrByAsync("post_" + item, 0); model.LookCount.Add(look); } model.Comments = comments; model.Posts = posts; return(Json(new AjaxResult { Data = model, Status = "ok" })); }
public async Task <IActionResult> AdoptPost(AdoptPostModel model) { var post = await PostSvc.GetByIdAsync(model.PostId); if (post == null) { return(new JsonResult(new APIResult <long> { ErrorMsg = "帖子不存在" }) { StatusCode = 400 }); } if (post.UserId != model.UserId) { return(new JsonResult(new APIResult <long> { ErrorMsg = "只有帖子拥有者才能采纳" }) { StatusCode = 400 }); } var comment = await CommentSvc.GetByIdAsync(model.CommentId); if (comment == null) { return(new JsonResult(new APIResult <long> { ErrorMsg = "评论Id不存在" }) { StatusCode = 400 }); } await PostSvc.AdoptPostAsync(model.UserId, model.PostId, model.CommentId); return(Ok()); }
public CommentController() { _svc = new CommentSvc(); }
public ActionResult Edit(long cid) { var comments = CommentSvc.GetById(cid); return(View(comments)); }
public ActionResult List() { var comments = CommentSvc.GetAll(); return(View(comments)); }