Ejemplo n.º 1
0
        public async Task <IActionResult> EditQuestion(EditQuestionViewModel model)
        {
            if (ModelState.IsValid)
            {
                Question quest = await db.Questions.Include("Variants").FirstOrDefaultAsync(t => t.Id == model.Id);

                if (quest != null)
                {
                    quest.Type = model.Type;
                    quest.Text = model.Text;
                    quest.Variants[0].QuestionId = model.Id;
                    quest.Variants[0].Text       = model.Var1;
                    quest.Variants[0].IsCorrect  = model.Var1IsCorrect;
                    quest.Variants[1].QuestionId = model.Id;
                    quest.Variants[1].Text       = model.Var2;
                    quest.Variants[1].IsCorrect  = model.Var2IsCorrect;
                    quest.Variants[2].QuestionId = model.Id;
                    quest.Variants[2].Text       = model.Var3;
                    quest.Variants[2].IsCorrect  = model.Var3IsCorrect;
                    quest.Variants[3].QuestionId = model.Id;
                    quest.Variants[3].Text       = model.Var4;
                    quest.Variants[3].IsCorrect  = model.Var4IsCorrect;
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Questions", new { id = model.TestId }));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Нет такого вопроса в базе, возможно он был удалён");
                }
            }
            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> EditQuestion(int id)
        {
            Question quest = await db.Questions.Include("Variants").FirstOrDefaultAsync(q => q.Id == id);

            if (quest == null)
            {
                return(Content("Нет записи с таким Id"));
            }
            EditQuestionViewModel model = new EditQuestionViewModel
            {
                Id            = quest.Id,
                TestId        = quest.TestId,
                Type          = quest.Type,
                Text          = quest.Text,
                Var1Id        = quest.Variants[0].Id,
                Var1          = quest.Variants[0].Text,
                Var1IsCorrect = quest.Variants[0].IsCorrect,
                Var2Id        = quest.Variants[1].Id,
                Var2          = quest.Variants[1].Text,
                Var2IsCorrect = quest.Variants[1].IsCorrect,
                Var3Id        = quest.Variants[2].Id,
                Var3          = quest.Variants[2].Text,
                Var3IsCorrect = quest.Variants[2].IsCorrect,
                Var4Id        = quest.Variants[3].Id,
                Var4          = quest.Variants[3].Text,
                Var4IsCorrect = quest.Variants[3].IsCorrect
            };

            return(View(model));
        }
Ejemplo n.º 3
0
        public IActionResult Create()
        {
            var model = new EditQuestionViewModel();

            AddReferenceDataToModel(model);
            return(View(model));
        }
Ejemplo n.º 4
0
        public IActionResult SaveNewCreate(EditQuestionViewModel model)
        {
            // Traitement pour sauvegarder les questions

            //transformer le viewModel en une entité Question
            var question = new Question
            {
                Category = new QuestionCategory {
                    Id = model.CategoryId
                },                                                         //
                Content    = model.Content,
                Difficulty = new QuestionDifficulty {
                    Id = model.DifficultyId
                },
                Type = new QuestionType {
                    Id = model.TypeId
                }
            };

            var questionId = _questionDao.CreateQuestion(question);

            if (questionId > 0)
            {
                Success = "La creation a bien ete effectuee";
                return(RedirectToAction(nameof(Create)));
            }


            return(View("Details", "QuestionViewModel"));
        }
Ejemplo n.º 5
0
        public EditQuestionViewModel GetEditQuestionViewModel(EditQuestionBindingModel model)
        {
            EditQuestionViewModel viewModel = Mapper.Instance
                                              .Map <EditQuestionBindingModel, EditQuestionViewModel>(model);

            return(viewModel);
        }
