Beispiel #1
0
    public async ValueTask <ActionResult> StartTypingSession()
    {
        var typingSessionId = await _typingSessionRepository.NextIdAsync();

        var typingSession = new TypingSession(typingSessionId, ProfileId, DateTime.UtcNow, new TypingSessionConfiguration());

        await _typingSessionRepository.SaveAsync(typingSession);

        var result = new { typingSessionId };

        return(CreatedAtAction(nameof(GetById), result, result));
    }
Beispiel #2
0
    public static TypingSessionDto From(TypingSession typingSession)
    {
        var state = typingSession.GetState();

        return(new TypingSessionDto
        {
            TypingSessionId = state.TypingSessionId,
            Texts = state.Texts.Select(x => new TypingSessionTextDto
            {
                Index = x.Key,
                TextId = x.Value.TextId,
                Value = x.Value.Value
            }).ToList()
        });
    }
    public async ValueTask <TypingResultSubmitData> AddTypingResultAsync(TypedText typedText, string userId)
    {
        var text = await _textRepository.FindAsync(typedText.TextId)
                   .ConfigureAwait(false);

        if (text == null)
        {
            throw new InvalidOperationException("Text was not found.");
        }

        var typingSessionId = await _typingSessionRepository.NextIdAsync()
                              .ConfigureAwait(false);

        var typingSession          = new TypingSession(typingSessionId, userId, DateTime.UtcNow, new TypingSessionConfiguration());
        var typingSessionTextIndex = typingSession.AddText(new TypingSessionText(typedText.TextId, text.Value));
        await _typingSessionRepository.SaveAsync(typingSession)
        .ConfigureAwait(false);

        var userSessionId = await _userSessionRepository.NextIdAsync()
                            .ConfigureAwait(false);

        var userSession = new UserSession(userSessionId, userId, typingSessionId, DateTime.UtcNow, typedText.UserTimeZoneOffsetMinutes);
        await _userSessionRepository.SaveAsync(userSession)
        .ConfigureAwait(false);

        var typingResultId = Guid.NewGuid().ToString();

        await AddTypingResultAsync(userSessionId, new TextTypingResult(
                                       typingResultId,
                                       typingSessionTextIndex,
                                       typedText.StartedTypingUtc,
                                       DateTime.UtcNow,
                                       typedText.Events))
        .ConfigureAwait(false);

        return(new TypingResultSubmitData(typedText.TextId, typingSessionId, userSessionId, typingResultId));
    }