public async Task <IHttpActionResult> GetReplyById(int id) { ReplyService service = CreateReplyService(); ReplyDetail reply = await service.GetReplyById(id); return(Ok(reply)); }
public ActionResult Delete(int id, ReplyDetail model) { var svc = CreateReplyService(); var reply = svc.GetReplyByID(id); int postId = reply.PostID; svc.DeleteReply(model.ID); return(RedirectToAction($"../Post/Details/{postId}")); }
public bool UpdateReply(ReplyDetail model) { using (var ctx = new ApplicationDbContext()) { var entity = GetReplyByID(model.ReplyId); entity.Content = model.Content; entity.ModifiedUTC = model.ModifiedUTC; return(ctx.SaveChanges() > 0); } }
// Get --Retrieve Reply Detail by id public ReplyDetail GetReplyDetail(int Id) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Replies.Single(e => e.Id == Id); var detailedReply = new ReplyDetail { Id = entity.Id, Text = entity.Text, CommentorsName = entity.Commenter != null ? entity.Commenter.FullName : "unknown", Replies = AddReplies(entity.Replies) }; return(detailedReply); } }
public async Task <ReplyDetail> GetReplyById(int id) { List <Reply> replies = await _context.Replies.ToListAsync(); Reply replyToGet = replies.Single(reply => reply.ReplyId == id); ReplyDetail replyDetail = new ReplyDetail() { ReplyId = replyToGet.ReplyId, Author = replyToGet.Author, Text = replyToGet.Text, CreatedUtc = replyToGet.CreatedUtc, ModifiedUtc = replyToGet.ModifiedUtc, Comment = replyToGet.Comment }; return(replyDetail); }
//Recursive function to Add replies private List <ReplyDetail> AddReplies(ICollection <Reply> replies) { if (replies.Count == 0) { return(new List <ReplyDetail>()); } var DetailedReplies = new List <ReplyDetail>(); foreach (var reply in replies) { var DetailedReply = new ReplyDetail { Id = reply.Id, Text = reply.Text, CommentorsName = reply.Commenter != null ? reply.Commenter.FullName : "Unknown" }; DetailedReply.Replies = AddReplies(reply.Replies); DetailedReplies.Add(DetailedReply); } return(DetailedReplies); }
//Recursive function to Add replies private List <ReplyDetail> AddReplies(ICollection <Reply> replies) { if (replies.Count == 0) { return(new List <ReplyDetail>()); } var DetailedReplies = new List <ReplyDetail>(); foreach (var reply in replies) { var DetailedReply = new ReplyDetail { Id = reply.Id, Text = reply.Text, //Using ternary incase of comment not having author CommentorsName = (reply.Comment != null ? reply.Commenter.FullName : "Unknown") }; DetailedReply.Replies = AddReplies(reply.Replies); DetailedReplies.Add(DetailedReply); } return(DetailedReplies); }
/// <summary> /// 从 PostInfo 中提取 ReplyDetail /// </summary> /// <param name="postInfo"></param> /// <param name="userId">当前用户编号,用于判断当前用户是否为帖子的发布者</param> /// <returns></returns> internal static ReplyDetail ToReplyDetail(this PostInfo postInfo, int userId) { ReplyDetail reply = new ReplyDetail { Id = postInfo.PostId, Owner = UserBiz.ReadUserCacheInfo(postInfo.UserId).ToUserBase(), Content = postInfo.Content.GetTopicContentList(), IsBestAnswer = postInfo.IsBestReply, FavouredCount = postInfo.FavouredCount, PublishTime = postInfo.CreateDate.ToString("yyyy-MM-dd HH:mm:ss"), ExpChanged = postInfo.ExpChanged, VirtualCoinChanged = postInfo.VirtualCoinChanged, IFavoured = true, SetBestDate = "", TargetUser = null }; if (userId != postInfo.UserId) { reply.IFavoured = BbsBiz.UserFavouredPost(userId, postInfo.PostId); } if (postInfo.IsBestReply) { reply.SetBestDate = postInfo.SetBestDate.ToString("yyyy-MM-dd HH:mm:ss"); } /* * if (postInfo.ReplyForUserId > 0) * { * reply.TargetUser = UserBiz.ReadUserCacheInfo(postInfo.ReplyForUserId).ToUserBase(); * } */ return(reply); }