예제 #1
0
        public ActionResult ReadNews(int newsId, int numberNews)
        {
            Stack <Comment> comments = new Stack <Comment>();

            NewService.currentStateNews = NewService.GetNew(newsId);
            comments = CommentsService.GetListComments(NewService.currentStateNews);
            JsonController.countComments = CommentsService.GetCountComments();


            List <int> countLikeList = new List <int>();
            int        rating        = 0;

            using (SampleContext context = new SampleContext())
            {
                foreach (var item in comments)
                {
                    var rowUser = context.users.SingleOrDefault(x => x.userId == item.userId);
                    if (rowUser != null)
                    {
                        if (rowUser.countLike >= 0)
                        {
                            countLikeList.Add(rowUser.countLike);
                        }
                    }
                    else
                    {
                        countLikeList.Add(0);
                    }
                }
                try
                {
                    int countLikeUser = context.users.SingleOrDefault(x => x.userId == NewService.currentStateNews.userId).countLike;
                    rating = countLikeUser;
                }
                catch { }
            }

            ViewBag.countLike      = rating;
            ViewBag.usersCountLike = countLikeList;
            ViewBag.comment        = comments;
            ViewBag.news           = NewService.currentStateNews;
            ViewBag.numberNews     = numberNews;
            return(View());
        }