Esempio n. 1
0
        QuestionViewModels CreateQuestion2Lists(List <object> values)
        {
            QuestionViewModels obj = new QuestionViewModels();

            foreach (var item in values)
            {
                obj.Questions.Add(ConvertToQuestion2(item));
            }
            return(obj);
        }
Esempio n. 2
0
        private void DeleteVM(QuestionViewModel obj)
        {
            var indexOf = QuestionViewModels.IndexOf(obj);

            QuestionViewModels.Remove(obj);
            EntityViewModel.QuestionViewModels.Remove(obj);
            for (int i = indexOf; i < QuestionViewModels.Count; i++)
            {
                QuestionViewModels[i].Order = i + 1;
            }
            Deleted.Add(obj);
        }
Esempio n. 3
0
        /// <summary>
        /// Saves the answer for the current question
        /// </summary>
        /// <param name="answer">The answer itself</param>
        public void SaveAnswer(Answer answer)
        {
            // Save the answer
            UserAnswers.Add(answer);

            DI.Logger.Log($"User answer saved for question nr {CurrentQuestionString}.");

            // Create view data from the results page if it is allowed to be shown
            if (AreResultsAllowed)
            {
                QuestionViewModels.Add(Questions[mCurrentQuestion - 1].ToViewModel(answer, QuestionViewModels.Count));
            }
        }
Esempio n. 4
0
        public ActionResult Create(QuestionViewModels model)
        {
            var question = new Question()
            {
                Id         = Guid.NewGuid(),
                Title      = model.Title,
                Content    = model.Content,
                CreateDate = model.CreateDate,
                CreateBy   = User.Identity.GetUserName(),
                Status     = true,
            };
            var result = _questionService.Create(question);

            if (result == true)
            {
                return(RedirectToAction("Index"));
            }
            return(View());
        }
Esempio n. 5
0
        // GET: Quiz
        //PlayArena: In that momemnt you click a level in a specific room.
        //UserID = ID number in AspnetUser
        //x (models.Question). It is main question (question.id) and its possible answers. Loops 10 times. It orders the id of the questions!
        //The player_status is based on the specifik room on a specific level. Afterwards finding that player and adding it in the table!
        //57: For each questions (10) populating them and its answers in the viewmodel.
        //Getting the 10 questions by giving a levelID. Afterwards populating the data in the viewModels! If questions is empty, then generate 10 random questions.
        //Linie 43 if 10 keep going or empty generate!
        //Creating a player_status. Populating level,room as objects and get a specific room_level_id (info).
        //If the list of questions are empty then it should generate random-questions (loading the page for first time), if not then we keep the questions until the user is finished (loading for second time).
        // Linie 48: It retrieves the already generated questions which are not finished yet and then ordering the questions by their ID's. We save them as well for resuming the game.
        //Populating the viewmodel properties withe question and answers --> because of validating the correct ID's
        //Players are connected on (same level id and roomID) = same questions.
        public ActionResult Index(int levelID, int roomID)
        {
            int             userID = int.Parse(User.Identity.GetUserId());
            List <Question> question;


            question = questionLogic.playerQuestion(roomID, levelID);
            if (question.Count == 0)
            {
                question = questionLogic.Get10Questions(levelID);
                questionLogic.savePlayerUnfinishedQuiz(question, levelID, roomID);
            }
            question = question.OrderBy(x => x.ID).ToList();

            QuizViewModel viewModel = new QuizViewModel();

            viewModel.LevelID = levelID;
            viewModel.RoomID  = roomID;

            viewModel.questions = new List <QuestionViewModels>();

            foreach (var item in question)
            {
                QuestionViewModels questionViewModel = new QuestionViewModels();
                questionViewModel.QuestionID    = item.ID;
                questionViewModel.QuestionTitle = item.Title;
                questionViewModel.Answers       = new List <AnswerViewModel>();

                foreach (var answers in item.Answers)
                {
                    AnswerViewModel answerViewModel = new AnswerViewModel();
                    answerViewModel.AnswerText = answers.AnswerText;
                    answerViewModel.ID         = answers.ID;


                    questionViewModel.Answers.Add(answerViewModel);
                }

                viewModel.questions.Add(questionViewModel);
            }
            return(View(viewModel));
        }
Esempio n. 6
0
        private async void GetQuestions()
        {
            var items = await _client.GetAll(EntityViewModel.Id);

            QuestionViewModels.CopyFrom(items.OrderBy(el => el.Order).ToList());
        }