public ActionResult Create(string createQuestionBox, int? id)
        {
            var context = new QuestDbEntities();
            Question question;
            if (!string.IsNullOrWhiteSpace(createQuestionBox))
            {
                question = new Question()
                {
                    Text = createQuestionBox
                };

                context.Questions.Add(question);
                context.SaveChanges();
            }
            else if (id != null)
            {
                question = context.Questions.
                    Where(x => x.Id == id).FirstOrDefault();
            }
            else
            {
                //ViewBag.Message = "You cannot create empty question";
                return RedirectToAction("Index", "AdminQuestions");
            }

            var model = new QuestionModel
            {
                Id = question.Id,
                Text = question.Text,
                Answers = question.Answers.AsQueryable().Select(AnswerModel.FromAnswer)
            };

            return View(model);
        }
Exemple #2
0
 public ActionResult Index()
 {
     //Include("Answers").Include("Answers.Votes").Include("Answers.Votes.VoteTypes")
     var context = new QuestDbEntities();
     var questions = context.Questions.Select(QuestionModel.FromQuestion).ToList();
     return View(questions);
 }
Exemple #3
0
 public ActionResult ById(int id)
 {
     var context = new QuestDbEntities();
     var question = context.Questions.
         Where(x => x.Id == id).
         Select(QuestionModel.FromQuestion).FirstOrDefault();
     return View(question);
 }
 public ActionResult Index(int id)
 {
     var context = new QuestDbEntities();
     var answer = context.Answers.
         Where(x => x.Id == id).
         Select(AnswerModel.FromAnswer).FirstOrDefault();
     return View(answer);
 }
Exemple #5
0
        public ActionResult Search(string searchBox)
        {
            if (searchBox == null)
            {
                searchBox = string.Empty;
            }

            var context = new QuestDbEntities();
            var questions = context.Questions.
                Where(x => x.Text.ToLower().Contains(searchBox.ToLower())).
                Select(QuestionModel.FromQuestion).ToList();
            return View(questions);
        }
        public ActionResult VoteYes(int id)
        {
            var context = new QuestDbEntities();
            var answer = context.Answers.FirstOrDefault(x => x.Id == id);
            if (answer != null)
            {
                var vote = new Vote() { TypeId = 1, AnswerId = id };
                answer.Votes.Add(vote);
                context.SaveChanges();
            }

            return RedirectToAction("ById", "Home", new { id = answer.QuestionId });
        }
        public ActionResult Create(string createAnswerBox, int id)
        {
            if (string.IsNullOrWhiteSpace(createAnswerBox))
            {
                //ViewBag.Message = "You cannot create empty question";
                return RedirectToAction("Create", "AdminQuestions", new { id = id });
            }

            var answer = new Answer()
            {
                Text = createAnswerBox
            };

            var context = new QuestDbEntities();
            var question = context.Questions.FirstOrDefault(x => x.Id == id);
            question.Answers.Add(answer);
            context.SaveChanges();
            return RedirectToAction("Create", "AdminQuestions", new { id = answer.QuestionId });
        }
 public ActionResult Index()
 {
     var context = new QuestDbEntities();
     var questions = context.Questions.Select(QuestionModel.FromQuestion).ToList();
     return View(questions);
 }
 public ActionResult Count()
 {
     var context = new QuestDbEntities();
     var count = context.Votes.Count();
     return Content(count.ToString());
 }