//GET:products?page=1&pageSize=3 public ActionResult Detail([FromQuery] ProductListParam param) { var page = param.Page; var pageSize = param.PageSize; try { var productsList = _productB.GetPageContentList(page, pageSize); return Ok(productsList); } catch (Exception) { throw new Exception("异常发生"); } }
public SingleResult <ProductListDto> GetProductList_Paging_Filtering_UI(ProductListParam filter) { try { List <Product> res = new List <Product>(); int totalcount = 0; long? MinPrice = 0; long? MaxPrice = 0; switch (filter.SortMethod) { case 2: res = _repository.Product.GetProductListFullInfo() .Where(c => (filter.ProductName == null || c.Name.Contains(filter.ProductName)) && (c.CatProductId == filter.CatProductId || filter.CatProductId == null) && (filter.MinPrice <= c.Price || filter.MinPrice == null) && (c.Price <= filter.MaxPrice || filter.MaxPrice == null) && (filter.SellerIdList.Contains(c.SellerId.Value) || filter.SellerIdList.Count == 0)) .OrderByDescending(c => c.ProductCustomerRate.Average(x => x.Rate)).ToList(); MinPrice = res.Min(c => c.Price); MaxPrice = res.Max(c => c.Price); totalcount = res.Count; res = res.Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToList(); break; case 3: res = _repository.Product.GetProductListFullInfo() .Where(c => (filter.ProductName == null || c.Name.Contains(filter.ProductName)) && (c.CatProductId == filter.CatProductId || filter.CatProductId == null) && (filter.MinPrice <= c.Price || filter.MinPrice == null) && (c.Price <= filter.MaxPrice || filter.MaxPrice == null) && (filter.SellerIdList.Contains(c.SellerId.Value) || filter.SellerIdList.Count == 0)) .OrderByDescending(c => c.CustomerOrderProduct.Count()).ToList(); MinPrice = res.Min(c => c.Price); MaxPrice = res.Max(c => c.Price); totalcount = res.Count; res = res.Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToList(); break; case 4: res = _repository.Product.GetProductListFullInfo() .Where(c => (filter.ProductName == null || c.Name.Contains(filter.ProductName)) && (c.CatProductId == filter.CatProductId || filter.CatProductId == null) && (filter.MinPrice <= c.Price || filter.MinPrice == null) && (c.Price <= filter.MaxPrice || filter.MaxPrice == null) && (filter.SellerIdList.Contains(c.SellerId.Value) || filter.SellerIdList.Count == 0)) .OrderBy(c => c.Price).ToList(); MinPrice = res.Min(c => c.Price); MaxPrice = res.Max(c => c.Price); totalcount = res.Count; res = res.Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToList(); break; case 5: res = _repository.Product.GetProductListFullInfo() .Where(c => (filter.ProductName == null || c.Name.Contains(filter.ProductName)) && (c.CatProductId == filter.CatProductId || filter.CatProductId == null) && (filter.MinPrice <= c.Price || filter.MinPrice == null) && (c.Price <= filter.MaxPrice || filter.MaxPrice == null) && (filter.SellerIdList.Contains(c.SellerId.Value) || filter.SellerIdList.Count == 0)) .OrderByDescending(c => c.Price).ToList(); MinPrice = res.Min(c => c.Price); MaxPrice = res.Max(c => c.Price); totalcount = res.Count; res = res.Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToList(); break; case 6: res = _repository.Product.GetProductListFullInfo() .Where(c => c.MelliFlag == true && (filter.ProductName == null || c.Name.Contains(filter.ProductName)) && (c.CatProductId == filter.CatProductId || filter.CatProductId == null) && (filter.MinPrice <= c.Price || filter.MinPrice == null) && (c.Price <= filter.MaxPrice || filter.MaxPrice == null) && (filter.SellerIdList.Contains(c.SellerId.Value) || filter.SellerIdList.Count == 0)) .OrderByDescending(c => c.Cdate).ToList(); MinPrice = res.Min(c => c.Price); MaxPrice = res.Max(c => c.Price); totalcount = res.Count; res = res.Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToList(); break; case 7: res = _repository.Product.GetProductListFullInfo() .Where(c => c.UnescoFlag == true && (filter.ProductName == null || c.Name.Contains(filter.ProductName)) && (c.CatProductId == filter.CatProductId || filter.CatProductId == null) && (filter.MinPrice <= c.Price || filter.MinPrice == null) && (c.Price <= filter.MaxPrice || filter.MaxPrice == null) && (filter.SellerIdList.Contains(c.SellerId.Value) || filter.SellerIdList.Count == 0)) .OrderByDescending(c => c.Cdate).ToList(); MinPrice = res.Min(c => c.Price); MaxPrice = res.Max(c => c.Price); totalcount = res.Count; res = res.Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToList(); break; default: res = _repository.Product.GetProductListFullInfo() .Where(c => (filter.ProductName == null || c.Name.Contains(filter.ProductName)) && (c.CatProductId == filter.CatProductId || filter.CatProductId == null) && (filter.MinPrice <= c.Price || filter.MinPrice == null) && (c.Price <= filter.MaxPrice || filter.MaxPrice == null) && (filter.SellerIdList.Contains(c.SellerId.Value) || filter.SellerIdList.Count == 0)) .OrderByDescending(c => c.Cdate).ToList(); MinPrice = res.Min(c => c.Price); MaxPrice = res.Max(c => c.Price); totalcount = res.Count; res = res.Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToList(); break; } ProductListDto result = new ProductListDto { MaxPrice = MaxPrice, MinPrice = MinPrice, TotalCount = totalcount, ProductList = _mapper.Map <List <ProductDto> >(res) }; var finalresult = SingleResult <ProductListDto> .GetSuccessfulResult(result); return(finalresult); } catch (Exception e) { return(SingleResult <ProductListDto> .GetFailResult(null)); } }