Esempio n. 1
0
 public PagedCollection<ProductRequest> GetProductsByType(int pageindex, int pagesize, PrdType prdType)
 {
     var prds = _productRepository.GetByType(pageindex, pagesize, prdType);
     List<ProductRequest> prdRequests = new List<ProductRequest>();
     foreach (var prd in prds.Items)
     {
         ProductRequest prdReqeust = _productMapper_ptov.Map(prd);
         prdRequests.Add(prdReqeust);
     }
     return new PagedCollection<ProductRequest>(prdRequests, prds.PageIndex, prds.PageSize, prds.ItemCount);
 }
 private List<Product> FindByType(PrdType prdType)
 {
     List<Product> result = new List<Product>();
     var builder = Builders<BsonDocument>.Filter;
     var filter = builder.Eq("Status", 0) | builder.Exists("Status", false);
     filter = filter & builder.Eq("Type", (int)prdType);
     var sort = Builders<BsonDocument>.Sort.Descending("UpdateDate");
     _collection.Find(filter).Sort(sort).ToListAsync().ContinueWith(t =>
     {
         var list = t.Result;
         foreach (var item in list)
         {
             result.Add(item.ToProduct());
         }
     }).Wait();
     return result;
 }
Esempio n. 3
0
 private PagedCollection<IndexProduct> GetProducts(int pageindex, int pagesize, ImageSize imgSize, PrdType prdType)
 {
     var pagedProducts = _adminService.GetProductsByType(pageindex, pagesize, prdType);
     List<IndexProduct> indexProducts = new List<IndexProduct>();
     foreach (var item in pagedProducts.Items)
     {
         var imgs = _imgService.GetImages(item._id);
         var selectImg = imgs.FirstOrDefault(m => m.Width == imgSize.Width && m.Height == imgSize.Height);
         if (selectImg == null) continue;
         IndexProduct idxProduct = new IndexProduct();
         idxProduct.Product = item;
         idxProduct.Image = selectImg;
         indexProducts.Add(idxProduct);
     }
     return new PagedCollection<IndexProduct>(indexProducts, pagedProducts.PageIndex,
         pagedProducts.PageSize, pagedProducts.ItemCount);
 }
 public PagedCollection<Product> GetByType(int pageindex, int pagesize, PrdType prdType)
 {
     var fullList = FindByType(prdType);
     List<Product> prds = fullList.Skip((pageindex - 1) * pagesize).Take(pagesize).ToList();
     return new PagedCollection<Product>(prds, pageindex, pagesize, fullList.Count);
 }