Ejemplo n.º 6
0
        public EditQuestionViewModel GetEditQuestionViewModel(int id)
        {
            Question question = this.GetQuestion(id);

            if (question == null)
            {
                throw new ArgumentNullException(nameof(id), "There is no Question with such Id.");
            }
            EditQuestionViewModel viewModel = new EditQuestionViewModel()
            {
                Id          = question.Id,
                Description = question.Description
            };

            Answer[] answers = question.Answers.ToArray();
            for (int i = 0; i < 3; i++)
            {
                if (answers[i].IsCorrect)
                {
                    viewModel.CorrectAnswer = i + 1;
                }
            }
            viewModel.AnswerOneId   = answers[0].Id;
            viewModel.OptionOne     = answers[0].Value;
            viewModel.AnswerTwoId   = answers[1].Id;
            viewModel.OptionTwo     = answers[1].Value;
            viewModel.AnswerThreeId = answers[2].Id;
            viewModel.OptionThree   = answers[2].Value;

            return(viewModel);
        }
Ejemplo n.º 7
0
        public ActionResult EditQuestion(int quizID, int ID)
        {
            EditQuestionViewModel model = new EditQuestionViewModel();

            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var quiz   = UserHasRights() ? QuizzesService.Instance.GetQuizForAdmin(quizID) : QuizzesService.Instance.GetUserQuiz(userId, quizID);

            if (quiz == null)
            {
                return(NotFound());
            }

            var question = QuestionsService.Instance.GetQuizQuestion(quizID, ID);

            if (question == null)
            {
                return(NotFound());
            }

            model.PageInfo = new PageInfo()
            {
                PageTitle       = "Modify Question",
                PageDescription = "Modify selected question."
            };

            model.ID             = question.ID;
            model.QuizID         = question.QuizID;
            model.QuizType       = quiz.QuizType;
            model.Title          = question.Title;
            model.CorrectOptions = question.Options.Where(q => q.IsCorrect).ToList();
            model.Options        = question.Options.Where(q => !q.IsCorrect).ToList();

            return(View(model));
        }
Ejemplo n.º 8
0
        private void AddReferenceDataToModel(EditQuestionViewModel model)
        {
            if (model == null)
            {
                model = new EditQuestionViewModel();
            }

            model.Categories = _categoryDao.GetAllQuestionCategory().Select(o => new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem
            {
                Text  = o.Name,
                Value = o.Id.ToString()
            });
            model.Difficulties = _difficultyDao.GetAll().Select(o => new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem
            {
                Text  = o.DifficultyLevel,
                Value = o.Id.ToString()
            });
            model.QuestionTypes = _questionTypeDao.GetAll().Select(o => new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem
            {
                Text  = o.Name,
                Value = o.Id.ToString()
            });
            model.Answers = _answerDao.GetAll().Select(o => new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem
            {
                Text  = o.Content,
                Value = o.Id.ToString()
            });
        }
Ejemplo n.º 9
0
        public PartialViewResult EditQuestion(AssessmentQuestionPrimaryKey assessmentQuestionPrimaryKey)
        {
            var question  = assessmentQuestionPrimaryKey.EntityObject;
            var viewModel = new EditQuestionViewModel(question);

            return(ViewEditQuestion(viewModel));
        }
Ejemplo n.º 10
0
        public IActionResult OnGet(int questionId)
        {
            EditQuestionViewModel = new EditQuestionViewModel();

            var question = _context.Questions.Include(x => x.Options).Include("Options.Image").Include(x => x.Image).FirstOrDefault(x => x.Id == questionId);

            if (question == null)
            {
                return(NotFound());
            }

            EditQuestionViewModel.ID             = question.Id;
            EditQuestionViewModel.QuizID         = question.QuizID;
            EditQuestionViewModel.Title          = question.Title;
            EditQuestionViewModel.Hours          = question.TimeDuration.Hours;
            EditQuestionViewModel.Minutes        = question.TimeDuration.Minutes;
            EditQuestionViewModel.Seconds        = question.TimeDuration.Seconds;
            EditQuestionViewModel.HasOptionsTime = question.HasOptionsDuration;
            EditQuestionViewModel.OptionHours    = question.OptionsTimeDuration.Hours;
            EditQuestionViewModel.OptionMinutes  = question.OptionsTimeDuration.Minutes;
            EditQuestionViewModel.OptionSeconds  = question.OptionsTimeDuration.Seconds;
            EditQuestionViewModel.ImagePath      = question.Image?.Name;
            //EditQuestionViewModel.CorrectOptions = question.Options.Where(q => q.IsCorrect).ToList();
            EditQuestionViewModel.Options = question.Options.ToList();

            return(Page());
        }
