Ejemplo n.º 1
0
        public ActionResult Index(CreateQuestionInputModel inputModel)
        {
            if (inputModel != null && this.ModelState.IsValid)
            {
                this.ValidateAnswers(inputModel.Answers);

                if (this.ModelState.IsValid)
                {
                    var context = new VotingSystemEntities();

                    var newQuestion = new Question {
                        Content = inputModel.Content, RequireNames = inputModel.RequireNames
                    };

                    this.AddQuestionAnswers(inputModel.Answers, newQuestion);

                    this.GenerateQuestionUrlId(newQuestion);

                    context.Questions.Add(newQuestion);
                    context.SaveChanges();

                    return(Redirect("/Vote/Index/" + newQuestion.UrlId));
                }
            }

            return(this.View("~/Views/Home/Index.cshtml", inputModel ?? new CreateQuestionInputModel()));
        }
 public VotingSystemDAO()
 {
     _context = new VotingSystemEntities();
 }