public JsonResult PostResult([FromBody] PostSurveyResultModel model)
        {
            SurveyResultLog surveyLog = new SurveyResultLog();
            int             clientid  = Convert.ToInt32(HttpContext.Session.GetString("Clientid"));
            var             db        = new Dao(HttpContext.Session);

            db.PostResults(model.postId, model.surveyResult, clientid);
            return(Json("Ok"));
        }
        public async Task <JsonResult> PostResult([FromBody] PostSurveyResultModel model)
        {
            //Get users role
            var usersRoleString = HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Role && x.Type != null).Value;

            Enum.TryParse(usersRoleString, out Role usersRole);

            //Only post results if users is a volunteer
            if (usersRole == Role.Volunteer)
            {
                //Get ids from cookie!
                var participantId = HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier && x.Type != null).Value;
                var linkId        = HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Uri && x.Type != null).Value;


                //Get link model
                var linkManager = _context.ManagerFactory.CreateSurveyLinkManager();
                var linkModel   = await linkManager.GetLink(linkId);

                var result = new SurveyResult
                {
                    SurveyName    = model.PostId,
                    JsonResult    = model.SurveyResult,
                    ParticipantId = int.Parse(participantId),
                    TimeStamp     = DateTime.Now,
                    UserSessionId = linkModel.UserSessionId
                };

                //Save result to DB
                var surveyManager = _context.ManagerFactory.CreateSurveyManager();
                await surveyManager.SaveSurveyResult(result);

                //This kills the cookie
                await HttpContext.SignOutAsync();

                //Delete link from DB
                await linkManager.DeleteLink(linkId);
            }

            return(Json("Ok"));
        }
Exemple #3
0
        public async Task SurveyRunnerController_PostResults_ResultsAreSavedSurveyLinkIsDeleted()
        {
            var linkId           = "LinkId";
            var participantEmail = "*****@*****.**";
            var participantId    = 1;
            var surveyName       = "TestSurvey";

            var result      = "{}";
            var resultModel = new PostSurveyResultModel {
                PostId = surveyName, SurveyResult = result
            };
            var jsonContent = JsonConvert.SerializeObject(resultModel);

            await _fixture.SignInAsVolunteer(surveyName, linkId, participantEmail, participantId);


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

            var response = await _fixture.HttpClient.SendAsyncWithCookie(request, "VerifyLinkId");

            var surveyLink = await _fixture.ManagerFactory.CreateSurveyLinkManager().GetLink(linkId);

            var surveyResult = await _fixture.ManagerFactory.CreateSurveyManager().GetResults(surveyName);


            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Null(surveyLink);
            Assert.NotNull(surveyResult);
            Assert.Single(surveyResult);
            Assert.Contains(result, surveyResult);
        }
 public IActionResult SurveyFromBody([FromBody] PostSurveyResultModel model)
 {
     return(Json(new { Id = "123" }));
 }
Exemple #5
0
 public IActionResult OnPost([FromBody] PostSurveyResultModel model)
 {
     return(new JsonResult(new { Id = 123 }));
 }