Ejemplo n.º 11
0
        public EditQuestion(AmericanQuestion q)
        {
            EditQuestionViewModel context = new EditQuestionViewModel(q);

            context.Pop        += () => Navigation.PopAsync();
            this.BindingContext = context;
            InitializeComponent();
        }
Ejemplo n.º 12
0
        public void UpdateQuestionDetails(EditQuestionViewModel editQuestionViewModel)
        {
            var      config   = new MapperConfiguration(cfg => { cfg.CreateMap <EditQuestionViewModel, Question>(); cfg.IgnoreUnmapped(); });
            IMapper  mapper   = config.CreateMapper();
            Question question = mapper.Map <EditQuestionViewModel, Question>(editQuestionViewModel);

            questionRepository.UpdateQuestionDetails(question);
        }
Ejemplo n.º 13
0
        public void UpdateQuestionDetails(EditQuestionViewModel qvm)
        {
            var      config = new MapperConfiguration(cfg => { cfg.CreateMap <EditQuestionViewModel, Question>(); cfg.IgnoreUnmapped(); });
            IMapper  mapper = config.CreateMapper();
            Question q      = mapper.Map <EditQuestionViewModel, Question>(qvm);

            qr.UpdateQuestionDetails(q);
        }
Ejemplo n.º 14
0
        public Question ToQuestionModel(EditQuestionViewModel vm)
        {
            var model = _questionService.Get(vm.Question.QuestionId);

            model.Text          = vm.Question.Text;
            model.EstimatedTime = vm.Question.EstimatedTime;
            model.Points        = vm.Question.Points;

            return(model);
        }
Ejemplo n.º 15
0
        public ActionResult EditQuestion(int id)
        {
            if (id < 1)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EditQuestionViewModel viewModel = this.service.GetEditQuestionViewModel(id);

            return(this.View(viewModel));
        }
Ejemplo n.º 16
0
        public static Question ToModel(this EditQuestionViewModel vm, IQuestionService questionService)
        {
            var model = questionService.Get(vm.Question.QuestionId);

            model.Text          = vm.Question.Text;
            model.EstimatedTime = vm.Question.EstimatedTime;
            model.Points        = vm.Question.Points;

            return(model);
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> Edit(EditQuestionViewModel viewModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(viewModel));
            }

            await this.questionsService.EditQuestionAsync(viewModel);

            return(this.RedirectToAction("Details", "Questions", new { id = viewModel.Id }));
        }
Ejemplo n.º 18
0
        public ActionResult Edit(int?id)
        {
            var question = _questionAppService.GetQuestion(new GetQuestionInput {
                Id = id.Value, IncrementViewCount = false
            }).Question;
            var model = new EditQuestionViewModel
            {
                Question = question
            };

            return(View(model));
        }
Ejemplo n.º 19
0
        public IActionResult EditQuestion(string id)
        {
            EditQuestionViewModel model = new EditQuestionViewModel();
            var currentQuestion         = _context.Questions.Where(q => q.Id == Convert.ToInt32(id)).First();

            model.AnswerOptions = currentQuestion.AnswerOptions;
            model.CorrectAnswer = currentQuestion.CorrectAnswer;
            model.Title         = currentQuestion.Text;
            model.Id            = currentQuestion.Id;
            model.TestId        = currentQuestion.TestId;
            return(View(model));
        }
