コード例 #1
0
        /// <summary>
        /// 根据套餐状态标签分页获取定制套餐列表
        /// </summary>
        /// <param name="keywords">关键字</param>
        /// <param name="status">套餐状态</param>
        /// <param name="labels">套餐标签</param>
        /// <param name="sort">排序条件 false为倒序</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页容量</param>
        /// <param name="rowCount">总记录条数</param>
        /// <param name="pageCount">总页数</param>
        /// <returns>定制套餐列表</returns>
        public IEnumerable <BalePack> FindCustPackByPage(string keywords, ShelfStatus?status, IList <string> labels, Dictionary <string, bool> sort, int pageIndex, int pageSize, out int rowCount, out int pageCount)
        {
            #region 标签处理

            IQueryable <BalePack> balePacks = base.FindAllInner();
            if (labels != null && labels.Any())
            {
                PredicateBuilder <BalePack> builder = new PredicateBuilder <BalePack>(s => false);
                foreach (string label in labels)
                {
                    string slabel = label;
                    builder.Or(s => s.LabelStr.Contains(slabel));
                }
                balePacks = balePacks.Where(builder.Build());
            }

            #endregion

            Expression <Func <BalePack, bool> > condition =
                s => (string.IsNullOrEmpty(keywords) || s.Keywords.Contains(keywords)) &&
                (status == null || s.PackShelfStatus == status) &&
                s.BalePackType == BalePackType.Customized &&
                s.SourcePackId == null;

            balePacks = balePacks.Where(condition);
            //排序
            if (sort != null && sort.Any())
            {
                balePacks = balePacks.OrderBy(sort);
            }
            rowCount  = balePacks.Count();
            pageCount = (int)Math.Ceiling(rowCount * 1.0 / pageSize);
            return(balePacks.Skip((pageIndex - 1) * pageSize).Take(pageSize));
            //return balePacks.ToPage(s => true, pageIndex, pageSize, out rowCount, out pageCount);
        }
コード例 #2
0
        public void ShouldCombineExpressionsCorrectly_And(bool left, bool right, bool expected)
        {
            PredicateBuilder <object>         builder    = new PredicateBuilder <object>(_ => left).And(_ => right);
            Expression <Func <object, bool> > expression = builder.Build();
            bool result = expression.Compile().Invoke(new object());

            result.Should().Be(expected);
        }
コード例 #3
0
        public void ShouldNotUseDefaultFallback_False_Or()
        {
            PredicateBuilder <object>         builder    = new PredicateBuilder <object>(true).Or(_ => false);
            Expression <Func <object, bool> > expression = builder.Build();
            bool result = expression.Compile().Invoke(new object());

            result.Should().BeFalse();
        }
コード例 #4
0
        public void ShouldBuildAndConvertToTheSameExpression()
        {
            var builder = new PredicateBuilder <object>(_ => true);
            Expression <Func <object, bool> > expression1 = builder;
            Expression <Func <object, bool> > expression2 = builder.Build();

            expression1.Should().Be(expression2);
        }
コード例 #5
0
        public virtual IQueryable <T> ApplyFilters(IQueryable <T> query)
        {
            if (PredicateBuilder != null)
            {
                var @where = PredicateBuilder.Build();
                if (@where != null)
                {
                    query = query.Where(@where);
                }
            }

            return(query);
        }
コード例 #6
0
        public void TestBuildExpression()
        {
            //初始化
            DbSession dbSession = new DbSession();

            string[] keywords = { "张三", "李四", "王五" };

            //动态拼接
            PredicateBuilder <Student> builder = new PredicateBuilder <Student>(x => false);

            foreach (string keyword in keywords)
            {
                if (!string.IsNullOrEmpty(keyword))
                {
                    builder.Or(x => x.Name.Contains(keyword));
                }
            }

            IQueryable <Student> specStudents = dbSession.Set <Student>().Where(builder.Build());

            Assert.IsNotNull(specStudents.Any());
        }
