Пример #1
0
        public ActionResult Assignment2(string submitanswer, string answereverified, string newpractise, Assignment2ViewModel viewModel)
        {
            Assignment2DataAccess dataAccess = new Assignment2DataAccess(RavenSession);
            MathPractice exam = dataAccess.RetrieveFromSession();
            Question currentQuestion = exam.CurrentQuestion;

            if(exam != null && currentQuestion == null && string.IsNullOrEmpty(newpractise))
            {
                ModelState.Clear();
                viewModel.InjectFrom(exam);
                viewModel.Done = true;
            }
            else if(!string.IsNullOrEmpty(submitanswer))
            {
                int result;
                int.TryParse(viewModel.Answer, out result);
                currentQuestion.Answer = result;

                if(currentQuestion.Answer == currentQuestion.Solution)
                {
                    currentQuestion = exam.CurrentQuestion;

                    if(currentQuestion != null)
                    {
                        viewModel.InjectFrom(exam, currentQuestion);
                        ModelState.Remove("Answer");
                        viewModel.Answer = string.Empty;
                        viewModel.AnswereVerified = true;
                    }
                    else
                    {
                        ModelState.Clear();
                        viewModel.InjectFrom(exam);
                        viewModel.Done = true;
                    }
                }
                else
                {
                    viewModel.InjectFrom(exam, currentQuestion);
                    viewModel.AnswereVerified = false;
                }
            }
            else if(!string.IsNullOrEmpty(answereverified))
            {
                currentQuestion = exam.CurrentQuestion;

                if(currentQuestion != null)
                {
                    viewModel.InjectFrom(exam, currentQuestion);
                    ModelState.Remove("Answer");
                    viewModel.Answer = string.Empty;
                    viewModel.AnswereVerified = true;
                }
                else
                {
                    ModelState.Clear();
                    viewModel.InjectFrom(exam);
                    viewModel.Done = true;
                }
            }
            else if(!string.IsNullOrEmpty(newpractise))
            {
                ModelState.Clear();
                exam = dataAccess.CreateNewSession();
                currentQuestion = exam.CurrentQuestion;
                viewModel.InjectFrom(exam, currentQuestion);
                viewModel.Answer = string.Empty;
            }

            return View("Assignment2", viewModel);
        }
Пример #2
0
        //
        // GET: /Assignments/Assignment2
        public ActionResult Assignment2()
        {
            //Initialize Data Model
            Assignment2DataAccess dataAccess = new Assignment2DataAccess(RavenSession);

            //Retrieve quiz from the database
            MathPractice exam = dataAccess.RetrieveFromSession();
            Question currentQuestion = exam.CurrentQuestion;

            //Initialize View Model
            Assignment2ViewModel viewModel = new Assignment2ViewModel();

            if(currentQuestion != null)
            {
                //Use Object mapper to map Data Model to View Model
                viewModel.InjectFrom(exam, currentQuestion);
                viewModel.Answer = string.Empty;
            }
            else
            {
                viewModel.InjectFrom(exam);
                viewModel.Done = true;
            }

            return View("Assignment2", viewModel);
        }