コード例 #1
0
        private static string GetAreaOfNonCompliance(QuestionAnswerViewModel question, QuestionResponseViewModel selectedResponse)
        {
            if (string.IsNullOrEmpty(question.Answer.AreaOfNonCompliance)){
              return  !string.IsNullOrEmpty(selectedResponse.ReportLetterStatement) ? selectedResponse.ReportLetterStatement : question.Question.Text;
            }

            return question.Answer.AreaOfNonCompliance;
        }
コード例 #2
0
        // Pass in view model and integer to create method
        public async Task <IActionResult> Create(QuestionResponseViewModel viewModel, int Id)
        {
            // Create instance of a test based on Id passed into create method
            Test test = await _context.Test.FirstOrDefaultAsync(t => t.TestId == Id);

            var currentUser = await GetCurrentUserAsync();

            // Create new instance of a UserTest called NewUserTest
            var NewUserTest = new UserTest()
            {
                // Provide NewUserTest with necessary values
                TestId = test.TestId,
                UserId = currentUser.Id
            };

            // Add NewUserTest to UserTests in database
            _context.Add(NewUserTest);

            ModelState.Remove($"UserTest.User");
            ModelState.Remove($"UserTest.UserId");

            // Check if model state is valid
            if (ModelState.IsValid)
            {
                // Create iterator based on number of Responses in view model
                for (var i = 0; i < viewModel.Responses.Count; i++)
                {
                    // Give the value of NewUserTest to every instance of UserTest within the list of Responses in the view model
                    viewModel.Responses[i].UserTest = NewUserTest;
                    // Give the value of current user to every instance of User within the list of Responses in the view model
                    // Add the iterated list of Responses to the database
                    _context.Add(viewModel.Responses[i]);
                }
                // Save changes to the database
                await _context.SaveChangesAsync();

                // Redirect to Details view with id value of UserTestId in the NewUserTest
                return(RedirectToAction(nameof(Details), new { id = NewUserTest.UserTestId }));
            }

            // Return view model
            return(View(viewModel));
        }
コード例 #3
0
        // GET: Tests/Create
        public async Task <IActionResult> Create(int Id)
        {
            // Create instance of a test based on Id passed into create method
            Test test = await _context.Test.FirstOrDefaultAsync(t => t.TestId == Id);

            // Create list of questions with value of Questions in database where Question.TestId equals test.TestId
            List <Question> questions = await _context.Question.Where(q => q.TestId == test.TestId).ToListAsync();

            // Create instance of QuestionResponseViewModel
            QuestionResponseViewModel viewModel = new QuestionResponseViewModel();

            // Give the value of "questions" to the Questions list in the view model
            viewModel.Questions = questions;
            // Give the value of "test" to the Test instance in the view model
            viewModel.Test = test;

            // return the view model
            return(View(viewModel));
        }
        private ComplianceReviewItemStatus? ComplianceReviewItemStatus(QuestionResponseViewModel response)
        {
            if (response == null)
            {
                return null;
            }
            switch (response.Title)
            {
                default:
                case "Acceptable":
                case "Not Applicable":
                    return Models.ComplianceReviewItemStatus.Satisfactory;
                    break;

                case "Unacceptable":
                    return Models.ComplianceReviewItemStatus.ImmediateActionRequired;                   
                    break;

                case "Improvement Required":
                    return Models.ComplianceReviewItemStatus.FurtherActionRequired;                  
                    break;
            }
        }
        /// <summary>
        /// create a question with 3 responses
        /// </summary>
        /// <param name="ResponseType">the selected answer</param>
        /// <returns></returns>
        private static QuestionAnswerViewModel CreateQuestionAnswerViewModel( int ResponseType )
        {
            QuestionAnswerViewModel qaViewModel = new QuestionAnswerViewModel();

            Guid categoryId = new Guid();
            qaViewModel.Question = new QuestionViewModel()
            {
                Id = Guid.NewGuid(),
                Text = "QuestionText",
                PossibleResponses = new List<QuestionResponseViewModel>(),
                Mandatory = false,
                SpecificToClientId = (long)1234,
                Category = new CategoryViewModel()
                               {
                                   Id = categoryId,
                                   Title = "TestCategory"
                               },
                CategoryId = categoryId
            };

            QuestionResponseViewModel qrAcceptableViewModel = new QuestionResponseViewModel()
            {
                Id = Guid.NewGuid(),
                Title = "Acceptable",
                SupportingEvidence = "Acceptable supporting evidence",
                ActionRequired = "Acceptable action required",
                ResponseType = "Positive",
                GuidanceNotes = "Acceptable guidance notes",ReportLetterStatement = "acceptable letter statement"
            };

            QuestionResponseViewModel qrUnacceptableViewModel = new QuestionResponseViewModel()
            {
                Id = Guid.NewGuid(),
                Title = "Unacceptable",
                SupportingEvidence = "Unacceptable supporting evidence",
                ActionRequired = "Unacceptable action required",
                ResponseType = "Negative",
                GuidanceNotes = "Unacceptable guidance notes",ReportLetterStatement = "unacceptable letter statement"
            };

            QuestionResponseViewModel qrImprovementRequiredViewModel = new QuestionResponseViewModel()
            {
                Id = Guid.NewGuid(),
                Title = "Improvement Required",
                SupportingEvidence = "Improvement Required supporting evidence",
                ActionRequired = "Improvement Required action required",
                ResponseType = "Neutral",
                GuidanceNotes = "Improvement Required guidance notes"
            };

            QuestionResponseViewModel qrNotApplicableRequiredViewModel = new QuestionResponseViewModel()
            {
                Id = Guid.NewGuid(),
                Title = "Not Applicable",
                SupportingEvidence = "Not Applicable supporting evidence",
                ActionRequired = "Not Applicable Required action required",
                ResponseType = "Neutral",
                GuidanceNotes = "Not Applicable guidance notes",
                ReportLetterStatement = "not applicable letter statement"
            };

            qaViewModel.Question.PossibleResponses.Add(qrAcceptableViewModel);
            qaViewModel.Question.PossibleResponses.Add(qrUnacceptableViewModel);
            qaViewModel.Question.PossibleResponses.Add(qrImprovementRequiredViewModel);
            qaViewModel.Question.PossibleResponses.Add(qrNotApplicableRequiredViewModel);

            qaViewModel.Answer = new AnswerViewModel()
            {
                SupportingEvidence = "Answer supporting evidence",
                ActionRequired = "Answer action required",
                GuidanceNotes = "Answer guidance notes",
                Timescale = new TimescaleViewModel()
                {
                    Id = 1234,
                    Name = "This Week"
                },
                AssignedTo = new AssignedToViewModel()
                {
                    Id = Guid.NewGuid(),
                    NonEmployeeName = "Bob Roberts"
                },
                QuestionId = Guid.NewGuid()
            };

            switch( ResponseType )
            {
                case ACCEPTABLE_RESPONSE:
                    qaViewModel.Answer.SelectedResponseId = qrAcceptableViewModel.Id;
                    break;

                case UNACCEPTABLE_RESPONSE:
                    qaViewModel.Answer.SelectedResponseId = qrUnacceptableViewModel.Id;
                    break;

                case IMPROVEMENT_REQUIRED_RESPONSE:
                    qaViewModel.Answer.SelectedResponseId = qrImprovementRequiredViewModel.Id;
                    break;

                case NOT_APPLICABLE_RESPONSE:
                    qaViewModel.Answer.SelectedResponseId = qrNotApplicableRequiredViewModel.Id;
                    break;
            }

            return qaViewModel;
        }