示例#1
0
        private ProductDTOViewModel GetViewModel(int?CategoryId = null)
        {
            int pageId       = GetLastPageId();
            int itemsPerPage = GetItemsPerPage();

            /////filters
            var IsAdmin = Request.IsAuthenticated && User.IsInRole("admin");

            var predicate = PredicateBuilder.New <ProductDTO>(true);

            predicate.And(x => x.CategoryId == CategoryId);
            if (!IsAdmin)
            {
                predicate.And(x => x.IsPublished);
            }
            /////

            int pageCount = selector.GetPageCount(itemsPerPage, predicate);
            var list      = selector.GetItemList(predicate)
                            .OrderBy(x => x.ProductName)
                            .Skip((pageId - 1) * itemsPerPage)
                            .Take(itemsPerPage);
            var model = new ProductDTOViewModel()
            {
                CategoryId     = CategoryId,
                Products       = list.ToList(),
                PageCount      = pageCount,
                Specifications = uof.Category.Get(CategoryId)?.SpecificationTypes.ToArray()
            };

            return(model);
        }
示例#2
0
        private async Task <SpecificationTypeDTOViewModel> GetViewModelAsync()
        {
            int pageId = GetLastPageId();

            //change for filters
            /////
            var predicate = PredicateBuilder.New <SpecificationTypeDTO>(true);
            /////

            int pageCount = await Task.Factory.StartNew(() => selector.GetPageCount(itemsPerPage, predicate));

            var list = await Task.Factory.StartNew(() => selector.GetItemList(predicate)
                                                   .OrderBy(x => x.SpecificationName)
                                                   .Skip((pageId - 1) * itemsPerPage)
                                                   .Take(itemsPerPage));

            var model = new SpecificationTypeDTOViewModel()
            {
                Specifications = list.ToList(),
                PageCount      = pageCount
            };

            return(model);
        }