示例#1
0
        public void WhereStrTest()
        {
            var condition = new QueryCondition <Vendor>();

            //condition.AddFilter("Name", ConditionOperator.Equal, "null", LogicOperator.AndAlso);
            condition.AddFilter("Name", ConditionOperator.Equal, "ABC");
            condition.AddFilter("Number", ConditionOperator.StartsWith, "000");

            var vendors = GetTestList();
            var query   = vendors.AsQueryable().Where(condition.GetFilter(), condition.GetValues());

            var data = query.ToList();

            Assert.NotNull(data);
            Assert.True(data.Count == 1);
            Assert.True(data[0].Name == "ABC");
            Assert.True(data[0].Number == vendors[0].Number);
        }
        public async Task <PageData <InventoryOutputDto> > SearchProductAsync(QueryCondition <Inventory> condition, IServiceProvider serviceProvider)
        {
            var query = _inventoryRepo.Query();
            var total = 0;

            if (condition.Filters != null && condition.Filters.Count > 0)
            {
                query = query.Where(condition.GetFilter(), condition.GetValues());
            }

            if (condition.Sorts != null && condition.Sorts.Count > 0)
            {
                query = query.OrderBy(condition.Sorts.ConvertToSortString());
            }

            total = await query.CountAsync();

            query = query.Skip((condition.PageIndex - 1) * condition.PageSize).Take(condition.PageSize);

            var productRepo = serviceProvider.GetService <IRepository <Product, Guid> >();

            return((await(from inventory in query
                          join product in productRepo.Query() on inventory.Number equals product.Number
                          select new InventoryOutputDto
            {
                Id = inventory.Id,
                Number = inventory.Number,
                GoodsCategory = GoodsCategory.Material,
                Amount = inventory.Amount,
                WarehouseId = inventory.WarehouseId,
                DateTime = inventory.DateTime,
                Name = inventory.Name,
                Spec = product.Spec,
                Price = product.CostPrice,
                Brand = product.Brand,
                Unit = product.Unit,
                Type = product.Type
            }).ToListAsync()).ToPageData(total));
        }
示例#3
0
        public async Task <PageData <ProductOutputDto> > SearchAsync(QueryCondition <Product> condition = null)
        {
            var query = _productRepo.Query();
            var total = 0;

            if (condition != null)
            {
                if (condition.Filters != null && condition.Filters.Count > 0)
                {
                    query = query.FilterDateTime(ref condition).Where(condition.GetFilter(), condition.GetValues());
                }

                if (condition.Sorts != null && condition.Sorts.Count > 0)
                {
                    query = query.OrderBy(condition.Sorts.ConvertToSortString());
                }

                total = await query.CountAsync();

                query = query.Skip((condition.PageIndex - 1) * condition.PageSize).Take(condition.PageSize);
            }

            return((await query.ToListAsync()).Select(v => v.MapTo <ProductOutputDto>()).ToPageData(total));
        }
示例#4
0
        public async Task <PageData <CustomerOutputDto> > GetCustomers(QueryCondition <CustomerProduct> queryCondition, IServiceProvider serviceProvider)
        {
            var productProductQuery = serviceProvider.GetService <IRepository <CustomerProduct, Guid> >().Query();
            var customerRepo        = serviceProvider.GetService <IRepository <Customer, Guid> >();

            if (queryCondition.Filters != null && queryCondition.Filters.Count > 0)
            {
                productProductQuery = productProductQuery.Where(queryCondition.GetFilter(), queryCondition.GetValues());
            }

            if (queryCondition.Sorts != null && queryCondition.Sorts.Count > 0)
            {
                productProductQuery = productProductQuery.OrderBy(queryCondition.Sorts.ConvertToSortString());
            }

            var total = await productProductQuery.CountAsync();

            productProductQuery = productProductQuery.Skip((queryCondition.PageIndex - 1) * queryCondition.PageSize).Take(queryCondition.PageSize);

            return((await(from vm in productProductQuery
                          join v in customerRepo.Query() on vm.CustomerId equals v.Id
                          select v)
                    .ToListAsync())
                   .Select(v => v.MapTo <CustomerOutputDto>()).ToPageData(total));
        }
        public async Task <PageData <MaterialOutputDto> > GetMaterials(QueryCondition <VendorMaterial> queryCondition, IServiceProvider serviceProvider)
        {
            var materialMaterialQuery = serviceProvider.GetService <IRepository <VendorMaterial, Guid> >().Query();
            var materialRepo          = serviceProvider.GetService <IRepository <Material, Guid> >();

            if (queryCondition.Filters != null && queryCondition.Filters.Count > 0)
            {
                materialMaterialQuery = materialMaterialQuery.Where(queryCondition.GetFilter(), queryCondition.GetValues());
            }

            if (queryCondition.Sorts != null && queryCondition.Sorts.Count > 0)
            {
                materialMaterialQuery = materialMaterialQuery.OrderBy(queryCondition.Sorts.ConvertToSortString());
            }

            var total = await materialMaterialQuery.CountAsync();

            materialMaterialQuery = materialMaterialQuery.Skip((queryCondition.PageIndex - 1) * queryCondition.PageSize).Take(queryCondition.PageSize);

            return((await(from vm in materialMaterialQuery
                          join m in materialRepo.Query() on vm.MaterialId equals m.Id
                          select m)
                    .ToListAsync())
                   .Select(m => m.MapTo <MaterialOutputDto>()).ToPageData(total));
        }