Ejemplo n.º 1
0
        public async Task <IHttpActionResult> GetReplyById(int id)
        {
            ReplyService service = CreateReplyService();
            ReplyDetail  reply   = await service.GetReplyById(id);

            return(Ok(reply));
        }
Ejemplo n.º 2
0
        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}"));
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        //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);
        }
Ejemplo n.º 7
0
        //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);
        }
Ejemplo n.º 8
0
        /// <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);
        }