public static Dictionary <string, object> ToDictionary <TEntity> (this DbDeleteListCommand <TEntity> from) where TEntity : class { if (from is null) { return(null); } return(new Dictionary <string, object> { { nameof(from.Ids), String.Join(',', from.Ids) } }); }
public async Task <DeleteResult> Handle (DbDeleteListCommand <GeoTask> request, CancellationToken cancellationToken) { try { Logger.LogInformation(LogEvent.DatabaseRequest, "Request={Request}.", request.ToDictionary()); var validation = new DbDeleteListCommandValidator <GeoTask>() .Validate(request); if (!validation.IsValid) { Logger.LogWarning (LogEvent.DatabaseRequestArgumentError, "Database command validation error. Error={Error}.", validation.Errors); return(ErrorResult("Database command validation error.")); } var db = DbContext.Db; var deleted = await db.GetCollection <DbGeoTask> (Defaults.TaskCollectionName) .DeleteManyAsync(x => request.Ids.Contains(x.Id)) .ConfigureAwait(false); if (deleted is null) { Logger.LogWarning(LogEvent.DatabaseEmptyResponse, "Database null response."); return(ErrorResult("Database null response")); } else { if (deleted.IsAcknowledged) { Logger.LogInformation(LogEvent.DatabaseRequest, "GeoTask deleted count={Count}.", deleted.DeletedCount); } } return(new DeleteResult(true)); } catch (Exception e) { Logger.LogWarning(LogEvent.DatabaseExceptionError, e, "Database exception error. Error={Error}.", e.Message); return(ErrorResult("Database exception error")); } }