protected override void ProcessRecord()
        {
            var qb = new QuerystringBuilder();

            if (Ids != null && Ids.Any())
            {
                qb.Add("ids", Ids);
            }

            if (Names != null && Names.Any())
            {
                qb.Add("names", Names);
            }

            if (ClusterPartitionIds != null && ClusterPartitionIds.Any())
            {
                qb.Add("clusterPartitionIds", ClusterPartitionIds);
            }

            if (FetchStats.IsPresent)
            {
                qb.Add("fetchStats", true.ToString());
            }

            var preparedUrl = $"/public/viewBoxes{qb.Build()}";
            var result      = Session.ApiClient.Get <IEnumerable <ViewBox> >(preparedUrl);

            WriteObject(result, true);
        }
Пример #2
0
        public IQueryable <Account> Filter(IQueryable <Account> filterQuery)
        {
            if (!string.IsNullOrEmpty(SearchTerm))
            {
                if (Guid.TryParse(SearchTerm, out var accId))
                {
                    filterQuery = filterQuery.Where(t => t.Id == accId);
                }
                else
                {
                    filterQuery = filterQuery.Where(t => t.Email == SearchTerm);
                }
            }

            if (Ids.Count > 0)
            {
                filterQuery = filterQuery.Where(t => Ids.Any(v => v == t.Id));
            }

            if (Names.Count > 0)
            {
                filterQuery = filterQuery.Where(t => Names.Any(v => t.Name.Contains(v)));
            }

            return(filterQuery);
        }
        protected override void ProcessRecord()
        {
            var queries = new Dictionary <string, string>();

            // Always include last run and stats
            queries.Add("includeLastRunAndStats", true.ToString().ToLower());

            if (OnlyActive.IsPresent)
            {
                queries.Add("isActive", true.ToString().ToLower());
            }

            if (OnlyInactive.IsPresent)
            {
                queries.Add("isActive", false.ToString().ToLower());
            }

            if (OnlyDeleted.IsPresent)
            {
                queries.Add("isDeleted", true.ToString().ToLower());
            }

            if (Ids != null && Ids.Any())
            {
                queries.Add("ids", string.Join(",", Ids));
            }

            if (Names != null && Names.Any())
            {
                queries.Add("names", string.Join(",", Names));
            }

            if (PolicyIds != null && PolicyIds.Any())
            {
                queries.Add("policyIds", string.Join(",", PolicyIds));
            }

            if (Environments != null && Environments.Any())
            {
                List <string> envs = Environments.ToList().ConvertAll <string>(x => x.ToString().First().ToString().ToLower() + x.ToString().Substring(1));
                queries.Add("environments", string.Join(",", envs));
            }

            var queryString = string.Empty;

            if (queries.Any())
            {
                queryString = "?" + string.Join("&", queries.Select(q => $"{q.Key}={q.Value}"));
            }

            var preparedUrl = $"/public/protectionJobs{queryString}";
            var results     = Session.ApiClient.Get <IEnumerable <Model.ProtectionJob> >(preparedUrl);

            // Hide deleted protection jobs unless explicitly asked for
            if (!OnlyDeleted.IsPresent)
            {
                results = results.Where(x => !(x.Name.StartsWith("_DELETED"))).ToList();
            }
            WriteObject(results, true);
        }
