Exemplo 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));
        }
Exemplo n.º 2
0
        public ActionResult Index()
        {
            var model = new QuestionsVM();

            model.Questions    = GetQuestions();
            model.QuestionText = null;
            return(View(model));
        }
Exemplo n.º 3
0
        public IActionResult Questions(string id, int page = 1)
        {
            QuestionsVM model = new QuestionsVM();

            if (id == token)
            {
                model.Page      = page - 1;
                model.Count     = 1000;
                model.Questions = SemEvalRepository.GetQuestionList(model.Count, page).Result;
                model.Max       = SemEvalRepository.GetQuestionsCount().Result;
                model.Token     = id;
                return(View(model));
            }
            return(Redirect("/"));
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
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));
        }
Exemplo n.º 6
0
        /// METODO: durante il passaggio alla pagina con id x caricami i dati del livello con id x e setta il DataContext
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            string liv = string.Empty;

            /// IF: riesco a prendere il livello sul quale sto navigando
            if (NavigationContext.QueryString.TryGetValue("id", out liv))
            {
                /// converti la stringa dell id del livello in intero
                idLivello = Convert.ToInt32(liv);
                /// crea un nuovo DataContext con il LivelloVM(id) per il binding
                this.DataContext = new QuestionsVM(idLivello, Cursore);
                QuestionsVM vm = (QuestionsVM)this.DataContext;
                ///associo all'evento PlaySounds il play dei vari media elements
                vm.PlayCorrettaSound += (sender, ev) =>
                {
                    correctding.Play();
                };

                vm.PlayErrataSound += (sender, ev) =>
                {
                    wrong.Play();
                };

                vm.PlayVittoriaSound += (sender, ev) =>
                {
                    win.Play();
                };

                vm.PlayContatoreSound += (sender, ev) =>
                {
                    beep.Play();
                };

                vm.PlayContatoreLastSound += (sender, ev) =>
                {
                    lastbeep.Play();
                };
            }
        }
Exemplo n.º 7
0
 public IActionResult AddQuestion(QuestionsVM entities, int lessonId)
 {
     if (ModelState.IsValid)
     {
         foreach (var item in entities.Questions)
         {
             Questions model = new Questions();
             model.Question = item.Question;
             model.Option1  = item.Option1;
             model.Option2  = item.Option2;
             model.Option3  = item.Option3;
             model.Option4  = item.Option4;
             model.LessonId = lessonId;
             _questionsService.Add(model);
         }
         return(Redirect("/Admin/AddQuestionReply/" + lessonId));
     }
     ViewBag.Lessons     = _lessonService.GetAll();
     TempData["message"] = "Boş Alanları Doldurunuz";
     return(View(entities));
 }