Ejemplo n.º 1
0
        public ActionResult Index(QuestionsVM model)
        {
            model.Questions = db.Questions.OrderByDescending(o => o.Votes.Sum(v => v.VoteValue));

            if (ModelState.IsValid)
            {

                var user = db.Users.Find(User.Identity.GetUserId());
                model.VoteQuota = user.VoteQuota;
                model.QuestionQuota = user.QuestionQuota;
                if (user.QuestionQuota > 0)
                {
                    user.QuestionQuota--;
                    db.Questions.Add(new Question() {
                        Text = model.QuestionText,
                        Questioner = user,
                        TimeStamp = DateTime.UtcNow
                    });
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
                else
                {
                    ModelState.AddModelError("QuestionText", "Out of questions!");
                    return View("Index", model);
                }
            }
            return View("Index", model);
        }
Ejemplo n.º 2
0
 public ActionResult Index()
 {
     var model = new QuestionsVM();
     model.Questions = GetQuestions();
     model.QuestionText = null;
     return View(model);
 }
Ejemplo n.º 3
0
 public ActionResult Index()
 {
     var model = new QuestionsVM();
     if (User.Identity.IsAuthenticated)
     {
         var user = db.Users.Find(User.Identity.GetUserId());
         model.VoteQuota = user.VoteQuota;
         model.QuestionQuota = user.QuestionQuota;
     }
     model.Questions = db.Questions
         .OrderBy(o => o.Answered)
         .ThenByDescending(o => o.Votes.Sum(v => v.VoteValue));
     model.QuestionText = null;
     return View(model);
 }
Ejemplo n.º 4
0
        public ActionResult AskQuestion(QuestionsVM model)
        {
            if (ModelState.IsValid)
            {

                var user = db.Users.Find(User.Identity.GetUserId());

                db.Questions.Add(new Question()
                {
                    Text = model.QuestionText,
                    Questioner = user,
                    TimeStamp = DateTime.UtcNow
                });
                db.SaveChanges();
                return RedirectToAction("Index");

            }
            return View("Index", model);
        }