Пример #4
0
        protected override void ProcessRecord()
        {
            var qb = new QuerystringBuilder();

            if (Environments != null && Environments.Any())
            {
                List <string> envs = Environments.ToList().ConvertAll <string>(x => x.ToString().First().ToString().ToLower() + x.ToString().Substring(1));
                qb.Add("environments", string.Join(",", envs));
            }

            if (Ids != null && Ids.Any())
            {
                qb.Add("ids", string.Join(",", Ids));
            }

            if (Names != null && Names.Any())
            {
                qb.Add("names", string.Join(",", Names));
            }

            var preparedUrl = $"/public/protectionPolicies{qb.Build()}";
            var result      = Session.ApiClient.Get <IEnumerable <Model.ProtectionPolicy> >(preparedUrl);

            WriteObject(result, true);
        }
        /// <summary>
        /// Process Records
        /// </summary>
        protected override void ProcessRecord()
        {
            var queries = new Dictionary <string, string>();

            if (Ids != null && Ids.Any())
            {
                queries.Add("ids", string.Join(",", Ids));
            }

            if (Names != null && Names.Any())
            {
                queries.Add("names", string.Join(",", Names));
            }

            var queryString = string.Empty;

            if (queries.Any())
            {
                queryString = "?" + string.Join("&", queries.Select(q => $"{q.Key}={q.Value}"));
            }

            var preparedUrl = $"/public/clusterPartitions{queryString}";
            var result      = Session.ApiClient.Get <IEnumerable <Models.ClusterPartition> >(preparedUrl);

            WriteObject(result, true);
        }
        private bool EntryHandlerFunction(PwDatabase db, PwEntry pwEntry)
        {
            if (!IncludeRecycleBin && db.RecycleBinEnabled && db.IsEntryInRecycleBin(pwEntry))
            {
                return(false);
            }

            return(Ids.Any(x => pwEntry.Uuid.ToHexString() == x));
        }
Пример #7
0
 internal Func <Product, bool> GetFuncPredicate()
 {
     return((Product p) =>
            (Ids != null && Ids.Any() ? Ids.Contains(p.Id) : true) &&
            (MaxCount != null ? p.CountInStock < MaxCount : true) &&
            (MinCount != null ? p.CountInStock > MinCount : true) &&
            (UnitId != null ? p.UnitId == UnitId : true) &&
            (MinWeight != null ? p.Weight > MinWeight : true) &&
            (MaxWeight != null ? p.Weight < MaxWeight : true) &&
            (ManufactureCountryId != null ? p.ManufactureCountryId == ManufactureCountryId : true) &&
            (Name != null ? p.Name.Contains(Name, StringComparison.OrdinalIgnoreCase) : true));
 }
        /// <summary>
        /// Add parameters to the object model dictionary.
        /// </summary>
        /// <param name="dict">Dictionary to be updated with parameters.</param>
        protected override void AddParamsToDictionary(SortedDictionary <string, object> dict)
        {
            if (Enabled.HasValue)
            {
                AddParam(dict, "enabled", Enabled.Value);
            }

            if (Ids != null && Ids.Any())
            {
                AddParam(dict, "ids", Ids);
            }

            if (!string.IsNullOrEmpty(Prefix))
            {
                AddParam(dict, "prefix", Prefix);
            }
        }
Пример #9
0
        public IQueryable <User> Filter(IQueryable <User> filterQuery)
        {
            if (!string.IsNullOrEmpty(SearchTerm))
            {
                filterQuery = Guid.TryParse(SearchTerm, out var userId)
                    ? filterQuery.Where(t => t.Id == userId)
                    : filterQuery.Where(t => CheckContains(t));
            }

            if (Ids.Count > 0)
            {
                filterQuery = filterQuery.Where(t => Ids.Any(v => v == t.Id));
            }

            if (Names.Count > 0)
            {
                filterQuery = filterQuery.Where(t => Names.Any(v => t.Username.Contains(v)));
            }

            return(filterQuery);
        }
Пример #10
0
        public IQueryable <Material> Filter(IQueryable <Material> filterQuery)
        {
            if (!string.IsNullOrEmpty(SearchTerm))
            {
                filterQuery = Guid.TryParse(SearchTerm, out var materialId)
                    ? filterQuery.Where(t => t.Id == materialId)
                    : filterQuery.Where(t => t.MaterialName == SearchTerm);
            }

            if (Ids.Count > 0)
            {
                filterQuery = filterQuery.Where(t => Ids.Any(v => v == t.Id));
            }

            if (Names.Count > 0)
            {
                filterQuery = filterQuery.Where(t => Names.Any(v => t.MaterialName.Contains(v)));
            }

            return(filterQuery);
        }
