コード例 #1
0
        public IActionResult EditQuestionSave(EditQuestionViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Traitement pour sauvegarder les questions

                //transformer le viewModel en une entité Question

                var question = new Domain.Entities.Question
                {
                    Id       = model.Id.Value,
                    Category = new QuestionCategory {
                        Id = model.CategoryId
                    },                                                         //
                    Content    = model.Content,
                    Difficulty = new QuestionDifficulty {
                        Id = model.DifficultyId
                    },
                    Type = new QuestionType {
                        Id = model.TypeId
                    }
                };

                var questionId = _questionDao.UpdateQuestion(question);

                if (questionId > 0)
                {
                    return(RedirectToAction("Details", new { questionId }));
                }
                else
                {
                    ModelState.AddModelError("CategoryId", "La question n'a pas été mise à jour!");
                }
            }


            AddReferenceDataToModel(model);

            return(View("Edit", model));
        }
コード例 #2
0
        public IActionResult Create(EditQuestionViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Traitement pour sauvegarder les questions

                //transformer le viewModel en une entité Question

                var question = new Domain.Entities.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(Details), new { questionId }));
                }
                else
                {
                    ModelState.AddModelError("CategoryId", "La question n'a pas été ajoutée!");
                }
            }

            AddReferenceDataToModel(model);
            return(View(model));
        }