public static Expression <Func <Factor, bool> > ToFactorExpression( this FactorPaginationDto factorPaginationDto, SearchIdEnums searchIdType, string id = "", string userId = "", bool isAdmin = true) { switch (searchIdType) { case SearchIdEnums.None: Expression <Func <Factor, bool> > exp = p => true; if (!string.IsNullOrEmpty(factorPaginationDto.Filter) && !string.IsNullOrWhiteSpace(factorPaginationDto.Filter)) { Expression <Func <Factor, bool> > tempExp = (p => p.Id.Contains(factorPaginationDto.Filter) || p.UserName.Contains(factorPaginationDto.Filter) || p.GiftCode.Contains(factorPaginationDto.Filter) || p.Price.ToString().Contains(factorPaginationDto.Filter) || p.EndPrice.ToString().Contains(factorPaginationDto.Filter) || p.RefBank.Contains(factorPaginationDto.Filter) || p.EnterMoneyWalletId.Contains(factorPaginationDto.Filter) || p.UserId.Contains(factorPaginationDto.Filter) || p.GateId.Contains(factorPaginationDto.Filter)); exp = CombineExpressions.CombiningExpressions <Factor>(exp, tempExp, ExpressionsTypeEnum.And); } // if (factorPaginationDto.Status == 1) { Expression <Func <Factor, bool> > tempExp = p => p.Status; exp = CombineExpressions.CombiningExpressions <Factor>(exp, tempExp, ExpressionsTypeEnum.And); } if (factorPaginationDto.Status == 2) { Expression <Func <Factor, bool> > tempExp = p => !p.Status; exp = CombineExpressions.CombiningExpressions <Factor>(exp, tempExp, ExpressionsTypeEnum.And); } // if (factorPaginationDto.FactorType > 0 && factorPaginationDto.FactorType < 5) { Expression <Func <Factor, bool> > tempExp = p => p.Kind == factorPaginationDto.FactorType; exp = CombineExpressions.CombiningExpressions <Factor>(exp, tempExp, ExpressionsTypeEnum.And); } // if (factorPaginationDto.Bank > 0 && factorPaginationDto.Bank < 10) { Expression <Func <Factor, bool> > tempExp = p => p.Bank == factorPaginationDto.Bank; exp = CombineExpressions.CombiningExpressions <Factor>(exp, tempExp, ExpressionsTypeEnum.And); } // Expression <Func <Factor, bool> > priceExp = p => p.Price >= factorPaginationDto.MinPrice && p.Price <= factorPaginationDto.MaxPrice; exp = CombineExpressions.CombiningExpressions <Factor>(exp, priceExp, ExpressionsTypeEnum.And); // var minDt = DateTimeOffset.FromUnixTimeMilliseconds(factorPaginationDto.MinDate); minDt = new DateTime(minDt.Year, minDt.Month, minDt.Day, 0, 0, 0); var maxDt = DateTimeOffset.FromUnixTimeMilliseconds(factorPaginationDto.MaxDate); maxDt = new DateTime(maxDt.Year, maxDt.Month, maxDt.Day, 23, 59, 0); Expression <Func <Factor, bool> > datExp = p => p.DateCreated >= minDt && p.DateCreated <= maxDt; exp = CombineExpressions.CombiningExpressions <Factor>(exp, datExp, ExpressionsTypeEnum.And); return(exp); case SearchIdEnums.User: if (string.IsNullOrEmpty(factorPaginationDto.Filter) || string.IsNullOrWhiteSpace(factorPaginationDto.Filter)) { Expression <Func <Factor, bool> > expUser = p => p.UserId == id; return(expUser); } else { Expression <Func <Factor, bool> > expUser = p => p.UserId == id && (p.Id.Contains(factorPaginationDto.Filter) || p.UserName.Contains(factorPaginationDto.Filter) || p.GiftCode.Contains(factorPaginationDto.Filter) || p.Price.ToString().Contains(factorPaginationDto.Filter) || p.EndPrice.ToString().Contains(factorPaginationDto.Filter) || p.RefBank.Contains(factorPaginationDto.Filter) || p.EnterMoneyWalletId.Contains(factorPaginationDto.Filter) || p.UserId.Contains(factorPaginationDto.Filter) || p.GateId.Contains(factorPaginationDto.Filter)); return(expUser); } case SearchIdEnums.Wallet: if (string.IsNullOrEmpty(factorPaginationDto.Filter) || string.IsNullOrWhiteSpace(factorPaginationDto.Filter)) { Expression <Func <Factor, bool> > expWallet = p => p.EnterMoneyWalletId == id; return(expWallet); } else { Expression <Func <Factor, bool> > expWallet = p => p.EnterMoneyWalletId == id && (p.Id.Contains(factorPaginationDto.Filter) || p.UserName.Contains(factorPaginationDto.Filter) || p.GiftCode.Contains(factorPaginationDto.Filter) || p.Price.ToString().Contains(factorPaginationDto.Filter) || p.EndPrice.ToString().Contains(factorPaginationDto.Filter) || p.RefBank.Contains(factorPaginationDto.Filter) || p.EnterMoneyWalletId.Contains(factorPaginationDto.Filter) || p.UserId.Contains(factorPaginationDto.Filter) || p.GateId.Contains(factorPaginationDto.Filter)); return(expWallet); } case SearchIdEnums.Gate: Expression <Func <Factor, bool> > expGate = p => true; if (!isAdmin) { Expression <Func <Factor, bool> > tempExp = p => p.UserId == userId; expGate = CombineExpressions.CombiningExpressions <Factor>(expGate, tempExp, ExpressionsTypeEnum.And); } if (string.IsNullOrEmpty(factorPaginationDto.Filter) || string.IsNullOrWhiteSpace(factorPaginationDto.Filter)) { Expression <Func <Factor, bool> > tempExp = p => p.GateId == id; return(CombineExpressions.CombiningExpressions <Factor>(expGate, tempExp, ExpressionsTypeEnum.And)); } else { Expression <Func <Factor, bool> > tempExp = p => p.GateId == id && (p.Id.Contains(factorPaginationDto.Filter) || p.UserName.Contains(factorPaginationDto.Filter) || p.GiftCode.Contains(factorPaginationDto.Filter) || p.Price.ToString().Contains(factorPaginationDto.Filter) || p.EndPrice.ToString().Contains(factorPaginationDto.Filter) || p.RefBank.Contains(factorPaginationDto.Filter) || p.EnterMoneyWalletId.Contains(factorPaginationDto.Filter) || p.UserId.Contains(factorPaginationDto.Filter) || p.GateId.Contains(factorPaginationDto.Filter)); return(CombineExpressions.CombiningExpressions <Factor>(expGate, tempExp, ExpressionsTypeEnum.And)); } default: return(null); } }