Пример #11
0
        public Exp GetExpression()
        {
            var exp = Exp.Empty;

            if (Ids != null && Ids.Any())
            {
                exp &= Exp.In(UserFolderTreeTable.Columns.FolderId, Ids);
            }

            if (ParentId.HasValue)
            {
                exp &= Exp.Eq(UserFolderTreeTable.Columns.ParentId, ParentId.Value);
            }

            if (Level.HasValue)
            {
                exp &= Exp.Eq(UserFolderTreeTable.Columns.Level, Level.Value);
            }

            return(exp);
        }
        protected override void ProcessRecord()
        {
            var queries = new Dictionary <string, string>();

            if (Types != null && Types.Any())
            {
                List <string> types = Types.ToList().ConvertAll <string>(x => x.ToString().First().ToString().ToLower() + x.ToString().Substring(1));
                queries.Add("taskTypes", string.Join(",", types));
            }

            if (Ids != null && Ids.Any())
            {
                queries.Add("taskIds", string.Join(",", Ids));
            }

            if (StartTime.HasValue)
            {
                queries.Add("startTimeUsecs", StartTime.ToString());
            }

            if (EndTime.HasValue)
            {
                queries.Add("endTimeUsecs", EndTime.ToString());
            }

            var queryString = string.Empty;

            if (queries.Any())
            {
                queryString = "?" + string.Join("&", queries.Select(q => $"{q.Key}={q.Value}"));
            }

            var url    = $"/public/restore/tasks{queryString}";
            var result = Session.ApiClient.Get <IEnumerable <RestoreTask> >(url);

            WriteObject(result, true);
        }
        protected override void ProcessRecord()
        {
            var qb = new QuerystringBuilder();

            if (Environments != null && Environments.Any())
            {
                qb.Add("environments", string.Join(",", Environments));
            }

            if (Ids != null && Ids.Any())
            {
                qb.Add("ids", string.Join(",", Ids));
            }

            if (Names != null && Names.Any())
            {
                qb.Add("names", string.Join(",", Names));
            }

            var preparedUrl = $"/public/protectionPolicies{qb.Build()}";
            var result      = Session.ApiClient.Get <IEnumerable <Models.ProtectionPolicy> >(preparedUrl);

            WriteObject(result, true);
        }
        public Exp GetExpression()
        {
            var exp = Exp.Eq(UserFolderTable.Columns.Tenant, Tenant)
                      & Exp.Eq(UserFolderTable.Columns.User, User);

            if (Ids != null && Ids.Any())
            {
                exp &= Exp.In(UserFolderTable.Columns.Id, Ids);
            }

            if (ParentId.HasValue)
            {
                exp &= Exp.Eq(UserFolderTable.Columns.ParentId, ParentId.Value);
            }

            if (!string.IsNullOrEmpty(Name))
            {
                exp &= Exp.Eq(UserFolderTable.Columns.Name, Name);
            }

            if (HasMails.HasValue)
            {
                exp &= HasMails.Value
                    ? Exp.Gt(UserFolderTable.Columns.TotalMessagesCount, 0)
                    : Exp.Eq(UserFolderTable.Columns.TotalMessagesCount, 0);
            }

            if (HasFolders.HasValue)
            {
                exp &= HasFolders.Value
                    ? Exp.Gt(UserFolderTable.Columns.FolderCount, 0)
                    : Exp.Eq(UserFolderTable.Columns.FolderCount, 0);
            }

            return(exp);
        }
