Beispiel #1
0
        /// <summary>
        /// Handles the Click event of the btnNext control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnNext_Click(object sender, EventArgs e)
        {
            int pageNumber = hfPageNo.ValueAsInt() + 1;

            GetResponse();

            LinkButton btn             = ( LinkButton )sender;
            string     commandArgument = btn.CommandArgument;

            var totalQuestion = pageNumber * QuestionCount;

            if ((_assessmentResponses.Count > totalQuestion && !_assessmentResponses.All(a => a.Response.HasValue)) || "Next".Equals(commandArgument))
            {
                BindRepeater(pageNumber);
            }
            else
            {
                MotivatorService.AssessmentResults result = MotivatorService.GetResult(_assessmentResponses.ToDictionary(a => a.Code, b => b.Response.Value));
                MotivatorService.SaveAssessmentResults(_targetPerson, result);
                var rockContext = new RockContext();

                var        assessmentService = new AssessmentService(rockContext);
                Assessment assessment        = null;

                if (hfAssessmentId.ValueAsInt() != 0)
                {
                    assessment = assessmentService.Get(int.Parse(hfAssessmentId.Value));
                }

                if (assessment == null)
                {
                    var assessmentType = new AssessmentTypeService(rockContext).Get(Rock.SystemGuid.AssessmentType.MOTIVATORS.AsGuid());
                    assessment = new Assessment()
                    {
                        AssessmentTypeId = assessmentType.Id,
                        PersonAliasId    = _targetPerson.PrimaryAliasId.Value
                    };
                    assessmentService.Add(assessment);
                }

                assessment.Status               = AssessmentRequestStatus.Complete;
                assessment.CompletedDateTime    = RockDateTime.Now;
                assessment.AssessmentResultData = new { Result = result.AssessmentData, TimeToTake = RockDateTime.Now.Subtract(StartDateTime).TotalSeconds }.ToJson();
                rockContext.SaveChanges();

                // Since we are rendering chart.js we have to register the script or reload the page.
                if (_assessmentId == 0)
                {
                    var removeParams = new List <string>
                    {
                        PageParameterKey.AssessmentId
                    };

                    NavigateToCurrentPageReferenceWithRemove(removeParams);
                }
                else
                {
                    this.NavigateToCurrentPageReference();
                }
            }
        }