public async Task <IActionResult> Post(UpdatePostModel model) { var post = await PostSvc.GetByIdAsync(model.Id); if (post == null) { return(new JsonResult(new APIResult <long> { ErrorMsg = "帖子不存在" }) { StatusCode = 400 }); } var statu = await StatuSvc.GetByIdAsync(model.PostStatusId); if (statu == null) { return(new JsonResult(new APIResult <long> { ErrorMsg = "帖子状态不存在" }) { StatusCode = 400 }); } UpdatePostDTO dto = new UpdatePostDTO(); dto.Id = model.Id; dto.PostStatusId = model.PostStatusId; dto.IsEssence = model.IsEssence; await PostSvc.UpdateAsync(dto); return(Ok()); }
public async Task <IActionResult> Detail(long postId) { ListContentPostDTO post; ListUserDTO user; string postCache = await RedisHelper.GetAsync($"postDetail_{postId}"); string userCache = await RedisHelper.GetAsync($"user_{postId}"); if (!string.IsNullOrEmpty(postCache) && !string.IsNullOrEmpty(userCache)) { post = JsonConvert.DeserializeObject <ListContentPostDTO>(postCache); user = JsonConvert.DeserializeObject <ListUserDTO>(userCache); } else { post = await PostSvc.GetByIdAsync(postId); user = await UserSvc.GetByIdAsync(post.UserId); if (post == null) { return(Json(new AjaxResult { Status = "redirect", Data = "/Error/Error404" })); } if (user == null) { return(Json(new AjaxResult { Status = "error", Data = UserSvc.ErrorMsg })); } await RedisHelper.SetAsync($"postDetail_{postId}", post); await RedisHelper.SetAsync($"user_{postId}", user); } long count = await RedisHelper.IncrByAsync("post_" + postId); PostDetailModel model = new PostDetailModel(); model.Post = post; model.User = user; model.LookCount = count; return(Json(new AjaxResult { Status = "ok", Data = model })); }
public async Task <IActionResult> UserCollectionPost(UserCollectionModel model) { var post = await PostSvc.GetByIdAsync(model.PostId); if (post == null) { return(new JsonResult(new APIResult <long> { ErrorMsg = "帖子不存在" }) { StatusCode = 400 }); } return(new JsonResult(new APIResult <long> { Data = await PostSvc.UserCollectionPostAsync(model.UserId, model.PostId) })); }
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> GetById(long id) { var post = await PostSvc.GetByIdAsync(id); if (post == null) { return(new JsonResult(new APIResult <long> { ErrorMsg = "帖子不存在" }) { StatusCode = 400 }); } return(new JsonResult(new APIResult <ListPostDTO>() { Data = post })); }
public async Task <IActionResult> GetByPostId(long postId, int pageIndex = 1, int pageDataCount = 10) { var post = await PostSvc.GetByIdAsync(postId); if (post == null) { return(new JsonResult(new APIResult <long> { ErrorMsg = "帖子不存在" }) { StatusCode = 400 }); } return(new JsonResult(new APIResult <ListModel <ListPostCommentDTO> > { Data = new ListModel <ListPostCommentDTO> { Datas = await CommentSvc.GetPageByPostIdAsync(postId, pageIndex, pageDataCount), TotalCount = await CommentSvc.GetTotalCountByPostIdAsync(postId) } })); }
public async Task <IActionResult> Put(AddCommentModel model) { var post = await PostSvc.GetByIdAsync(model.PostId); if (post == null) { return(new JsonResult(new APIResult <long> { ErrorMsg = "帖子不存在" }) { StatusCode = 400 }); } AddPostCommentDTO dto = new AddPostCommentDTO(); dto.CommentUserId = model.CommentUserId; dto.Content = model.Content; dto.PostId = model.PostId; dto.ReplyUserId = model.ReplyUserId; return(new JsonResult(new APIResult <long> { Data = await CommentSvc.AddNewAsync(dto) })); }
public async Task <IActionResult> Edit(long id) { var post = await PostSvc.GetByIdAsync(id); if (post == null) { return(NotFound()); } var user = await UserSvc.GetByIdAsync(post.UserId); if (user == null) { return(NotFound()); } var status = await PsSVC.GetAllAsync(); LookPostModel model = new LookPostModel(); model.Post = post; model.User = user; model.PostStatuses = status; return(View(model)); }
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()); }