Пример #15
0
        /// <summary>
        /// Prepares the WHERE clause of the SQL query from the <see cref="Filter"/> argument: WHERE ABC
        /// </summary>
        private string PrepareWhereSql(QxCompilationContext ctx)
        {
            var ps = ctx.Parameters;

            // WHERE is cached
            if (_cachedWhere == null)
            {
                string whereFilter       = null;
                string whereInIds        = null;
                string whereInParentIds  = null;
                string whereInPropValues = null;

                if (Filter != null)
                {
                    whereFilter = Filter.Expression.CompileToBoolean(ctx);
                }

                if (Ids != null && Ids.Any())
                {
                    if (Ids.Count() == 1)
                    {
                        string paramName = ps.AddParameter(Ids.Single());
                        whereInIds = $"[P].[Id] = @{paramName}";
                    }
                    else
                    {
                        var isIntKey    = KeyType == KeyType.Int; // (Nullable.GetUnderlyingType(KeyType) ?? KeyType) == typeof(int);
                        var isStringKey = KeyType == KeyType.String;

                        // Prepare the ids table
                        DataTable idsTable = isIntKey ? RepositoryUtilities.DataTable(Ids.Select(id => new IdListItem {
                            Id = (int)id
                        }))
                            : isStringKey?RepositoryUtilities.DataTable(Ids.Select(id => new StringListItem {
                            Id = id.ToString()
                        }))
                                                 : throw new InvalidOperationException("Only string and Integer Ids are supported");

                        //
                        var idsTvp = new SqlParameter("@Ids", idsTable)
                        {
                            TypeName = isIntKey ? "[dbo].[IdList]" : isStringKey ? "[dbo].[StringList]" : throw new InvalidOperationException("Only string and Integer Ids are supported"),
                                             SqlDbType = SqlDbType.Structured
                        };

                        ps.AddParameter(idsTvp);
                        whereInIds = $"[P].[Id] IN (SELECT Id FROM @Ids)";
                    }
                }

                if (ParentIds != null)
                {
                    if (!ParentIds.Any())
                    {
                        if (IncludeRoots)
                        {
                            whereInParentIds = $"[P].[ParentId] IS NULL";
                        }
                    }
                    else if (ParentIds.Count() == 1)
                    {
                        string paramName = ps.AddParameter(ParentIds.Single());
                        whereInParentIds = $"[P].[ParentId] = @{paramName}";
                        if (IncludeRoots)
                        {
                            whereInParentIds += " OR [P].[ParentId] IS NULL";
                        }
                    }
                    else
                    {
                        var isIntKey    = KeyType == KeyType.Int; // (Nullable.GetUnderlyingType(KeyType) ?? KeyType) == typeof(int);
                        var isStringKey = KeyType == KeyType.String;

                        // Prepare the data table
                        var    parentIdsTable = new DataTable();
                        string idName         = "Id";
                        var    idType         = KeyType switch
                        {
                            KeyType.String => typeof(string),
                            KeyType.Int => typeof(int),
                            _ => throw new InvalidOperationException("Bug: Only string and Integer ParentIds are supported"),
                        };

                        var column = new DataColumn(idName, idType);
                        if (isStringKey)
                        {
                            column.MaxLength = 450; // Just for performance
                        }
                        parentIdsTable.Columns.Add(column);
                        foreach (var id in ParentIds.Where(e => e != null))
                        {
                            DataRow row = parentIdsTable.NewRow();
                            row[idName] = id;
                            parentIdsTable.Rows.Add(row);
                        }

                        // Prepare the TVP
                        var parentIdsTvp = new SqlParameter("@ParentIds", parentIdsTable)
                        {
                            TypeName = KeyType == KeyType.Int ? "[dbo].[IdList]" : KeyType == KeyType.String ? "[dbo].[StringList]" : throw new InvalidOperationException("Bug: Only string and Integer ParentIds are supported"),
                                             SqlDbType = SqlDbType.Structured
                        };

                        ps.AddParameter(parentIdsTvp);
                        whereInParentIds = $"[P].[ParentId] IN (SELECT Id FROM @ParentIds)";
                        if (IncludeRoots)
                        {
                            whereInParentIds += " OR [P].[ParentId] IS NULL";
                        }
                    }
                }

                if (!string.IsNullOrWhiteSpace(PropName) && Values != null && Values.Any())
                {
                    var propDesc = ResultDescriptor.Property(PropName);
                    var propType = propDesc.Type;

                    var isIntKey    = propType == typeof(int?) || propType == typeof(int);
                    var isStringKey = propType == typeof(string);

                    // Prepare the ids table
                    DataTable valuesTable =
                        isStringKey ? RepositoryUtilities.DataTable(Values.Select(id => new StringListItem {
                        Id = id.ToString()
                    })) :
                        isIntKey?RepositoryUtilities.DataTable(Values.Select(id => new IdListItem {
                        Id = (int)id
                    })) :
                        throw new InvalidOperationException("Only string and Integer Ids are supported");

                    var valuesTvp = new SqlParameter("@Values", valuesTable)
                    {
                        TypeName = isIntKey ? "[dbo].[IdList]" : isStringKey ? "[dbo].[StringList]" : throw new InvalidOperationException("Only string and Integer values are supported"),
                                         SqlDbType = SqlDbType.Structured
                    };

                    ps.AddParameter(valuesTvp);
                    whereInPropValues = $"[P].[{propDesc.Name}] IN (SELECT Id FROM @Values)";
                }

                // The final WHERE clause (if any)
                string whereSql = "";

                var clauses = new List <string> {
                    whereFilter, whereInIds, whereInParentIds, whereInPropValues
                }.Where(e => !string.IsNullOrWhiteSpace(e));
                if (clauses.Any())
                {
                    whereSql = clauses.Aggregate((c1, c2) => $"{c1}) AND ({c2}");
                    whereSql = $"WHERE ({whereSql})";
                }

                _cachedWhere = whereSql;
            }

            return(_cachedWhere);
        }
