public static Expression <Func <Gate, bool> > ToGateExpression(this string Filter,
                                                                       bool isId, string id = "")
        {
            Expression <Func <Gate, bool> > exp = p => true;

            if (isId)
            {
                Expression <Func <Gate, bool> > tempExp = p => p.WalletId == id;
                exp = CombineExpressions.CombiningExpressions <Gate>(exp, tempExp, ExpressionsTypeEnum.And);
            }

            if (string.IsNullOrEmpty(Filter) || string.IsNullOrWhiteSpace(Filter))
            {
                return(exp);
            }
            else
            {
                Expression <Func <Gate, bool> > tempExp =
                    p => p.Id.Contains(Filter) ||
                    p.Ip.Contains(Filter) ||
                    p.WebsiteName.Contains(Filter) ||
                    p.WebsiteUrl.Contains(Filter) ||
                    p.PhoneNumber.Contains(Filter) ||
                    p.Text.Contains(Filter) ||
                    p.Grouping.Contains(Filter) ||
                    p.IconUrl.Contains(Filter) ||
                    p.WalletId.Contains(Filter);

                return(CombineExpressions.CombiningExpressions <Gate>(exp, tempExp, ExpressionsTypeEnum.And));
            }
        }
        public static Expression <Func <Ticket, bool> > ToTicketExpression(
            this TicketsPaginationDto ticketsPaginationDto,
            SearchIdEnums searchIdType, string id = "")
        {
            switch (searchIdType)
            {
            case SearchIdEnums.None:
                Expression <Func <Ticket, bool> > exp = p => true;
                if (!string.IsNullOrEmpty(ticketsPaginationDto.Filter) && !string.IsNullOrWhiteSpace(ticketsPaginationDto.Filter))
                {
                    Expression <Func <Ticket, bool> > tempExp =
                        (p => p.Id.Contains(ticketsPaginationDto.Filter) ||
                         p.Title.Contains(ticketsPaginationDto.Filter) ||
                         p.TicketContents.Any(s => s.Text.Contains(ticketsPaginationDto.Filter)) ||
                         p.TicketContents.Any(s => s.Id.Contains(ticketsPaginationDto.Filter)));

                    exp = CombineExpressions.CombiningExpressions <Ticket>(exp, tempExp, ExpressionsTypeEnum.And);
                }
                //
                if (ticketsPaginationDto.Closed == 1)
                {
                    Expression <Func <Ticket, bool> > tempExp =
                        p => p.Closed;
                    exp = CombineExpressions.CombiningExpressions <Ticket>(exp, tempExp, ExpressionsTypeEnum.And);
                }
                if (ticketsPaginationDto.Closed == 2)
                {
                    Expression <Func <Ticket, bool> > tempExp =
                        p => !p.Closed;
                    exp = CombineExpressions.CombiningExpressions <Ticket>(exp, tempExp, ExpressionsTypeEnum.And);
                }
                //
                if (ticketsPaginationDto.IsAdminSide == 1)
                {
                    Expression <Func <Ticket, bool> > tempExp =
                        p => p.IsAdminSide;
                    exp = CombineExpressions.CombiningExpressions <Ticket>(exp, tempExp, ExpressionsTypeEnum.And);
                }
                if (ticketsPaginationDto.IsAdminSide == 2)
                {
                    Expression <Func <Ticket, bool> > tempExp =
                        p => !p.IsAdminSide;
                    exp = CombineExpressions.CombiningExpressions <Ticket>(exp, tempExp, ExpressionsTypeEnum.And);
                }
                //
                if (ticketsPaginationDto.Department > 0)
                {
                    Expression <Func <Ticket, bool> > tempExp =
                        p => p.Department == ticketsPaginationDto.Department;
                    exp = CombineExpressions.CombiningExpressions <Ticket>(exp, tempExp, ExpressionsTypeEnum.And);
                }
                if (ticketsPaginationDto.Level > 0)
                {
                    Expression <Func <Ticket, bool> > tempExp =
                        p => p.Level == ticketsPaginationDto.Level;
                    exp = CombineExpressions.CombiningExpressions <Ticket>(exp, tempExp, ExpressionsTypeEnum.And);
                }
                //
                var minDt = DateTimeOffset.FromUnixTimeMilliseconds(ticketsPaginationDto.MinDate);

                var maxDt = DateTimeOffset.FromUnixTimeMilliseconds(ticketsPaginationDto.MaxDate);

                Expression <Func <Ticket, bool> > datExp =
                    p => p.DateCreated >= minDt &&
                    p.DateCreated <= maxDt;
                exp = CombineExpressions.CombiningExpressions <Ticket>(exp, datExp, ExpressionsTypeEnum.And);

                return(exp);

            case SearchIdEnums.User:
                if (string.IsNullOrEmpty(ticketsPaginationDto.Filter) || string.IsNullOrWhiteSpace(ticketsPaginationDto.Filter))
                {
                    Expression <Func <Ticket, bool> > expUser =
                        p => p.UserId == id;
                    return(expUser);
                }
                else
                {
                    Expression <Func <Ticket, bool> > expUser =
                        p => p.UserId == id &&
                        (p.Id.Contains(ticketsPaginationDto.Filter) ||
                         p.Title.Contains(ticketsPaginationDto.Filter) ||
                         p.TicketContents.Any(s => s.Text.Contains(ticketsPaginationDto.Filter)) ||
                         p.TicketContents.Any(s => s.Id.Contains(ticketsPaginationDto.Filter)));
                    return(expUser);
                }

            default:
                return(null);
            }
        }
        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);

                var maxDt = DateTimeOffset.FromUnixTimeMilliseconds(factorPaginationDto.MaxDate);

                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);
            }
        }