public async ValueTask <ActionResult> StartUserSession(StartUserSessionDto dto) { var typingSession = await _typingSessionRepository.FindAsync(dto.TypingSessionId); if (typingSession == null) { return(NotFound()); } var userSessionId = await _userSessionRepository.NextIdAsync(); var userSession = new UserSession(userSessionId, ProfileId, dto.TypingSessionId, DateTime.UtcNow, dto.UserTimeZoneOffsetMinutes); await _userSessionRepository.SaveAsync(userSession); var result = new { userSessionId }; return(CreatedAtAction(nameof(GetById), result, result)); }
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)); }