Пример #16
0
        public virtual Exp GetExpression()
        {
            var filterExp = Exp.Eq(MailTable.Columns.Folder.Prefix(MM_ALIAS), (int)Filter.PrimaryFolder);

            if (Filter.Unread.HasValue)
            {
                filterExp &= Exp.Eq(MailTable.Columns.Unread.Prefix(MM_ALIAS), Filter.Unread);
            }

            if (Filter.Attachments.HasValue)
            {
                filterExp &= Exp.Gt(MailTable.Columns.AttachCount.Prefix(MM_ALIAS), 0);
            }

            if (Filter.PeriodFrom.HasValue && Filter.PeriodTo.HasValue)
            {
                var fromTs = TimeSpan.FromMilliseconds(Filter.PeriodFrom.Value);
                var from   = Defines.BaseJsDateTime.Add(fromTs);

                var toTs = TimeSpan.FromMilliseconds(Filter.PeriodTo.Value);
                var to   = Defines.BaseJsDateTime.Add(toTs);

                filterExp &= Exp.Between(MailTable.Columns.DateSent.Prefix(MM_ALIAS), from, to);
            }

            if (Filter.Important.HasValue)
            {
                filterExp &= Exp.Eq(MailTable.Columns.Importance.Prefix(MM_ALIAS), true);
            }

            if (Filter.WithCalendar.HasValue)
            {
                filterExp &= !Exp.Eq(MailTable.Columns.CalendarUid.Prefix(MM_ALIAS), null);
            }

            if (!string.IsNullOrEmpty(Filter.FromAddress) && !FactoryIndexer <MailWrapper> .Support)
            {
                if (Filter.PrimaryFolder == FolderType.Sent || Filter.PrimaryFolder == FolderType.Draft)
                {
                    filterExp &= Exp.Like(MailTable.Columns.To.Prefix(MM_ALIAS), Filter.FromAddress, SqlLike.AnyWhere);
                }
                else
                {
                    filterExp &= Exp.Like(MailTable.Columns.From.Prefix(MM_ALIAS), Filter.FromAddress,
                                          SqlLike.AnyWhere);
                }
            }

            if (!string.IsNullOrEmpty(Filter.ToAddress) && !FactoryIndexer <MailWrapper> .Support)
            {
                if (Filter.PrimaryFolder == FolderType.Sent || Filter.PrimaryFolder == FolderType.Draft)
                {
                    filterExp &= Exp.Like(MailTable.Columns.From.Prefix(MM_ALIAS), Filter.ToAddress, SqlLike.AnyWhere);
                }
                else
                {
                    filterExp &= Exp.Like(MailTable.Columns.To.Prefix(MM_ALIAS), Filter.ToAddress,
                                          SqlLike.AnyWhere);
                }
            }

            if (Filter.MailboxId.HasValue)
            {
                filterExp &= Exp.Eq(MailTable.Columns.MailboxId.Prefix(MM_ALIAS), Filter.MailboxId.Value);
            }

            if (!string.IsNullOrEmpty(Filter.SearchText) && !FactoryIndexer <MailWrapper> .Support)
            {
                filterExp &=
                    Exp.Or(Exp.Like(MailTable.Columns.From.Prefix(MM_ALIAS), Filter.SearchText, SqlLike.AnyWhere),
                           Exp.Or(
                               Exp.Like(MailTable.Columns.To.Prefix(MM_ALIAS), Filter.SearchText, SqlLike.AnyWhere),
                               Exp.Or(
                                   Exp.Like(MailTable.Columns.Cc.Prefix(MM_ALIAS), Filter.SearchText,
                                            SqlLike.AnyWhere),
                                   Exp.Or(
                                       Exp.Like(MailTable.Columns.Bcc.Prefix(MM_ALIAS), Filter.SearchText,
                                                SqlLike.AnyWhere),
                                       Exp.Or(
                                           Exp.Like(MailTable.Columns.Subject.Prefix(MM_ALIAS), Filter.SearchText,
                                                    SqlLike.AnyWhere),
                                           Exp.Like(MailTable.Columns.Introduction.Prefix(MM_ALIAS), Filter.SearchText,
                                                    SqlLike.AnyWhere)
                                           )
                                       )
                                   )
                               )
                           );
            }

            if (Ids != null && Ids.Any())
            {
                filterExp &= Exp.In(MailTable.Columns.Id.Prefix(MM_ALIAS), Ids);
            }

            var exp = Exp.Eq(MailTable.Columns.Tenant.Prefix(MM_ALIAS), Tenant) &
                      Exp.Eq(MailTable.Columns.User.Prefix(MM_ALIAS), User) &
                      Exp.Eq(MailTable.Columns.IsRemoved.Prefix(MM_ALIAS), false);

            exp &= filterExp;

            return(exp);
        }
        public virtual Exp GetExpression()
        {
            var filterExp = Exp.Empty;

            if (!FactoryIndexer <MailWrapper> .Support)
            {
                Func <ConditionKeyType, string> toDbField = c =>
                {
                    switch (c)
                    {
                    case ConditionKeyType.From:
                        return(MailTable.Columns.From.Prefix(MM_ALIAS));

                    case ConditionKeyType.To:
                        return(MailTable.Columns.To.Prefix(MM_ALIAS));

                    case ConditionKeyType.Cc:
                        return(MailTable.Columns.Cc.Prefix(MM_ALIAS));

                    case ConditionKeyType.Subject:
                        return(MailTable.Columns.Subject.Prefix(MM_ALIAS));

                    default:
                        throw new ArgumentOutOfRangeException("c", c, null);
                    }
                };

                Func <MailSieveFilterConditionData, Exp> getConditionExp = c =>
                {
                    var e = Exp.Empty;

                    switch (c.Operation)
                    {
                    case ConditionOperationType.Matches:
                        e = c.Key == ConditionKeyType.ToOrCc
                                ? Exp.Or(Exp.Eq(MailTable.Columns.To.Prefix(MM_ALIAS), c.Value),
                                         Exp.Eq(MailTable.Columns.Cc.Prefix(MM_ALIAS), c.Value))
                                : Exp.Eq(toDbField(c.Key), c.Value);
                        break;

                    case ConditionOperationType.Contains:
                        e = c.Key == ConditionKeyType.ToOrCc
                                ? Exp.Or(Exp.Like(MailTable.Columns.To.Prefix(MM_ALIAS), c.Value, SqlLike.AnyWhere),
                                         Exp.Like(MailTable.Columns.Cc.Prefix(MM_ALIAS), c.Value, SqlLike.AnyWhere))
                                : Exp.Like(toDbField(c.Key), c.Value, SqlLike.AnyWhere);
                        break;

                    case ConditionOperationType.NotMatches:
                        e = c.Key == ConditionKeyType.ToOrCc
                                ? !Exp.And(Exp.Eq(MailTable.Columns.To.Prefix(MM_ALIAS), c.Value),
                                           Exp.Eq(MailTable.Columns.Cc.Prefix(MM_ALIAS), c.Value))
                                : !Exp.Eq(toDbField(c.Key), c.Value);
                        break;

                    case ConditionOperationType.NotContains:
                        e = c.Key == ConditionKeyType.ToOrCc
                                ? Exp.And(!Exp.Like(MailTable.Columns.To.Prefix(MM_ALIAS), c.Value, SqlLike.AnyWhere),
                                          !Exp.Like(MailTable.Columns.Cc.Prefix(MM_ALIAS), c.Value, SqlLike.AnyWhere))
                                : !Exp.Like(toDbField(c.Key), c.Value, SqlLike.AnyWhere);
                        break;
                    }

                    return(e);
                };

                if (Filter.Conditions != null && Filter.Conditions.Any())
                {
                    var cExp = Exp.Empty;

                    foreach (var c in Filter.Conditions)
                    {
                        switch (Filter.Options.MatchMultiConditions)
                        {
                        case MatchMultiConditionsType.MatchAll:
                        case MatchMultiConditionsType.None:
                            cExp &= getConditionExp(c);
                            break;

                        case MatchMultiConditionsType.MatchAtLeastOne:
                            cExp |= getConditionExp(c);
                            break;
                        }
                    }

                    filterExp &= cExp;
                }
            }

            if (Ids != null && Ids.Any())
            {
                filterExp &= Exp.In(MailTable.Columns.Id.Prefix(MM_ALIAS), Ids);
            }

            if (Filter.Options.ApplyTo.Folders.Any())
            {
                filterExp &= Exp.In(MailTable.Columns.Folder.Prefix(MM_ALIAS), Filter.Options.ApplyTo.Folders);
            }

            if (Filter.Options.ApplyTo.Mailboxes.Any())
            {
                filterExp &= Exp.In(MailTable.Columns.MailboxId.Prefix(MM_ALIAS), Filter.Options.ApplyTo.Mailboxes);
            }

            switch (Filter.Options.ApplyTo.WithAttachments)
            {
            case ApplyToAttachmentsType.WithAttachments:
                filterExp &= Exp.Gt(MailTable.Columns.AttachCount.Prefix(MM_ALIAS), 0);
                break;

            case ApplyToAttachmentsType.WithoutAttachments:
                filterExp &= Exp.Eq(MailTable.Columns.AttachCount.Prefix(MM_ALIAS), 0);
                break;

            case ApplyToAttachmentsType.WithAndWithoutAttachments:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            var exp = Exp.Eq(MailTable.Columns.Tenant.Prefix(MM_ALIAS), Tenant) &
                      Exp.Eq(MailTable.Columns.User.Prefix(MM_ALIAS), User) &
                      Exp.Eq(MailTable.Columns.IsRemoved.Prefix(MM_ALIAS), false);

            exp &= filterExp;

            return(exp);
        }