Example #1
0
        public ActionResult Manage()
        {
            GymGameModelDataContext dc = new GymGameModelDataContext();
            // user komt normaal gezien uit de sessievar.
            User u = new User();
            u.User_Id = 1;
            QuizMasterModel qmm = new QuizMasterModel();
            List<Quiz> Allquizzes = qmm.getAllQuizzes(u);

            ViewBag.quizzes = Allquizzes;
            return View();
        }
Example #2
0
        public ActionResult Start(FormCollection f)
        {
            QuizMasterModel qmm = new QuizMasterModel();
            Round round = selectRound(f["roundId"]);

            List<Round> rounds = (List<Round>)Session["roundsManaging"];
            Session.Remove("roundsManaging");

            // return values
            var status = new Dictionary<string, string>{};

            try
            {
                //hier testen we al of user effectief rondes mag starten
                Boolean editPermission = false;
                foreach (Round r in rounds)
                {
                    if(r.Round_Id == round.Round_Id) { editPermission = true; }
                }

                if(editPermission)
                {
                    try
                    {
                        //start round (current time is set there)
                        if (f["action"] == "start")
                        {
                            int duration = int.Parse(f["duration"]) * 60;
                            round.Max_Time = int.Parse(f["duration"]) * 60;
                            round = qmm.startRound(round);
                        }
                        else
                        {
                            round = qmm.stopRound(round);
                        }
                        status.Add("status","success");
                    }
                    catch (Exception e)
                    {
                        status.Add("status", "error");
                    }

                    //set additional return values
                    if (f["action"] == "start")
                    {
                        status.Add("current", "Gestart");
                    }
                    else
                    {
                        status.Add("current", "Gestopt");
                    }

                    DateTime maxTime = new DateTime();
                    if (round.Round_started != null) { maxTime = (DateTime)round.Round_started; }
                    if (round.Max_Time != null) { maxTime = maxTime.AddSeconds((double)round.Max_Time); }

                    String timeRemaining = "0";

                    if (round.Round_started <= DateTime.Now && DateTime.Now < maxTime)
                    {
                        TimeSpan timeRem = (TimeSpan)(maxTime - DateTime.Now);
                        timeRemaining = Math.Round(timeRem.TotalSeconds).ToString();
                    }
                    else { timeRemaining = round.Max_Time.ToString(); }

                    status.Add("timeRemaining", timeRemaining);
                }
                else { throw new Exception("Je bent niet gemachtigd om deze quiz te starten..."); }
            }
            catch (Exception e)
            {
                status.Add("status", "error");
            }

            return Json(status, JsonRequestBehavior.AllowGet);
        }