Esempio n. 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
            {
                SpiritualGiftsService.AssessmentResults result = SpiritualGiftsService.GetResult(_assessmentResponses.ToDictionary(a => a.Code, b => b.Response.Value));
                SpiritualGiftsService.SaveAssessmentResults(_targetPerson, result);
                var resultData  = _assessmentResponses.ToDictionary(a => a.Code, b => b.Response.Value);
                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.GIFTS.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 = resultData, TimeToTake = RockDateTime.Now.Subtract(StartDateTime).TotalSeconds }.ToJson();
                rockContext.SaveChanges();

                ShowResult(result, assessment);
            }
        }
Esempio n. 2
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();
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            /*
             * 2019-12-09 - ED
             * This activity will create a new assessment for each assessment type selected. If an assessment already exists for that type it is left in a pending status but a new assessment is still created.
             * Per Jon, code in Rock should account for the possibility of multiple assessments for a type that are in a pending state and only select the latest one.
             */

            rockContext = rockContext ?? new RockContext();

            errorMessages = new List <string>();

            var assessmentTypesGuidString = GetAttributeValue(action, AttributeKey.AssessmentTypesKey, true);
            var assessmentTypeGuids       = assessmentTypesGuidString.IsNullOrWhiteSpace() ? null : assessmentTypesGuidString.Split(new char[] { ',' });

            var  personAliasGuid      = GetAttributeValue(action, AttributeKey.Person, true).AsGuidOrNull();
            Guid?requestedByAliasGuid = GetAttributeValue(action, AttributeKey.RequestedBy, true).AsGuidOrNull();
            var  dueDate = GetAttributeValue(action, AttributeKey.DueDate, true).AsDateTime();

            // Validate attribute data
            if (!assessmentTypeGuids.Any())
            {
                errorMessages.Add("No Assessments selected.");
                return(false);
            }

            if (personAliasGuid == null)
            {
                errorMessages.Add("Invalid Person Attribute or Value.");
                return(false);
            }

            var personAlias = new PersonAliasService(rockContext).Get(personAliasGuid.Value);

            if (personAlias == null)
            {
                errorMessages.Add("Invalid Person Attribute or Value.");
                return(false);
            }

            var requestedByAlias = new PersonAliasService(rockContext).Get(requestedByAliasGuid.Value);

            foreach (string assessmentTypeGuid in assessmentTypeGuids)
            {
                var assessmentTypeService = new AssessmentTypeService(rockContext);
                int?assessmentTypeId      = assessmentTypeService.GetId(assessmentTypeGuid.AsGuid());

                if (assessmentTypeId == null)
                {
                    // This really shouldn't be able to happen, but let's not risk an NRE.
                    errorMessages.Add($"Invalid Assessment Type: {assessmentTypeGuid}");
                    continue;
                }

                // Create a new assessment
                var assessment = new Assessment
                {
                    PersonAliasId          = personAlias.Id,
                    AssessmentTypeId       = assessmentTypeId.Value,
                    RequesterPersonAliasId = requestedByAlias.Id,
                    RequestedDateTime      = RockDateTime.Now,
                    RequestedDueDate       = dueDate,
                    Status = AssessmentRequestStatus.Pending
                };

                var assessmentService = new AssessmentService(rockContext);
                assessmentService.Add(assessment);
                rockContext.SaveChanges();
            }

            return(true);
        }
