Beispiel #1
0
        public IActionResult Login(string participantID)
        {
            participantID             = participantID.Trim();
            var(isEnrolled, isActive) = _participantEnrollmentVerifier.Verify(participantID);
            string action;
            string whenToReturn = null;
            string nextActionAfterScreenCheck = null;

            if (isEnrolled)
            {
                IReturningUserPhaseData phaseData = _returningUserPhaseDataGetter.Get(participantID);
                if (isActive)
                {
                    if (phaseData.Action == ReturningUserAction.Done)
                    {
                        action = Url.Action("Index", "ThankYou");
                    }
                    else if (phaseData.Action == ReturningUserAction.Wait)
                    {
                        var nextTestWhenUtc = phaseData.NextTestWhenUtc.Value.AddMinutes(1);
                        whenToReturn = $"{nextTestWhenUtc.ToShortDateString()} {(nextTestWhenUtc.ToString("h:mm tt"))} UTC";
                        action       = Url.Action("Wait", "Test");
                    }
                    else if (phaseData.Action == ReturningUserAction.TooLate)
                    {
                        action = Url.Action("Expired", "Test");
                    }
                    else if (phaseData.Action == ReturningUserAction.Test)
                    {
                        var testName = _testNameGetter.Get(participantID);
                        var preTestQuestionsNeeded = !string.Equals(testName, "Immediate");
                        nextActionAfterScreenCheck = preTestQuestionsNeeded ? Url.Action("Index", "SleepQuestions") : Url.Action("WelcomeBack", "Test");
                        action = Url.Action("Index", "ScreenCheck");
                    }
                    else
                    {
                        var stanford = _stanfordRepository.Get(participantID);
                        if (stanford.Immediate.HasValue)
                        {
                            action = Url.Action("PreviouslyInterrupted", "Home");
                        }
                        else
                        {
                            nextActionAfterScreenCheck = Url.Action("ConsentInfo", "Home");
                            action = Url.Action("Index", "ScreenCheck");
                        }
                    }
                }
                else
                {
                    action = Url.Action("Index", "Finished");
                }
            }
            else
            {
                action = Url.Action("NotEnrolled", "Participant", new { id = participantID });
            }
            return(Json(new { success = true, action, participantID, whenToReturn, nextActionAfterScreenCheck }));
        }
        public IReturningUserPhaseData Get(string participantID)
        {
            var                 phaseSets       = _phaseSetsGetter.Get(participantID);
            var                 progress        = _progressGetter.Get(participantID);
            var                 testName        = _testNameGetter.Get(phaseSets, progress);
            var                 stanford        = _stanfordRepository.Get(participantID);
            DateTime?           nextTestWhenUtc = default;
            ReturningUserAction action;
            var                 testNameIsImmediate = string.Equals(testName, nameof(phaseSets.Immediate));
            var                 encodingRequired    = !_encodingFinishedChecker.IsFinished(participantID);

            if (encodingRequired)
            {
                action = ReturningUserAction.NewUser;
            }
            else if (testName == default)
            {
                action = ReturningUserAction.Done;
            }
            else
            {
                var      nextTestStartTime = _testStartTimeGetter.GetUtc(participantID);
                DateTime utcNow            = DateTime.UtcNow;
                bool     mustWait          = nextTestStartTime.Start > utcNow;
                bool     tooLate           = nextTestStartTime.End < utcNow;
                if (mustWait)
                {
                    action          = ReturningUserAction.Wait;
                    nextTestWhenUtc = nextTestStartTime.Start;
                }
                else if (tooLate)
                {
                    action = ReturningUserAction.TooLate;
                }
                else
                {
                    action = ReturningUserAction.Test;
                }
            }
            var result = new ReturningUserPhaseData(action, progress, testName, nextTestWhenUtc);

            return(result);
        }