Ejemplo n.º 1
0
        public async Task SignInAsVolunteer(string surveyName, string linkId, string participantEmail, int participantId)
        {
            var linkModel = new SurveyLinkModel()
            {
                LinkId           = linkId,
                SurveyName       = surveyName,
                ParticipantId    = participantId,
                ParticipantEmail = participantEmail
            };

            var manager = ManagerFactory.CreateSurveyLinkManager();
            await manager.SaveSurveyLink(linkModel);


            var verifyLinkIdModel = new VerifyLinkIdModel()
            {
                LinkId = linkModel.LinkId
            };
            var content = JsonConvert.SerializeObject(verifyLinkIdModel);

            var request = new HttpRequestMessage
            {
                Method     = HttpMethod.Post,
                RequestUri = new Uri("Cookie/VerifyLinkId", UriKind.Relative),
                Content    = new StringContent(content, Encoding.UTF8, "application/json")
            };


            var response = await HttpClient.SendAsync(request);

            response.EnsureSuccessStatusCode();
        }
Ejemplo n.º 2
0
        public async Task SendLink(SurveyLinkModel link, string baseUrl)
        {
            await SaveSurveyLink(link);


            //Send emails here?
            var actionUrl  = "/surveyrunner/index?id=";
            var surveyLink = baseUrl + actionUrl + link.LinkId;

            //TODO: Create and send email?
            var mailHelper = new MailHelper();

            var mailSubject = "Some not-so-random subject here";
            var mailBody    = $"Some text and then a link: {surveyLink}";

            mailHelper.SendMail(link.ParticipantEmail, mailSubject, mailBody);
        }
Ejemplo n.º 3
0
        public async Task CookieController_VerifyLinkIdThatExists_CookieIsReturned()
        {
            var participantEmail = "*****@*****.**";
            var id         = 1;
            var surveyName = "TestSurvey";


            var linkModel = new SurveyLinkModel()
            {
                SurveyName       = surveyName,
                ParticipantId    = id,
                ParticipantEmail = participantEmail
            };

            var linkId = linkModel.LinkId;


            var linkManager = _fixture.ManagerFactory.CreateSurveyLinkManager();
            await linkManager.SaveSurveyLink(linkModel);


            var verifyLinkIdModel = new VerifyLinkIdModel()
            {
                LinkId = linkId
            };
            var content = JsonConvert.SerializeObject(verifyLinkIdModel);

            var request = new HttpRequestMessage
            {
                Method     = HttpMethod.Post,
                RequestUri = new Uri("Cookie/VerifyLinkId", UriKind.Relative),
                Content    = new StringContent(content, Encoding.UTF8, "application/json")
            };

            var response = await _fixture.HttpClient.SendAsync(request);


            response.Headers.TryGetValues("Set-Cookie", out var newCookies);
            var cookieList = newCookies.ToList();

            Assert.Single(cookieList);
            Assert.Contains("auth_cookie", cookieList.First());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> StartSession(int studyId, string sessionName)
        {
            var sessionManager    = _context.ManagerFactory.CreateSessionManager();
            var externalDbManager = _context.ManagerFactory.CreateExternalDbManager();
            var surveyLinkManager = _context.ManagerFactory.CreateSurveyLinkManager();

            var studySessionModel = sessionManager.GetStudySession(studyId, sessionName).Result;

            var id = studySessionModel.Id;

            var userSessions = await sessionManager.GetAllUserSessionsForStudySession(id);

            var participants = externalDbManager.GetParticipantInfo(studyId);

            foreach (var survey in studySessionModel.Surveys)
            {
                foreach (var session in userSessions)
                {
                    //Create surveylink wih a reference to UserSessions ObjectId

                    var participantId   = session.ParticipantId;
                    var participantInfo = participants.FirstOrDefault(x => x.ParticipantId == participantId);

                    var baseUrl = BaseUrlHelper.GetBaseUrl(Request);

                    var link = new SurveyLinkModel
                    {
                        ParticipantId    = participantInfo.ParticipantId,
                        ParticipantEmail = participantInfo.Email,
                        SurveyName       = survey,
                        UserSessionId    = session.Id
                    };

                    await surveyLinkManager.SendLink(link, baseUrl);
                }
            }

            await sessionManager.SetStudySessionStarted(studyId, sessionName);

            return(RedirectToAction("AllStudies", "Study"));
        }
Ejemplo n.º 5
0
        public async Task SaveSurveyLink(SurveyLinkModel surveyLink)
        {
            var surveyCollection = _db.GetCollection <SurveyLinkModel>("surveyLink_collection");

            await surveyCollection.InsertOneAsync(surveyLink);
        }