protected async Task <ActionResult <CountResult> > GetCountImplAsync(ExceptionlessSystemFilter sf, TimeInfo ti, string filter = null, string aggregations = null)
        {
            var pr = await _validator.ValidateQueryAsync(filter);

            if (!pr.IsValid)
            {
                return(BadRequest(pr.Message));
            }

            var far = await _validator.ValidateAggregationsAsync(aggregations);

            if (!far.IsValid)
            {
                return(BadRequest(far.Message));
            }

            sf.UsesPremiumFeatures = pr.UsesPremiumFeatures || far.UsesPremiumFeatures;
            var query = new RepositoryQuery <TModel>()
                        .SystemFilter(ShouldApplySystemFilter(sf, filter) ? sf : null)
                        .DateRange(ti.Range.UtcStart, ti.Range.UtcEnd, ti.Field)
                        .Index(ti.Range.UtcStart, ti.Range.UtcEnd);

            CountResult result;

            try {
                result = await _repository.CountBySearchAsync(query, filter, aggregations);
            } catch (Exception ex) {
                using (_logger.BeginScope(new ExceptionlessState().Property("Search Filter", new { SystemFilter = sf, UserFilter = filter, Time = ti, Aggregations = aggregations }).Tag("Search").Identity(CurrentUser.EmailAddress).Property("User", CurrentUser).SetHttpContext(HttpContext)))
                    _logger.LogError(ex, "An error has occurred. Please check your filter or aggregations.");

                return(BadRequest("An error has occurred. Please check your search filter."));
            }

            return(Ok(result));
        }
        protected virtual async Task <IHttpActionResult> GetCountAsync(IExceptionlessSystemFilterQuery sf, TimeInfo ti, string filter = null, string aggregations = null)
        {
            var pr = await _validator.ValidateQueryAsync(filter);

            if (!pr.IsValid)
            {
                return(BadRequest(pr.Message));
            }

            var far = await _validator.ValidateAggregationsAsync(aggregations);

            if (!far.IsValid)
            {
                return(BadRequest(far.Message));
            }

            sf.UsesPremiumFeatures = pr.UsesPremiumFeatures || far.UsesPremiumFeatures;
            IRepositoryQuery query = new ExceptionlessQuery()
                                     .WithSystemFilter(ShouldApplySystemFilter(sf, filter) ? sf : null)
                                     .WithDateRange(ti.Range.UtcStart, ti.Range.UtcEnd, ti.Field)
                                     .WithIndexes(ti.Range.UtcStart, ti.Range.UtcEnd);

            CountResult result;

            try {
                result = await _repository.CountBySearchAsync(query, filter, aggregations);
            } catch (Exception ex) {
                _logger.Error().Exception(ex)
                .Message("An error has occurred. Please check your filter or aggregations.")
                .Property("Search Filter", new { SystemFilter = sf, UserFilter = filter, Time = ti, Aggregations = aggregations })
                .Tag("Search")
                .Identity(CurrentUser.EmailAddress)
                .Property("User", CurrentUser)
                .SetActionContext(ActionContext)
                .Write();

                return(BadRequest("An error has occurred. Please check your search filter."));
            }

            return(Ok(result));
        }