示例#1
0
        public static Result <Items> QueryPageList(ReqItems req)
        {
            Result <Items> results = new Result <Items>();

            if (req.IsFull)
            {
                var tempItems = TaoBaoKeHelper.QueryCoupon(req.KeyWord);
                if (tempItems.Count > req.PageInfo.PageSize)
                {
                    results.Results = tempItems.OrderByDescending(t => t.CommissionRate).ThenByDescending(t => t.Volume).Skip(req.PageInfo.PageSize * (req.PageInfo.PageIndex - 1)).Take(req.PageInfo.PageSize).ToList();
                }
                else
                {
                    results.Results = tempItems;
                }
                results.TotalCount = tempItems.Count;
                Task.Factory.StartNew(() =>
                {
                    UpdateCache(tempItems);
                });
                return(results);
            }
            if (mDict.HasValue())
            {
                List <Items> temp = mDict.Where(m =>
                {
                    bool tempResult = m.Status == 1;
                    if (tempResult && req.KeyWord.IsNotNullOrEmpty())
                    {
                        tempResult = m.Title.TryContains(req.KeyWord);

                        if (tempResult == false)
                        {
                            tempResult = m.Tags.TryContains(req.KeyWord);
                        }

                        if (tempResult == false)
                        {
                            tempResult = m.ProductUrl.TryContains(req.KeyWord);
                        }

                        if (tempResult == false)
                        {
                            tempResult = m.ProductWapUrl.TryContains(req.KeyWord);
                        }
                    }

                    if (tempResult && req.TypeId > 0)
                    {
                        tempResult = m.TypeId == req.TypeId;
                    }

                    if (tempResult && req.ZCId > 0)
                    {
                        tempResult = m.ZCId == req.ZCId;
                    }

                    if (tempResult && req.Tag.IsNotNullOrEmpty() && m.Tags != null)
                    {
                        tempResult = m.Tags.TryContains(req.Tag) || m.Title.TryContains(req.Tag);
                    }

                    return(tempResult);
                }).ToList();

                temp = temp.OrderByDescending(t => t.YouhuiPrice).ToList();

                if (req.PageInfo.SortFields.IsNotNullOrEmpty() && req.PageInfo.SortFields == "volume")
                {
                    if (req.PageInfo.Sort.EqualsCurrentCultureIgnoreCase("desc"))
                    {
                        temp = temp.OrderByDescending(t => t.Volume).ToList();
                    }
                    else
                    {
                        temp = temp.OrderBy(t => t.Volume).ToList();
                    }
                }
                results.Results    = temp.Skip(req.PageInfo.PageSize * (req.PageInfo.PageIndex - 1)).Take(req.PageInfo.PageSize).ToList();
                results.TotalCount = temp.Count;
                if (results.TotalCount == 0)
                {
                    var tempItems = TaoBaoKeHelper.QueryCoupon(req.KeyWord);
                    if (tempItems.Count > req.PageInfo.PageSize)
                    {
                        results.Results = tempItems.OrderByDescending(t => t.CommissionRate).ThenByDescending(t => t.Volume).Take(req.PageInfo.PageSize).ToList();
                    }
                    results.TotalCount = tempItems.Count;
                    Task.Factory.StartNew(() =>
                    {
                        UpdateCache(tempItems);
                    });
                }
                return(results);
            }

            var dbContext = new DbContext();
            Expression <Func <Items, bool> > fun = null;

            if (req.KeyWord.IsNotNullOrEmpty())
            {
                fun = (r) => SqlFunc.Contains(r.Title, req.KeyWord);
            }

            var result = dbContext.ItemsDb.GetPages(req.ConvertData(), fun, req.PageInfo);

            return(result);
        }
示例#2
0
 public ResponseResult Get([FromQuery] ReqItems req)
 {
     req.PageInfo = HttpContext.Request.GetPageInfo();
     return(new ResponseResult(0, "", BLL.ItemsBLL.QueryPageList(req)));
 }