public async Task <PagList <Product> > GetProducts(ProdParams prodParams)
        {
            var prods = _context.Products.OrderByDescending(p => p.Name).AsQueryable();

            if (prodParams.Phrase.Length != 0)
            {
                prods = _context.Products.Where(p => p.Name.ToLower()
                                                .Contains(prodParams.Phrase.ToLower())).AsQueryable();
            }

            switch (prodParams.OrderBy)
            {
            case "NameAsc":
                prods = prods.OrderBy(p => p.Name).AsQueryable();
                break;

            case "NameDesc":
                prods = prods.OrderByDescending(p => p.Name).AsQueryable();
                break;

            case "PriceAsc":
                prods = prods.OrderBy(p => p.Price).AsQueryable();
                break;

            case "PriceDesc":
                prods = prods.OrderByDescending(p => p.Price).AsQueryable();
                break;

            default:
                prods = prods.OrderBy(p => p.Name).AsQueryable();
                break;
            }

            return(await PagList <Product> .CreateAsync(prods, prodParams.PageNo, prodParams.PageSize));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetProducts([FromQuery] ProdParams prodParams)
        {
            var products = await _repo.GetProducts(prodParams);

            Response.AddPag(products.CurrPage, products.PageSize
                            , products.TotCount, products.TotPages);
            return(Ok(products));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// suning.govbus.proddetail.get 获取商品详情接口
        /// </summary>
        /// <param name="skuId"></param>
        /// <returns></returns>
        public static SNComDetailDto GetSNDetail(string skuId)
        {
            SNComDetailDto SnDetail = new SNComDetailDto();

            try
            {
                LogHelper.Info("SuningSV.GetSNDetail 获取proddetail");
                var request = new snsdk.suning_api_sdk.BizRequest.CustomGovbusRequest.ProdDetailGetRequest();
                request.skuId = skuId;
                var result = SuningClient.Execute(request);
                if (!string.IsNullOrEmpty(result.name))
                {
                    SnDetail.brand        = result.brand;
                    SnDetail.category     = result.category;
                    SnDetail.image        = result.image;
                    SnDetail.introduction = result.introduction;
                    SnDetail.packlisting  = result.packlisting;
                    SnDetail.model        = result.model;
                    SnDetail.name         = result.name;
                    SnDetail.productArea  = result.productArea;
                    SnDetail.saleUnit     = result.saleUnit;
                    SnDetail.skuId        = result.skuId;
                    SnDetail.state        = result.state;
                    SnDetail.upc          = result.upc;
                    SnDetail.weight       = result.weight;
                    List <ProdParams> pros = new List <ProdParams>();
                    List <Param>      pa   = new List <Param>();
                    if (result.prodParams != null)
                    {
                        foreach (var item in result.prodParams)
                        {
                            ProdParams pro = new ProdParams();
                            pro.desc = item.desc;
                            if (item.param != null)
                            {
                                foreach (var model in item.param)
                                {
                                    Param p = new Param();
                                    p.coreFlag            = model.coreFlag;
                                    p.snparameterCode     = model.snparameterCode;
                                    p.snparameterdesc     = model.snparameterdesc;
                                    p.snparametersCode    = model.snparametersCode;
                                    p.snparametersDesc    = model.snparametersDesc;
                                    p.snparameterSequence = model.snparameterSequence;
                                    p.snparameterVal      = model.snparameterVal;
                                    p.snsequence          = model.snsequence;
                                    pro.param.Add(p);
                                }
                            }
                            pros.Add(pro);
                        }
                        SnDetail.prodParams = pros;
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("SuningSV.GetProdPool 获取prodpool 异常", ex);
            }
            return(SnDetail);
        }