Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="q"></param>
        /// <param name="f"></param>
        /// <returns></returns>
        public static IQueryable <Alert> Filter(this IQueryable <Alert> q, AlertSearchFilter f)
        {
            if (f.PanelId.HasValue)
            {
                q = q.Where(x => x.PanelId == f.PanelId);
            }

            if (f.State.HasValue && f.State != AlertSearchFilter.Kind.All)
            {
                q = f.State switch
                {
                    AlertSearchFilter.Kind.Alerting => q.Where(x => x.State == AlertState.Alerting),
                    AlertSearchFilter.Kind.Pending => q.Where(x => x.State == AlertState.Pending),
                    AlertSearchFilter.Kind.Ok => q.Where(x => x.State == AlertState.Ok),
                    AlertSearchFilter.Kind.NotOK => q.Where(x => x.State != AlertState.Ok),
                    AlertSearchFilter.Kind.NoData => q.Where(x => x.State == AlertState.NoData),
                    AlertSearchFilter.Kind.Paused => q.Where(x => x.State == AlertState.Paused),
                    _ => q
                };
            }

            if (!string.IsNullOrEmpty(f.Query))
            {
                q = q.Where(x => EF.Functions.Like(x.Name, f.Query));
            }

            if (!string.IsNullOrEmpty(f.DashboardQuery))
            {
                q = q.Where(x => EF.Functions.Like(x.Dashboard.Title, f.DashboardQuery));
            }

            if (f.Limit.HasValue)
            {
                q = q.Take(f.Limit.Value);
            }

            if (f.HasDashboardIds)
            {
                q = q.Where(x => f.DashboardIds.Contains(x.DashboardId));
            }

            if (f.HasFolderIds)
            {
                q = q.Where(x => f.FolderIds.Contains(x.Dashboard.Folder.Id));
            }

            return(q);
        }

        #endregion
    }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name=""></param>
        public OperationResult <ModelAlerts> Search(AlertSearchFilter f)
        {
            OperationResult <ModelAlerts> res;

            try
            {
                var alerts = DataContext
                             .Alerts
                             .ForActiveOrg()
                             .Include(x => x.Dashboard)
                             .ThenInclude(x => x.Folder)
                             .Filter(f)
                             .Select(x => x.ToModel())
                             .ToList();

                res = OperationResult <ModelAlerts> .Create(alerts);
            }
            catch (Exception e)
            {
                res = OperationResult <ModelAlerts> .Create(ErrorCode.BadGetAlerts, e);
            }

            return(res);
        }