Ejemplo n.º 1
0
        protected override async Task <IQueryable <MaterialBuy> > BuildSearchQueryAsync(IDictionary <string, string> searchKeys, IQueryable <MaterialBuy> query)
        {
            if (searchKeys.ContainsKey("MaterialTypeId"))
            {
                if (int.TryParse(searchKeys["MaterialTypeId"], out var materialTypeId))
                {
                    if (materialTypeId == -1)
                    {
                        query = query.Where(o => o.Material.MaterialTypeId == null);
                    }
                    else
                    {
                        var materialType = await BaseTreeManager.GetByIdFromCacheAsync(materialTypeId);

                        //所有子类的id集合
                        var childIds = (await BaseTreeManager.FindChildrenAsync(materialTypeId, materialType.Discriminator, true)).Select(o => o.Id);
                        query = query.Where(o => o.Material.MaterialTypeId == materialTypeId || o.Material.MaterialTypeId != null && childIds.Contains(o.Material.MaterialTypeId.Value));
                    }
                }
            }
            if (searchKeys.ContainsKey("startDate"))
            {
                query = query.Where(o => o.CreationTime > DateTime.Parse(searchKeys["startDate"]));
            }
            if (searchKeys.ContainsKey("endDate"))
            {
                query = query.Where(o => o.CreationTime < DateTime.Parse(searchKeys["endDate"]));
            }
            return(query);
        }
Ejemplo n.º 2
0
        protected override async Task <IQueryable <Material> > BuildSearchQueryAsync(IDictionary <string, string> searchKeys, IQueryable <Material> query)
        {
            if (searchKeys.ContainsKey("From"))
            {
                //如果是用于销售的只显示上架商品
                if (searchKeys["From"] == "sell")
                {
                    query = query.Where(o => o.IsActive);
                }
            }
            if (searchKeys.ContainsKey("MaterialTypeId"))
            {
                if (int.TryParse(searchKeys["MaterialTypeId"], out var materialTypeId))
                {
                    if (materialTypeId == -1)
                    {
                        query = query.Where(o => o.MaterialTypeId == null);
                    }
                    else
                    {
                        var materialType = await BaseTreeManager.GetByIdFromCacheAsync(materialTypeId);

                        //所有子类的id集合
                        var childIds = (await BaseTreeManager.FindChildrenAsync(materialTypeId, materialType.Discriminator, true)).Select(o => o.Id);
                        query = query.Where(o => o.MaterialTypeId == materialTypeId || o.MaterialTypeId != null && childIds.Contains(o.MaterialTypeId.Value));
                    }
                }
            }
            if (searchKeys.ContainsKey("SellUnitId") && !string.IsNullOrEmpty(searchKeys["SellUnitId"]))
            {
                //如果按照代理来查询,则需要按代理的销售方式进行查询
                var _unitId = int.Parse(searchKeys["SellUnitId"]);
                var user    = await GetCurrentUserAsync();

                query = query.Where(new MaterialSellUnitSpecification(_unitId, user.IsCenterUser));

                /*query=query.Where(o =>
                 * UnitMaterialRepository.GetAll().Count(d => d.UnitId == _unitId && d.MaterialId == o.Id &&( d.UnitSellMode==UnitSellMode.停止销售 || d.UnitSellMode == UnitSellMode.售完为止 && o.TotalNumber==0) ) == 0 //并未设置代理商销售方式的默认始终销售
                 *  );*/
            }
            return(query);
        }