private async Task EnsureClassroomDoesNotExistAsync( CreateClassroomCommand command, CancellationToken cancellationToken) { var query = new GetUserClassroomsQuery(command.UserId); var list = await _queryProcessor.ExecuteAsync(query, cancellationToken); if (list.Any(c => c.Grade == command.Grade && string.Equals(c.Name, command.Name, StringComparison.InvariantCultureIgnoreCase))) { throw new ValidationException(ErrorCodes.ClassroomExists); } }
public override async Task <IReadOnlyCollection <ClassroomReadModel> > ExecuteAsync( GetUserClassroomsQuery query, CancellationToken cancellationToken = default) { const string sql = "SELECT * FROM classrooms " + "WHERE created_by=@userId " + "ORDER BY grade_value,name_value"; await using var connection = new NpgsqlConnection(_connectionString); return((await connection.QueryAsync <ClassroomReadModel>( sql, new { userId = query.UserId })).ToList()); }