Ejemplo n.º 20
0
        public ActionResult EditQuestion(
            [Bind(Include = "Id,Description,OptionOne,OptionTwo,OptionThree,CorrectAnswer,AnswerOneId,AnswerTwoId,AnswerThreeId")]
            EditQuestionBindingModel model)
        {
            if (this.ModelState.IsValid)
            {
                this.service.EditQuestion(model);
                return(this.RedirectToAction("PreviewQuestion", "Quizzes", new { area = "Admin", id = model.Id }));
            }
            EditQuestionViewModel viewModel = this.service.GetEditQuestionViewModel(model);

            return(this.View(viewModel));
        }
        private EditQuestionViewModel Map(Question entity)
        {
            var result = new EditQuestionViewModel
            {
                QuestionId = entity.Id,
                Text       = entity.Condition,
                Answers    = DbContext.PossibleAnswers
                             .Where(x => x.QuestionId == entity.Id).ToList()
                             .Select(x => Map(x)).ToList()
            };


            return(result);
        }
Ejemplo n.º 22
0
        public void EditQuestion_Post()
        {
            var c = _controllerProvider.CreateQuizzesController();
            EditQuestionViewModel model = _mockRepository.QuestionRepo.Get(1).ToEditQuestionViewModel(_mockRepository.AnswerService, _mockRepository.QuizService);

            model.Question.Text = "text";

            var result = c.EditQuestion(model) as PartialViewResult;

            model = result.Model as EditQuestionViewModel;

            Assert.IsNotNull(model);
            Assert.AreEqual("text", model.Question.Text);
        }
Ejemplo n.º 23
0
        public void EditQuestion_Post()
        {
            var c = ControllerProvider.CreateQuizzesController();
            EditQuestionViewModel model = Mocks.ModelConverter.ToEditQuestionViewModel(Mocks.QuestionRepo.Get(1));

            model.Question.Text = "text";

            var result = c.EditQuestion(model) as PartialViewResult;

            model = result.Model as EditQuestionViewModel;

            Assert.IsNotNull(model);
            Assert.AreEqual("text", model.Question.Text);
        }
Ejemplo n.º 24
0
        private EditQuestionViewModel GetEditTextQuestionViewModelFromFormCollection(EditQuestionViewModel model, IFormCollection collection)
        {
            model.Options        = new List <Option>();
            model.CorrectOptions = new List <Option>();

            if (collection.Keys.Count() > 0)
            {
                foreach (var key in collection)
                {
                    if (key.Key == "ID")
                    {
                        model.ID = int.Parse(collection[key.Key]);
                    }
                    else if (key.Key == "Title")
                    {
                        model.Title = collection[key.Key];
                    }
                    //else if (key.Key.Contains("correctOption")) //this must be Correct Option
                    //{
                    //    if (!string.IsNullOrEmpty(collection[key.Key]))
                    //    {
                    //        var correctOption = new Option();
                    //        correctOption.Answer = collection[key.Key];
                    //        correctOption.IsCorrect = true;

                    //        model.CorrectOptions.Add(correctOption);
                    //    }
                    //}
                    else if (key.Key.Contains("option") && key.Key.Contains("isoptioncorrect") == false) //this must be Option
                    {
                        if (!string.IsNullOrEmpty(collection[key.Key]))
                        {
                            var option = new Option();
                            option.Answer = collection[key.Key];

                            var index = Regex.Replace(key.Key, "[^0-9]+", string.Empty);

                            var isOptionCorrect = collection["isoptioncorrect" + index] == "on";

                            option.IsCorrect = isOptionCorrect;

                            model.Options.Add(option);
                        }
                    }
                }
            }

            return(model);
        }
