예제 #1
0
        public void Can_Send_Pagination_View_Model()
        {
            // Arrange
            Mock <IReviewRepository> mock = new Mock <IReviewRepository>();

            mock.Setup(m => m.Reviews).Returns(new Review[] {
                new Review {
                    ReviewID = 1, Company = "C1", Person = "P1", Mark = 1
                },
                new Review {
                    ReviewID = 2, Company = "C2", Person = "P2", Mark = 2
                },
                new Review {
                    ReviewID = 3, Company = "C3", Person = "P3", Mark = 3
                },
                new Review {
                    ReviewID = 4, Company = "C4", Person = "P4", Mark = 4
                },
                new Review {
                    ReviewID = 5, Company = "C5", Person = "P5", Mark = 5
                }
            }.AsQueryable());

            ReviewController controller = new ReviewController(mock.Object);

            controller.PageSize = 3;
            ReviewsListViewModel result = (ReviewsListViewModel)controller.List(2).Model;

            PagingInfo pageInfo = result.PagingInfo;

            Assert.AreEqual(pageInfo.CurrentPage, 2);
            Assert.AreEqual(pageInfo.ItemsPerPage, 3);
            Assert.AreEqual(pageInfo.TotalItems, 5);
            Assert.AreEqual(pageInfo.TotalPages, 2);
        }
        public async Task <ActionResult> GetGoodsDescription(int?goodsId, int page = 1)
        {
            if (goodsId != null)
            {
                GoodsModel goods = await _repository.GetGoodsByIdAsync((int)goodsId);

                if (goods != null)
                {
                    ICollection <ReviewModel> reviews = await this._reviewRepository.GetReviewsByGoodsIdForOnePageAsync((int)goodsId, pageSizeForReviews, page);

                    PagingInfo pageInfo = new PagingInfo
                    {
                        CurrentPage  = page,
                        ItemsPerPage = pageSizeForReviews,
                        TotalItems   = await this._reviewRepository.GetCountReviewsByGoodsIdAsync((int)goodsId)
                    };

                    ReviewsListViewModel model = new ReviewsListViewModel
                    {
                        Reviews    = reviews,
                        PagingInfo = pageInfo,
                        Goods      = goods,
                    };
                    return(View(model));
                }
                else
                {
                    return(new HttpNotFoundResult());
                }
            }
            else
            {
                return(RedirectToAction("GoodsCards"));
            }
        }
 public DBReviewPage(IList <ReviewDetailsDataModel> reviewData)
 {
     InitializeComponent();
     viewModel        = new ReviewsListViewModel();
     BindingContext   = viewModel;
     singleReviewData = new ObservableCollection <ReviewDetailsDataModel>();
     foreach (ReviewDetailsDataModel ReviewModel in reviewData)
     {
         singleReviewData.Add(new ReviewDetailsDataModel()
         {
             ReviewID       = ReviewModel.ReviewID,
             CategoryName   = ReviewModel.CategoryName,
             ProductName    = ReviewModel.ProductName,
             ProductKey     = ReviewModel.ProductKey,
             UserName       = ReviewModel.UserName,
             ReviewStatus   = ReviewModel.ReviewStatus,
             ScoreValue     = ReviewModel.ScoreValue,
             DateTime       = ReviewModel.DateTime,
             ReviewText     = ReviewModel.ReviewText,
             ReviewUseful   = ReviewModel.ReviewUseful,
             ReviewUnuseful = ReviewModel.ReviewUnuseful,
             ProductPros    = ReviewModel.ProductPros,
             ProductCons    = ReviewModel.ProductCons,
             ReviewsCount   = ReviewModel.ReviewsCount,
             IsVisible      = ReviewModel.IsVisible
         });
     }
     viewModel.ReviewList = singleReviewData;
 }
예제 #4
0
        public ActionResult List(int?page = 1)
        {
            var currentPage = page ?? 1;
            ReviewsListViewModel reviewModel = new ReviewsListViewModel
            {
                Reviews = repository.Reviews
            };
            var resultReviews = reviewModel.GetReviewsOnPage(ref currentPage, ref PageSize);

            if (Request.IsAjaxRequest())
            {
                return(PartialView("_ReviewRow", resultReviews));
            }
            return(View(resultReviews));
        }
예제 #5
0
        public async Task <ActionResult> Reviews(SearchReview search, int page = 1)
        {
            ICollection <ReviewModel> reviews = await this._reviewRepository.GetReviewsForOnePageAsync(search, pageSize, page);

            PagingInfo pageInfo = new PagingInfo
            {
                CurrentPage  = page,
                ItemsPerPage = pageSize,
                TotalItems   = await this._reviewRepository.GetCountReviewsAsync(search)
            };
            ReviewsListViewModel model = new ReviewsListViewModel()
            {
                Reviews    = reviews,
                PagingInfo = pageInfo,
                Search     = search
            };

            return(PartialView("_PartialAdmin_Reviews", model));
        }
예제 #6
0
        public ViewResult List(int page = 1)
        {
            ReviewsListViewModel model = new ReviewsListViewModel
            {
                Reviews = repository.Reviews
                          .OrderByDescending(p => p.ReviewID)
                          .Skip((page - 1) * PageSize)
                          .Take(PageSize),

                PagingInfo = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = PageSize,
                    TotalItems   = repository.Reviews.Count()
                }
            };

            return(View(model));
        }
        public async Task <ActionResult> ListReviews(int?goodsId, int page = 1)
        {
            if (goodsId != null)
            {
                ICollection <ReviewModel> reviews = await this._reviewRepository.GetReviewsByGoodsIdForOnePageAsync((int)goodsId, pageSizeForReviews, page);

                PagingInfo pageInfo = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = pageSizeForReviews,
                    TotalItems   = await this._reviewRepository.GetCountReviewsByGoodsIdAsync((int)goodsId)
                };
                GoodsModel goods = await this._repository.GetGoodsByIdAsync((int)goodsId);

                ReviewsListViewModel model = new ReviewsListViewModel {
                    Reviews = reviews, PagingInfo = pageInfo, Goods = goods
                };
                return(PartialView("_PartialReviews", model));
            }
            return(new HttpNotFoundResult());
        }