コード例 #7
0
        private void GetFilterList()
        {
            try
            {
                IEnumerable           retrievedData     = (IEnumerable)HttpContext.Current.Session[SessionVarName];
                CustomList <BaseItem> retrievedDataList = retrievedData.ToCustomList <BaseItem>();
                String expression = String.Empty;
                foreach (String colName in HttpContext.Current.Request.QueryString)
                {
                    if (colName != "SessionVarName" && colName != "rows" &&
                        colName != "page" && colName != "sidx" &&
                        colName != "sord" && colName != "_search" &&
                        colName != "nd" && colName != "nd_" && colName != "id" &&
                        colName != "AggregateColumn" && colName != "FooterRowCaption")
                    {
                        String colValue = HttpContext.Current.Request.QueryString[colName];
                        if (!String.IsNullOrEmpty(expression))
                        {
                            expression += " And ";
                        }
                        //
                        expression += MakePredicateString(colName, colValue);
                    }
                }

                if (!String.IsNullOrEmpty(expression))
                {
                    retrievedDataList = retrievedDataList.FindAll(PredicateBuilder.Build <BaseItem>(expression));
                }
                //
                PerformRequestData(retrievedDataList);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #8
0
        /// <summary>
        /// 分页获取套餐模板列表(排除克隆版本套餐)
        /// </summary>
        /// <param name="keywords">关键字</param>
        /// <param name="propertyId">楼盘Id</param>
        /// <param name="applicableSquare">适用面积</param>
        /// <param name="isNewHouse">是否适用新房</param>
        /// <param name="isBuildingPrice">是否是建筑价格搜索</param>
        /// <param name="minPrice">最小价格</param>
        /// <param name="maxPrice">最大价格</param>
        /// <param name="isBuildingSquare">是否是建筑面积搜索</param>
        /// <param name="minSquare">最小面积</param>
        /// <param name="maxSquare">最大面积</param>
        /// <param name="hasOffSku">是否有下架商品</param>
        /// <param name="hasChangedSku">是否有变价商品|工艺</param>
        /// <param name="color">颜色</param>
        /// <param name="packType">套餐类型</param>
        /// <param name="packKind">套餐类别</param>
        /// <param name="packMode">套餐模式</param>
        /// <param name="status">状态</param>
        /// <param name="spaceTypes">空间类型集</param>
        /// <param name="styleNos">设计风格集</param>
        /// <param name="layouts">居室集</param>
        /// <param name="propertys">楼盘集</param>
        /// <param name="hasPackSeries"></param>
        /// <param name="packSeriesIds">套餐系列集</param>
        /// <param name="stores">门店集</param>
        /// <param name="hasStores">是否有门店(全部,标签:true,其他:false)</param>
        /// <param name="createrId">套餐创建人Id?(全部:null,我的:当前登录人员)</param>
        /// <param name="sort">排序条件 false为倒序</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页容量</param>
        /// <param name="rowCount">总记录条数</param>
        /// <param name="pageCount">总页数</param>
        /// <returns>套餐模板列表</returns>
        public IEnumerable <DecorationPack> FindByPage(string keywords, Guid?propertyId, float?applicableSquare, bool?isNewHouse, bool?isBuildingPrice, decimal?minPrice, decimal?maxPrice, bool?isBuildingSquare,
                                                       float?minSquare, float?maxSquare, bool?hasOffSku, bool?hasChangedSku, DecorationPackColor?color, DecorationPackType?packType,
                                                       DecorationPackKind?packKind, DecorationPackMode?packMode, ShelfStatus?status, IList <string> spaceTypes, IList <string> styleNos, IList <string> layouts,
                                                       IList <Guid> propertys, bool hasPackSeries, IList <Guid> packSeriesIds, IList <Guid> stores, bool hasStores, Guid?createrId, Dictionary <string, bool> sort, int pageIndex, int pageSize, out int rowCount, out int pageCount)
        {
            IQueryable <DecorationPack> packs = this.FindAllInner();

            packs = packs.Where(x => (status == null || x.Status == status) && x.SourcePackId == null);
            //需求文档要求,如果楼盘条件查询不到,则过滤此条件
            var hasProperties = packs.Any(s => propertyId == null || !string.IsNullOrEmpty(s.PropertysStr) && s.PropertysStr.Contains(propertyId.ToString()));

            #region # 标签处理


            //空间类型标签
            if (spaceTypes != null && spaceTypes.Any())
            {
                PredicateBuilder <DecorationPack> builder = new PredicateBuilder <DecorationPack>(x => false);
                foreach (string spaceType in spaceTypes)
                {
                    string sType = spaceType;

                    builder.Or(x => x.SpaceTypesStr.Contains(sType));
                }

                packs = packs.Where(builder.Build());
            }

            //设计风格标签
            if (styleNos != null && styleNos.Any())
            {
                PredicateBuilder <DecorationPack> builder = new PredicateBuilder <DecorationPack>(x => false);
                foreach (string styleNo in styleNos)
                {
                    string sStyleNo = styleNo;

                    builder.Or(x => x.StyleNosStr.Contains(sStyleNo));
                }

                packs = packs.Where(builder.Build());
            }

            //居室标签
            if (layouts != null && layouts.Any())
            {
                PredicateBuilder <DecorationPack> builder = new PredicateBuilder <DecorationPack>(x => false);
                foreach (string layout in layouts)
                {
                    string sLayout = layout;

                    builder.Or(x => x.LayoutsStr.Contains(sLayout));
                }

                packs = packs.Where(builder.Build());
            }

            //楼盘标签
            if (propertys != null && propertys.Any())
            {
                PredicateBuilder <DecorationPack> builder = new PredicateBuilder <DecorationPack>(x => false);
                foreach (Guid property in propertys)
                {
                    string sProperty = property.ToString();

                    builder.Or(x => x.PropertysStr.Contains(sProperty));
                }

                packs = packs.Where(builder.Build());
            }

            if (hasStores)
            {
                //门店标签
                if (stores != null && stores.Any())
                {
                    PredicateBuilder <DecorationPack> builder = new PredicateBuilder <DecorationPack>(x => false);
                    foreach (Guid store in stores)
                    {
                        string sStore = store.ToString();

                        builder.Or(x => x.StoresStr.Contains(sStore));
                    }

                    packs = packs.Where(builder.Build());
                }
            }
            else
            {
                packs = packs.Where(x => string.IsNullOrEmpty(x.StoresStr));
            }

            if (hasPackSeries)
            {
                if (packSeriesIds != null && packSeriesIds.Any())
                {
                    packs = packs.Where(s => s.PackSeries.Select(t => t.Id).Intersect(packSeriesIds).Any());
                }
            }
            else
            {
                packs = packs.Where(s => !s.PackSeries.Any());
            }
            #endregion


            #region  建筑面积  || 使用面积  价格搜索
            //2018-07-23  学梅确认, 价格搜索按照定价方式里面的建筑面积|使用面积勾选进行查询;建筑面积-(是否整体建筑定价|是否平米整体建筑定价为true)
            if (minPrice != null || maxPrice != null)
            {
                if (isBuildingPrice.Value)
                {
                    if (minPrice != null && maxPrice == null)
                    {
                        packs = packs.Where(x => (x.BuildingTotalPrice >= minPrice && x.IsBuilding) || (x.UnitBuildingTotalPrice >= minPrice && x.IsUnitBuilding));
                    }
                    else if (minPrice == null && maxPrice != null)
                    {
                        packs = packs.Where(x => (x.BuildingTotalPrice <= maxPrice && x.IsBuilding) || (x.UnitBuildingTotalPrice <= maxPrice && x.IsUnitBuilding));
                    }
                    else if (minPrice != null && maxPrice != null)
                    {
                        packs = packs.Where(x =>
                                            (x.BuildingTotalPrice >= minPrice && x.BuildingTotalPrice <= maxPrice && x.IsBuilding) ||
                                            (x.UnitBuildingTotalPrice >= minPrice && x.UnitBuildingTotalPrice <= maxPrice && x.IsUnitBuilding));
                    }
                }
                else
                {
                    if (minPrice != null && maxPrice == null)
                    {
                        packs = packs.Where(x => (x.TotalPrice >= minPrice && x.IsActual) || (x.UnitTotalPrice >= minPrice && x.IsUnitActual));
                    }
                    else if (minPrice == null && maxPrice != null)
                    {
                        packs = packs.Where(x => (x.TotalPrice <= maxPrice && x.IsActual) || (x.UnitTotalPrice <= maxPrice && x.IsUnitActual));
                    }
                    else if (minPrice != null && maxPrice != null)
                    {
                        packs = packs.Where(x => (x.TotalPrice >= minPrice && x.TotalPrice <= maxPrice && x.IsActual) ||
                                            (x.UnitTotalPrice >= minPrice && x.UnitTotalPrice <= maxPrice && x.IsUnitActual));
                    }
                }
            }

            #endregion

            #region 建筑面积 || 使用面积 面积搜索

            if (minSquare != null && maxSquare != null)
            {
                if (isBuildingSquare.Value)
                {
                    //2018-07-05  学梅确认, 平米定价-最低购买面积判断  ,   整体定价-使用面积
                    packs = packs.Where(x =>
                                        !x.PricingType.HasValue ||
                                        (x.PricingType == DecorationPackPricingType.Total && (minSquare == null || x.BuildingSquare >= minSquare) && (maxSquare == null || x.BuildingSquare <= maxSquare) ||
                                         x.PricingType == DecorationPackPricingType.Unit && (minSquare == null || x.UnitBuildingSquare >= minSquare) && (maxSquare == null || x.UnitBuildingSquare <= maxSquare)));
                }
                else
                {
                    //2018-07-05  学梅确认, 平米定价-最低购买面积判断  ,   整体定价-使用面积
                    packs = packs.Where(x =>
                                        !x.PricingType.HasValue ||
                                        (x.PricingType == DecorationPackPricingType.Total && (minSquare == null || x.Square >= minSquare) && (maxSquare == null || x.Square <= maxSquare) ||
                                         x.PricingType == DecorationPackPricingType.Unit && (minSquare == null || x.UnitSquare >= minSquare) && (maxSquare == null || x.UnitSquare <= maxSquare)));
                }
            }

            #endregion



            Expression <Func <DecorationPack, bool> > condition =
                x =>
                (string.IsNullOrEmpty(keywords) || x.Keywords.Contains(keywords)) &&
                (createrId == null || x.CreaterId == createrId) &&
                (!hasProperties || propertyId == null || !string.IsNullOrEmpty(x.PropertysStr) && x.PropertysStr.Contains(propertyId.ToString())) &&
                (applicableSquare == null || x.MinApplicableSquare <= applicableSquare && x.MaxApplicableSquare >= applicableSquare) &&
                (isNewHouse == null || (isNewHouse.Value ? x.NewHouse : x.SecondHandHouse)) &&
                (hasOffSku == null || x.HasOffShelvedSku == hasOffSku) &&
                (hasChangedSku == null || x.HasChangedSku == hasChangedSku) &&
                (color == null || x.Color == color) &&
                (packType == null || x.PackType == packType) &&
                (packKind == null || x.PackKind == packKind) &&
                (packMode == null || x.PackMode == packMode);

            packs = packs.Where(condition);
            //排序
            if (sort != null && sort.Any() && packs.Any())
            {
                packs = packs.OrderBy(sort);
            }

            rowCount  = packs.Count();
            pageCount = (int)Math.Ceiling(rowCount * 1.0 / pageSize);
            return(packs.Skip((pageIndex - 1) * pageSize).Take(pageSize));
            //return packs.ToPage(x => true, pageIndex, pageSize, out rowCount, out pageCount);
        }
コード例 #9
0
        /// <summary>
        /// 分页获取套餐模板列表(排除克隆版本套餐)
        /// </summary>
        /// <param name="keywords">关键字</param>
        /// <param name="containsNoProperty">是否包含无楼盘标签套餐(true查询)</param>
        /// <param name="propertys">楼盘集(查询包含此集合标签)</param>
        /// <param name="propertyId">楼盘Id(查询包含此楼盘标签)</param>
        /// <param name="houseTypeId">户型Id(查询包含此户型标签)</param>
        /// <param name="hasPackSeries">是否有标签(全部,标签:true,其他:false)</param>
        /// <param name="packSeriesIds">套餐系列集</param>
        /// <param name="styleNos">设计风格集</param>
        /// <param name="isBuildSuqare">是否是建筑面积搜索</param>
        /// <param name="minSquare">最小面积</param>
        /// <param name="maxSquare">最大面积</param>
        /// <param name="sort">排序条件 false为倒序</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页容量</param>
        /// <param name="rowCount">总记录条数</param>
        /// <param name="pageCount">总页数</param>
        /// <returns>套餐模板列表</returns>
        public IEnumerable <DecorationPack> FindByCondition(string keywords, bool containsNoProperty, IList <Guid> propertys, Guid?propertyId, Guid?houseTypeId, bool hasPackSeries, IEnumerable <Guid> packSeriesIds, IEnumerable <string> styleNos, bool?isBuildSuqare, float?minSquare, float?maxSquare, Dictionary <string, bool> sort, int pageIndex, int pageSize, out int rowCount, out int pageCount)
        {
            IQueryable <DecorationPack> packs = this.FindAllInner();

            packs = packs.Where(x => x.Status == ShelfStatus.Shelfed && x.SourcePackId == null);

            //筑家帮需求: 1、containsNoProperty false 楼盘集 只查询包含楼盘标签的套餐;2、containsNoProperty true 楼盘集 查询包含楼盘标签和无楼盘标签的套餐;
            //3、propertyId有值 只查询包含该楼盘标签的套餐;


            #region 标签处理
            //系列
            if (hasPackSeries)
            {
                if (packSeriesIds != null && packSeriesIds.Any())
                {
                    packs = packs.Where(s => s.PackSeries.Select(t => t.Id).Intersect(packSeriesIds).Any());
                }
            }
            else
            {
                packs = packs.Where(s => !s.PackSeries.Any());
            }
            //设计风格标签
            if (styleNos != null && styleNos.Any())
            {
                PredicateBuilder <DecorationPack> builder = new PredicateBuilder <DecorationPack>(x => false);
                foreach (string styleNo in styleNos)
                {
                    string sStyleNo = styleNo;

                    builder.Or(x => x.StyleNosStr.Contains(sStyleNo));
                }

                packs = packs.Where(builder.Build());
            }
            //楼盘标签
            if (propertys != null && propertys.Any())
            {
                PredicateBuilder <DecorationPack> builder = new PredicateBuilder <DecorationPack>(x => false);
                if (containsNoProperty)
                {
                    foreach (Guid property in propertys)
                    {
                        string sProperty = property.ToString();

                        builder.Or(x => string.IsNullOrEmpty(x.PropertysStr) || x.PropertysStr.Contains(sProperty));
                    }
                }
                else
                {
                    foreach (Guid property in propertys)
                    {
                        string sProperty = property.ToString();

                        builder.Or(x => x.PropertysStr.Contains(sProperty));
                    }
                }
                packs = packs.Where(builder.Build());
            }

            #endregion



            #region 建筑面积 || 使用面积 面积搜索

            if (minSquare != null && maxSquare != null)
            {
                if (isBuildSuqare.Value)
                {
                    //2018-07-05  学梅确认, 平米定价-最低购买面积判断  ,   整体定价-使用面积
                    packs = packs.Where(x =>
                                        !x.PricingType.HasValue ||
                                        (x.PricingType == DecorationPackPricingType.Total && (minSquare == null || x.BuildingSquare >= minSquare) && (maxSquare == null || x.BuildingSquare <= maxSquare) ||
                                         x.PricingType == DecorationPackPricingType.Unit && (minSquare == null || x.UnitBuildingSquare >= minSquare) && (maxSquare == null || x.UnitBuildingSquare <= maxSquare)));
                }
                else
                {
                    //2018-07-05  学梅确认, 平米定价-最低购买面积判断  ,   整体定价-使用面积
                    packs = packs.Where(x =>
                                        !x.PricingType.HasValue ||
                                        (x.PricingType == DecorationPackPricingType.Total && (minSquare == null || x.Square >= minSquare) && (maxSquare == null || x.Square <= maxSquare) ||
                                         x.PricingType == DecorationPackPricingType.Unit && (minSquare == null || x.UnitSquare >= minSquare) && (maxSquare == null || x.UnitSquare <= maxSquare)));
                }
            }

            #endregion


            Expression <Func <DecorationPack, bool> > condition =
                x => (string.IsNullOrEmpty(keywords) || x.Keywords.Contains(keywords)) &&
                (houseTypeId == null || !string.IsNullOrEmpty(x.HouseTypesStr) && x.HouseTypesStr.Contains(houseTypeId.ToString())) &&
                (propertyId == null || !string.IsNullOrEmpty(x.PropertysStr) && x.PropertysStr.Contains(propertyId.ToString()))
                //&& (!containsNoProperty || string.IsNullOrEmpty(x.PropertysStr))
            ;

            packs = packs.Where(condition);

            //排序
            if (sort != null && sort.Any() && packs.Any())
            {
                packs = packs.OrderBy(sort);
            }

            rowCount  = packs.Count();
            pageCount = (int)Math.Ceiling(rowCount * 1.0 / pageSize);
            return(packs.Skip((pageIndex - 1) * pageSize).Take(pageSize));
        }