Ejemplo n.º 25
0
        public static EditQuestionViewModel ToEditQuestionViewModel(this Question question, IAnswerService answers, IQuizService quizzes)
        {
            var vm = new EditQuestionViewModel();

            vm.Question = question.ToQuestionViewModel(answers, true);
            vm.Order    = string.Join(",", question.Answers.AsQueryable().AsNoTracking().OrderBy(x => x.OrderId).Select(x => x.Id));

            var quiz = quizzes.Get(question.QuizId);

            vm.QuizId      = quiz.Id;
            vm.AllowPoints = quiz.AllowPoints;
            vm.IsTimeable  = quiz.IsTimeable;

            return(vm);
        }
Ejemplo n.º 26
0
        public async Task EditQuestionAsync(EditQuestionViewModel model)
        {
            var question = await this.questionRepository.All()
                           .FirstOrDefaultAsync(x => x.Id == model.Id);

            if (question == null)
            {
                throw new ArgumentException("There is no question with this id.");
            }

            question.Text     = model.Text;
            question.IsActive = model.IsActive;

            this.questionRepository.Update(question);
            await this.questionRepository.SaveChangesAsync();
        }
Ejemplo n.º 27
0
        public IActionResult EditQuestion(EditQuestionViewModel model)
        {
            TestingQuestion question = new TestingQuestion
            {
                Id            = model.Id,
                TestId        = model.TestId,
                CorrectAnswer = model.CorrectAnswer,
                Text          = model.Title,
                AnswerOptions = model.AnswerOptions
            };
            var currentQuestion = _context.Questions.Find(model.Id);

            _context.Questions.Remove(currentQuestion);
            _context.Questions.Add(question);
            _context.SaveChanges();
            return(View(model));
        }
Ejemplo n.º 28
0
        private EditQuestionViewModel GetEditTextQuestionViewModelFromFormCollection(EditQuestionViewModel model, FormCollection collection)
        {
            model.Options        = new List <Option>();
            model.CorrectOptions = new List <Option>();

            if (collection.Keys.Count() > 0)
            {
                foreach (string key in collection.Keys)
                {
                    if (key == "ID")
                    {
                        model.ID = int.Parse(collection[key]);
                    }
                    else if (key == "Title")
                    {
                        model.Title = collection[key];
                    }
                    else if (key.Contains("correctOption")) //this must be Correct Option
                    {
                        if (!string.IsNullOrEmpty(collection[key]))
                        {
                            var correctOption = new Option();
                            correctOption.Answer     = collection[key];
                            correctOption.IsCorrect  = true;
                            correctOption.ModifiedOn = DateTime.Now;

                            model.CorrectOptions.Add(correctOption);
                        }
                    }
                    else if (key.Contains("option")) //this must be Option
                    {
                        if (!string.IsNullOrEmpty(collection[key]))
                        {
                            var option = new Option();
                            option.Answer     = collection[key];
                            option.IsCorrect  = false;
                            option.ModifiedOn = DateTime.Now;

                            model.Options.Add(option);
                        }
                    }
                }
            }

            return(model);
        }
Ejemplo n.º 29
0
        public virtual async Task <ActionResult> Edit(EditQuestionViewModel viewModel)
        {
            if (!await _questionService.IsInDb(viewModel.Id))
            {
                this.AddErrors("Body", "سوال مورد نظر توسط یکی از کاربران در شبکه،حذف شده است");
            }

            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }
            await _questionService.EditAsync(viewModel);

            await _unitOfWork.SaveAllChangesAsync();

            return(RedirectToAction(MVC.Question.List()));
        }
Ejemplo n.º 30
0
        public IActionResult Edit(EditQuestionViewModel model)
        {
            if (ModelState.IsValid)
            {
                var res = surveyRepository.GetQuestionById(model.Q_Id);

                if (res == null)
                {
                    ViewBag.Error = $"The id {res.Q_Id} mentioned is not available";
                    return(View("NotFound"));
                }

                res.Q_Text = model.Q_Text;
                surveyRepository.UpdatedQuestion(res);
                ViewBag.QuestionEdited = "The URL has been Successfully edited";
            }
            return(View(model));
        }