public IPagedList <Prod.Item> ProdItemSearch(ProdItemSearchParam param)
        {
            var sb = SqlBuilder
                     .Select("*")
                     .From("item");

            if (param.UserId.HasValue)
            {
                sb.Where("userid=@userid", new { param.UserId });
            }
            if (param.Id > 0)
            {
                sb.Where("Id=@id", new { param.Id });
            }
            if (!string.IsNullOrEmpty(param.Name))
            {
                sb.Where("Name LIKE @Name", new { name = param.Name + "%" });
            }
            if (!string.IsNullOrEmpty(param.Code))
            {
                sb.Where("Code=@code", new { param.Code });
            }
            if (param.CRId > 0)
            {
                sb.Where("CatgRId=@CatgRId", new { CatgRId = param.CRId });
            }
            if (param.PriceFrom > 0)
            {
                sb.Where("Price>=@PriceFrom", new { param.PriceFrom });
            }
            if (param.PriceEnd > 0)
            {
                sb.Where("Price<=@PriceEnd", new { param.PriceEnd });
            }
            if (param.SaleFrom > 0)
            {
                sb.Where("SaleCount>=@SaleFrom", new { param.SaleFrom });
            }
            if (param.SaleEnd > 0)
            {
                sb.Where("SaleCount>=@SaleEnd", new { param.SaleEnd });
            }
            if (param.OrderBy != null && param.OrderBy.Count > 0)
            {
                var tmp = new StringBuilder();
                foreach (var o in param.OrderBy)
                {
                    tmp.AppendFormat("[{0}] {1},", o.Key, o.Value ? "ASC" : "DESC");
                }
                sb.OrderBy(sb.ToString().TrimEnd(','));
            }
            else
            {
                sb.OrderBy("Id DESC");
            }
            var cmd = sb.ToCommand(param.PageIndex, param.PageSize);

            return(StoreConn.PagedList <Prod.Item>(param.PageIndex, param.PageSize, cmd));
        }
 public IActionResult Index(ProdItemSearchParam param)
 {
     var model = new ItemModel.Index();
     if (param.Keyword.IsMatch(@"^\d+$"))
     {
         param.Id = param.Keyword.AsInt();
     }
     else
     {
         param.Name = param.Keyword;
     }
     model.Param = param;
     model.Items = DefaultStorage.ProdItemSearch(param);
     return View(model);
 }
Пример #3
0
        public IActionResult Index(ProdItemSearchParam param)
        {
            var model = new ItemModel.Index();

            if (param.Keyword.IsMatch(@"^\d+$"))
            {
                param.Id = param.Keyword.AsInt();
            }
            else
            {
                param.Name = param.Keyword;
            }
            model.Param = param;
            model.Items = DefaultStorage.ProdItemSearch(param);
            return(View(model));
        }