示例#1
0
        public async Task <IActionResult> Index()
        {
            int?id          = HttpContext.Session.GetInt32("CommentsID"); /// pull saved recipe id from session located in saved recipe controller, details method
            var allComments = await _context.GetComments();

            if (allComments == null)
            {
                return(NotFound());
            }
            return(View(allComments));
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="search"></param>
        /// <returns></returns>
        public PartialViewResult Index(CommentSearch search)
        {
            string order = search.Order == 0 ? "ASC" : "DESC";

            if (search.PageIndex < 1)
            {
                search.PageIndex = 1;
            }
            int pageSize  = Site.Config.PageConfig.WebCommentPageSize;
            int dataCount = 0;
            var list      = new List <CommentEntity>();
            var comments  = Comments.GetComments(search.PageIndex, pageSize, search.AId, search.AuthorId, order, out dataCount);

            if (comments != null)
            {
                var users = Users.GetUsersByIds(comments.Select(n => n.UserId).ToArray());
                foreach (var comment in comments)
                {
                    var user = new UserVModel();
                    if (users.Any(n => n.Id == comment.UserId))
                    {
                        user = users.FirstOrDefault(n => n.Id == comment.UserId);
                    }
                    list.Add(new CommentEntity
                    {
                        Comment = comment,
                        User    = user
                    });
                }
            }
            PagedList <CommentEntity> pageList = list.ToPagedList(search.PageIndex, pageSize);

            pageList.TotalItemCount   = dataCount;
            pageList.CurrentPageIndex = search.PageIndex;
            //如果登录的话取得登录用户对该帖子下所有评论的点赞记录
            if (UserIsLogin)
            {
                List <long> commentIds = DianZanLogsPublic.GetUserAllDianZanCommentId(CurrentUserInfo.Id, search.AId);
                if (commentIds.Count > 0)
                {
                    pageList.ForEach(c => c.IsZan = commentIds.Any(n => n == c.Comment.Id));
                }
            }
            ViewBag.search = search;
            return(PartialView(pageList));
        }
示例#3
0
 public IEnumerable <RequestComment> GetComments(int id)
 {
     return(comments.GetComments(id));
 }
示例#4
0
        public ActionResult GetComments(WorksViewModel work)
        {
            HttpCookie cookieReqs = Request.Cookies["My localhost cookie"];
            int        idsWork    = work.Id;

            int idsUser = 0;

            if (cookieReqs != null)
            {
                idsUser = Convert.ToInt32(cookieReqs["ids"]);
            }
            else
            {
                FormsAuthentication.SignOut();
            }

            if (work.UserId != 0)
            {
                RatingsBO userRatingForWork = ratingServ.GetRatings().Where(x => x.UserId == idsUser && x.WorkId == idsWork).FirstOrDefault();

                RatingsBO newRating = new RatingsBO();
                newRating.Rank   = work.UserId;
                newRating.UserId = idsUser;
                newRating.WorkId = idsWork;

                if (userRatingForWork != null)
                {
                    RatingsBO old = ratingServ.GetRating(userRatingForWork.Id);
                    ratingServ.DeleteRating(old.Id);
                    ratingServ.Create(newRating);
                }
                else
                {
                    ratingServ.Create(newRating);
                }
            }



            if (work.Name != null)
            {
                CommentsBO newComment = new CommentsBO();
                newComment.Comment = work.Name;
                newComment.UserId  = idsUser;
                newComment.WorkId  = idsWork;
                CommentsBO test = commentServ.GetComments().Where(x => x.UserId == idsUser && x.WorkId == idsWork).FirstOrDefault();

                if (commentServ.GetComments().Where(x => x.UserId == idsUser && x.WorkId == idsWork).FirstOrDefault() != null)
                {
                    CommentsBO old = commentServ.GetComment(test.Id);
                    commentServ.DeleteComment(old.Id);
                    commentServ.Create(newComment);
                }
                else
                {
                    commentServ.Create(newComment);
                }
            }

            var commentList = commentServ.GetComments().Join(workServ.GetWorks(),
                                                             c => c.WorkId,
                                                             w => w.Id, (c, w) => new { Id = c.Id, Comment = c.Comment, UserId = c.UserId, WorkId = c.WorkId }).Join(userServ.GetUsers(),
                                                                                                                                                                     c => c.UserId,
                                                                                                                                                                     u => u.Id, (c, u) => new InfoModelWithComments {
                Id = c.Id, UserName = u.Login, Comment = c.Comment, WorkId = c.WorkId, IsDelete = u.IsDelete
            }).ToList();

            foreach (var item in commentList)
            {
                if (item.IsDelete == true)
                {
                    item.UserName = "******";
                }
            }
            ViewBag.CommentsList = commentList.Where(c => c.WorkId == idsWork).ToList();



            List <RatingsBO> lst = ratingServ.GetRatings().Where(x => x.WorkId == idsWork).Join(userServ.GetUsers(),
                                                                                                c => c.UserId,
                                                                                                u => u.Id, (c, u) => new RatingsBO {
                Id = c.Id, Rank = c.Rank, UserId = c.UserId, WorkId = c.WorkId, IsDeleteCheck = u.IsDelete
            }).Where(x => x.IsDeleteCheck == false).ToList();

            if (lst.Count != 0)
            {
                int sum    = 0;
                int rating = 0;
                foreach (var item in lst)
                {
                    sum += item.Rank;
                }
                rating          = sum / lst.Count;
                ViewBag.Ratings = rating;
            }
            else
            {
                ViewBag.Ratings = 0;
            }
            return(View("_CommentsTable"));
        }