Example #1
0
    protected virtual async Task <SessionInfo[]> GetUserSessions(
        string userId, CancellationToken cancellationToken = default)
    {
        if (!DbUserIdHandler.TryParse(userId).IsSome(out var dbUserId))
        {
            return(Array.Empty <SessionInfo>());
        }

        var dbContext = CreateDbContext();

        await using var _1 = dbContext.ConfigureAwait(false);
        var tx = await dbContext.Database.BeginTransactionAsync(cancellationToken).ConfigureAwait(false);

        await using var _2 = tx.ConfigureAwait(false);

        var dbSessions = await Sessions.ListByUser(dbContext, dbUserId, cancellationToken).ConfigureAwait(false);

        var sessions = new SessionInfo[dbSessions.Length];

        for (var i = 0; i < dbSessions.Length; i++)
        {
            sessions[i] = SessionConverter.ToModel(dbSessions[i]) !;
        }
        return(sessions);
    }