public async Task <IActionResult> CountObjects([FromRoute] DatabaseRouteParameters routeParameters, [FromBody] string countExpression) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var countResults = await _service.CountAsync(routeParameters.DatabaseName, routeParameters.CollectionName, countExpression); return(Ok(countResults)); }
/// <inheritdoc /> public virtual async Task <int> CountAsync( Expression <Func <TEntity, bool> > filter = null, CancellationToken cancellationToken = default) { int count = await DecoratedService.CountAsync(filter, cancellationToken); AuditScope auditScope = null; try { var options = new AuditScopeOptions { EventType = $"{EntityName}:Count", ExtraFields = new { Count = count }, AuditEvent = new AuditEvent { Target = new AuditTarget() } }; auditScope = await AuditScope.CreateAsync(options); auditScope.Event.Environment.UserName = UserContext.CurrentUser; auditScope.Event.Target.Type = $"{EntityFullName}"; } catch (Exception e) { Logger.Warning(e, "Auditing failed for CountAsync of type {Entity}.", EntityName); } finally { if (auditScope != null) { await auditScope.DisposeAsync(); } } return(count); }