Exemple #1
0
        public JsonResult GetComment(int?offset, int sizePage, int productID)
        {
            int offsetPage = offset.HasValue ? offset.Value : 0;                                                 //index tiep theo de lay
            IEnumerable <Comment> comments = _commentService.GetAll().Where(m => m.ProductID == productID && m.Type == 1 && m.isDelete == false).OrderByDescending(m => m.dateCreate).AsEnumerable();
            IEnumerable <Comment> c        = comments.Skip(offsetPage * sizePage).Take(sizePage).Select(m => m); //cat Array tu vi tri tiep theo + 3
            MoreCommentViewModel  models   = new MoreCommentViewModel();

            models.comments = c;
            offsetPage++;
            if (offsetPage == 0)//neu la vi tri mac dinh 0 thi vi tri tiep theo dc set se la 1
            {
                offsetPage = sizePage;
            }
            models.offset    = offsetPage;
            models.size      = sizePage;
            models.productId = productID;
            models.isNext    = false;
            if (comments.Count() > (offsetPage * sizePage)) //check xem con comment tiep theo ko?
            {
                models.isNext = true;
            }

            JsonResult result = new JsonResult();

            result.Data = models;
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            return(result);
        }
Exemple #2
0
        //GET: /Product/MoreComment/
        //comment ajax
        //partial view
        public ActionResult MoreComments(int?offset, int productID)
        {
            int offsetPage = offset.HasValue ? offset.Value : 0;                                                 //index tiep theo de lay
            int sizePage   = 3;                                                                                  //chi lay 3 comment
            IEnumerable <Comment> comments = _commentService.GetAll().Where(m => m.ProductID == productID && m.Type == 1 && m.isDelete == false).OrderByDescending(m => m.dateCreate).AsEnumerable();
            IEnumerable <Comment> c        = comments.Skip(offsetPage * sizePage).Take(sizePage).Select(m => m); //cat Array tu vi tri tiep theo + 3
            MoreCommentViewModel  models   = new MoreCommentViewModel();

            models.comments = c;
            offsetPage++;
            if (offsetPage == 0)//neu la vi tri mac dinh 0 thi vi tri tiep theo dc set se la 1
            {
                offsetPage = sizePage;
            }
            models.offset    = offsetPage;
            models.size      = sizePage;
            models.productId = productID;
            models.isNext    = false;
            if (comments.Count() > (offsetPage * sizePage)) //check xem con comment tiep theo ko?
            {
                models.isNext = true;
            }
            return(PartialView(models));
        }