Esempio n. 4
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 => !string.IsNullOrEmpty(a.MostScore) && !string.IsNullOrEmpty(a.LeastScore))) || "Next".Equals(commandArgument))
            {
                BindRepeater(pageNumber);
            }
            else
            {
                try
                {
                    var moreD = _assessmentResponses.Where(a => a.MostScore == "D").Count();
                    var moreI = _assessmentResponses.Where(a => a.MostScore == "I").Count();
                    var moreS = _assessmentResponses.Where(a => a.MostScore == "S").Count();
                    var moreC = _assessmentResponses.Where(a => a.MostScore == "C").Count();
                    var lessD = _assessmentResponses.Where(a => a.LeastScore == "D").Count();
                    var lessI = _assessmentResponses.Where(a => a.LeastScore == "I").Count();
                    var lessS = _assessmentResponses.Where(a => a.LeastScore == "S").Count();
                    var lessC = _assessmentResponses.Where(a => a.LeastScore == "C").Count();

                    // Score the responses and return the results
                    DiscService.AssessmentResults results = DiscService.Score(moreD, moreI, moreS, moreC, lessD, lessI, lessS, lessC);

                    // Now save the results for this person
                    DiscService.SaveAssessmentResults(
                        _targetPerson,
                        results.AdaptiveBehaviorD.ToString(),
                        results.AdaptiveBehaviorI.ToString(),
                        results.AdaptiveBehaviorS.ToString(),
                        results.AdaptiveBehaviorC.ToString(),
                        results.NaturalBehaviorD.ToString(),
                        results.NaturalBehaviorI.ToString(),
                        results.NaturalBehaviorS.ToString(),
                        results.NaturalBehaviorC.ToString(),
                        results.PersonalityType);

                    var assessmentData = _assessmentResponses.ToDictionary(a => a.QuestionNumber, b => new { Most = new string[2] {
                                                                                                                 b.MostScore, b.Questions[b.MostScore]
                                                                                                             }, Least = new string[2] {
                                                                                                                 b.LeastScore, b.Questions[b.LeastScore]
                                                                                                             } });
                    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.DISC.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 = assessmentData, TimeToTake = RockDateTime.Now.Subtract(StartDateTime).TotalSeconds }.ToJson();
                    rockContext.SaveChanges();

                    ShowResult(results, assessment);
                }
                catch (Exception ex)
                {
                    nbError.Visible = true;
                    nbError.Title   = "We're Sorry...";
                    nbError.Text    = "Something went wrong while trying to save your test results.";
                    LogException(ex);
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            rockContext = rockContext ?? new RockContext();

            errorMessages = new List <string>();

            var assessmentTypesGuidString = GetAttributeValue(action, AttributeKey.AssessmentTypesKey, true);
            var assessmentTypeGuids       = assessmentTypesGuidString.IsNullOrWhiteSpace() ? null : assessmentTypesGuidString.Split(new char[] { ',' });

            var  personAliasGuid      = GetAttributeValue(action, AttributeKey.Person, true).AsGuidOrNull();
            Guid?requestedByAliasGuid = GetAttributeValue(action, AttributeKey.RequestedBy, true).AsGuidOrNull();
            var  dueDate = GetAttributeValue(action, AttributeKey.DueDate, true).AsDateTime();

            // Validate attribute data
            if (!assessmentTypeGuids.Any())
            {
                errorMessages.Add("No Assessments selected.");
                return(false);
            }

            if (personAliasGuid == null)
            {
                errorMessages.Add("Invalid Person Attribute or Value.");
                return(false);
            }

            var personAlias = new PersonAliasService(rockContext).Get(personAliasGuid.Value);

            if (personAlias == null)
            {
                errorMessages.Add("Invalid Person Attribute or Value.");
                return(false);
            }

            var requestedByAlias = new PersonAliasService(rockContext).Get(requestedByAliasGuid.Value);

            foreach (string assessmentTypeGuid in assessmentTypeGuids)
            {
                // Check for an existing record
                var assessmentTypeService = new AssessmentTypeService(rockContext);
                int?assessmentTypeId      = assessmentTypeService.GetId(assessmentTypeGuid.AsGuid());

                var assessmentService  = new AssessmentService(rockContext);
                var existingAssessment = assessmentService
                                         .Queryable()
                                         .Where(a => a.PersonAliasId == personAlias.Id)
                                         .Where(a => a.AssessmentTypeId == assessmentTypeId)
                                         .Where(a => a.Status == AssessmentRequestStatus.Pending)
                                         .FirstOrDefault();

                // If a pending record for this person/type is found mark it complete.
                if (existingAssessment != null)
                {
                    existingAssessment.Status = AssessmentRequestStatus.Complete;
                }

                // Create a new assessment
                var assessment = new Assessment
                {
                    PersonAliasId          = personAlias.Id,
                    AssessmentTypeId       = assessmentTypeId.Value,
                    RequesterPersonAliasId = requestedByAlias.Id,
                    RequestedDateTime      = RockDateTime.Now,
                    RequestedDueDate       = dueDate,
                    Status = AssessmentRequestStatus.Pending
                };

                assessmentService.Add(assessment);
                rockContext.SaveChanges();
            }

            return(true);
        }