コード例 #1
0
ファイル: GameModel.cs プロジェクト: hansvn/GymGame
 public List<Result> getAllResultsByQuiz(Quiz q)
 {
     var result = (from r in dc.Results
                   where r.FK_Quiz == q.Quiz_Id
                   select r).ToList<Result>();
     return result;
 }
コード例 #2
0
ファイル: GameModel.cs プロジェクト: hansvn/GymGame
 public List<Round> getAllRounds(Quiz q)
 {
     if (q == null)
     {
         throw new Exception("Quiz must be given...");
     }
     var result = (from round in dc.Rounds
                   where round.FK_Quiz == q.Quiz_Id
                   select round).ToList<Round>();
     return result;
 }
コード例 #3
0
ファイル: PlayableQuiz.cs プロジェクト: hansvn/GymGame
        public void setQuiz(Quiz qz)
        {
            quiz = qz;

            //clear the lists and recreate the values
            playableRounds.Clear();
            List<Round> rounds = gm.getAllRounds(quiz);
            foreach (Round round in rounds)
            {
                playableRounds.Add(new PlayableRound(round));
            }
        }
コード例 #4
0
ファイル: PlayableQuiz.cs プロジェクト: hansvn/GymGame
        public PlayableQuiz(int quizId)
        {
            //select the quiz
            Quiz selectQuiz = new Quiz();
            selectQuiz.Quiz_Id = quizId;
            quiz = gm.getQuiz(selectQuiz);

            //select the rounds and create playable rounds
            List<Round> rounds = gm.getAllRounds(quiz);
            foreach(Round round in rounds)
            {
                playableRounds.Add(new PlayableRound(round));
            }
        }
コード例 #5
0
ファイル: PlayableQuiz.cs プロジェクト: hansvn/GymGame
        public PlayableQuiz(String quizCode)
        {
            //select the quiz
            Quiz selectQuiz = new Quiz();
            selectQuiz.code = quizCode;
            quiz = gm.getQuizByCode(selectQuiz);

            //select the rounds and create playable rounds
            List<Round> rounds = gm.getAllRounds(quiz);
            foreach (Round round in rounds)
            {
                playableRounds.Add(new PlayableRound(round));
            }
        }
コード例 #6
0
ファイル: QuizMasterModel.cs プロジェクト: hansvn/GymGame
 public List<Result> getResultsByUserAndQuiz(User u, Quiz q)
 {
     if (u == null)
     {
         throw new Exception("User must be given...");
     }
     else if (q == null)
     {
         throw new Exception("Quiz must be given...");
     }
     var result = (from r in dc.Results
                   where r.FK_Quiz == q.Quiz_Id && r.FK_User == u.User_Id
                   select r).ToList<Result>();
     return result;
 }
コード例 #7
0
ファイル: CompleteResult.cs プロジェクト: hansvn/GymGame
        public CompleteResult(Result res)
        {
            //set the result
            result = res;

            try
            {
                //get the question
                question.Question_Id = res.FK_Question;
                question = gm.getQuestion(question);

                //get the answer
                answer.Answer_Id = res.FK_Answer;
                answer = gm.getAnswer(answer);
                isRight = (answer.Answer_value == 1);

                //if needed, get the right answer
                if (!isRight)
                {
                    Question q = new Question();
                    q.Question_Id = answer.FK_Question;
                    rightAnswer = gm.getRightAnswer(q);
                }

                //get the quiz
                quiz.Quiz_Id = res.FK_Quiz;
                quiz = gm.getQuiz(quiz);

                //get the user
                user.User_Id = res.FK_User;
                user = um.getUser(user.User_Id);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
コード例 #8
0
ファイル: GameModel.cs プロジェクト: hansvn/GymGame
        public int InsertResultByValues(User user, Question question, Answer answer, Quiz quiz)
        {
            /**
             * User komt van Sessie,
             * Question ook (of uit controller)
             * Answer komt van controller (ajax post)
             * Quiz komt van sessie (of controller)
             **/

            //result aanmaken
            Result r = new Result();
            r.FK_User = user.User_Id;
            r.FK_Question = question.Question_Id;
            r.FK_Answer = answer.Answer_Id;
            r.FK_Quiz = quiz.Quiz_Id;

            //posten naar database
            dc.Results.InsertOnSubmit(r);
            dc.SubmitChanges();

            return r.Result_Id;
        }
コード例 #9
0
ファイル: GameModel.cs プロジェクト: hansvn/GymGame
 public List<Result> getResultsByUserAndQuiz(User u, Quiz q)
 {
     var result = (from r in dc.Results
                   where r.FK_Quiz == q.Quiz_Id && r.FK_User == u.User_Id
                   select r).ToList<Result>();
     return result;
 }
コード例 #10
0
ファイル: GameModel.cs プロジェクト: hansvn/GymGame
        public int getRightAnswersByQuiz(Quiz q)
        {
            var result = (from r in dc.Results
                          join a in dc.Answers on r.FK_Answer equals a.Answer_Id
                          where r.FK_Quiz == q.Quiz_Id
                          select r).ToList();

            //tel de rijen met een goed antwoord.
            foreach (var el in result)
            {
                if (el.Answer.Answer_value == 0) result.Remove(el);
            }
            return result.Count;
        }
コード例 #11
0
ファイル: GameModel.cs プロジェクト: hansvn/GymGame
        public List<Object> getFullQuiz(Quiz quiz)
        {
            if (quiz == null)
            {
                throw new Exception("Quiz must be given...");
            }

            Quiz playQuiz = getQuiz(quiz);
            List<Round> playRounds = getAllRounds(playQuiz);
            List<Question> playQuestions = new List<Question>();
            foreach (Round el in playRounds)
            {
                List<Question> toAdd = getAllQuestions(el);
                foreach (Question q in toAdd)
                {
                    playQuestions.Add(q);
                }
            }
            List<Answer> playAnswers = new List<Answer>();
            foreach (Question el in playQuestions)
            {
                List<Answer> toAdd = getAllAnswers(el);
                foreach (Answer a in toAdd)
                {
                    playAnswers.Add(a);
                }
            }

            List<Object> playableQuiz = new List<Object>();
            playableQuiz.Add(playQuiz);
            playableQuiz.Add(playRounds);
            playableQuiz.Add(playQuestions);
            playableQuiz.Add(playAnswers);

            return playableQuiz;
        }
コード例 #12
0
ファイル: GameModel.cs プロジェクト: hansvn/GymGame
 public Quiz getQuizByName(Quiz quiz)
 {
     if (quiz == null)
     {
         throw new Exception("Quiz must be given...");
     }
     var result = (from q in dc.Quizs
                   where q.name == quiz.name
                   select q).SingleOrDefault();
     return (Quiz)result;
 }
コード例 #13
0
ファイル: QuizMasterModel.cs プロジェクト: hansvn/GymGame
        /**
         * --------------------------------------UPDATE ------------------------------------------*
         **/
        public int updateQuiz(Quiz quiz)
        {
            //query naar database om waarde te vinden
            Quiz result = (from q in dc.Quizs
                          where q.Quiz_Id == quiz.Quiz_Id
                          select q).Single();

            //veranderingen aanbrengen
            if (quiz.FK_Users != null) result.FK_Users = quiz.FK_Users;
            if (quiz.Location != null) result.Location = quiz.Location;
            if (quiz.Date != null) result.Date = quiz.Date;

            //updaten in db
            try
            {
                dc.SubmitChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw new Exception("Value couldn't be updated...");
            }

            return result.Quiz_Id;
        }
コード例 #14
0
 partial void UpdateQuiz(Quiz instance);
コード例 #15
0
 partial void InsertQuiz(Quiz instance);
コード例 #16
0
ファイル: QuizMasterModel.cs プロジェクト: hansvn/GymGame
        /**
         * moet
         * -apart al zijn quizzen kunnen opvragen
         * -per quiz zijn vragen (volgende pagina/ajax)
         * -per vraag zijn antwoorden (volgende pagina/ajax)
         *
         * -Update queries --ok
         *
         * -schrijven (quiz, vraag1, ..) --ok
         * nog insertquery waar id's automatisch worden toegevoegd.
         *
         * (-statussen opvolgen (juiste vragen,...) )
         **/
        /**
         * --------------------------------------INSERT ------------------------------------------*
         **/
        public int insertQuiz(Quiz q)
        {
            //posten naar database
            dc.Quizs.InsertOnSubmit(q);
            try
            {
                dc.SubmitChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw new Exception("Query couldn't be executed...");
            }

            return q.Quiz_Id;
        }
コード例 #17
0
ファイル: GameController.cs プロジェクト: hansvn/GymGame
        public ActionResult Search(String quizCode)
        {
            GameModel gm = new GameModel();
            Quiz result = new Quiz();
            result.name = quizCode;

            result = gm.getQuizByName(result);

            if (result != null)
            {
                ViewBag.foundQuiz = result.name;
                ViewBag.quizUrl = result.code;
            }
            else
            {
                //we konden de quiz niet op de naam vinden, probeer het op code
                result = new Quiz();
                result.code = quizCode;
                result = gm.getQuizByCode(result);

                if (result != null)
                {
                    ViewBag.foundQuiz = result.name;
                    ViewBag.quizUrl = result.code;
                }
                else
                {
                    ViewBag.foundQuiz = "Die quiz hebben we niet gevonden :(";
                    ViewBag.quizUrl = "#";
                }
            }
            return View();
        }
コード例 #18
0
ファイル: GameController.cs プロジェクト: hansvn/GymGame
        public ActionResult Results(String id)
        {
            // checken of de gebruiker al is ingelogd. Indien niet -> /login ->
            if (Session["userId"] == null)
            {
                //gebruiker is niet ingelogd: doorverwijzen naar account/login
                Response.Redirect("~/account/login");
            }

            GameModel gm = new GameModel();
            List<CompleteResult> results = new List<CompleteResult>();

            //kijk of de quiz gegeven is, anders gaan we de status aanpassen naar "no quiz given"
            User u = new User();
            u.User_Id = (int)Session["userId"];

            try
            {
                int quizId = int.Parse(id);
                try
                {
                    //haal resultaten op
                    Quiz q = new Quiz();
                    q.Quiz_Id = quizId;
                    List<Result> res = gm.getResultsByUserAndQuiz(u, q);
                    foreach (Result r in res)
                    {
                        results.Add(new CompleteResult(r));
                    }
                    ViewBag.status = "success";
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    ViewBag.status = "no quiz given";
                }
            }
            catch (Exception e)
            {
                //als we hier terechtkomen is de id een textuele string (bv. "abc")
                try
                {
                    //haal resultaten op
                    Quiz q = new Quiz();
                    q.code = id;
                    q = gm.getQuizByCode(q);
                    List<Result> res = gm.getResultsByUserAndQuiz(u, q);
                    foreach (Result r in res)
                    {
                        results.Add(new CompleteResult(r));
                    }

                    ViewBag.status = "success";
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    //probeer op naam te zoeken (kleine kans, maar vergroot UX)
                    try
                    {
                        //haal resultaten op
                        Quiz q = new Quiz();
                        q.name = id;
                        q = gm.getQuizByName(q);
                        List<Result> res = gm.getResultsByUserAndQuiz(u, q);
                        foreach (Result r in res)
                        {
                            results.Add(new CompleteResult(r));
                        }

                        ViewBag.status = "success";
                    }
                    catch (Exception exc)
                    {
                        Console.WriteLine(exc);

                        ViewBag.status = "no quiz given";
                    }
                }
            }

            //viewbag data:
            //the number of questions
            int questions = results.Count();
            ViewBag.questions = questions;

            //count the right answers
            int rightAnswers = 0;
            foreach (CompleteResult cr in results)
            {
                if (cr.answer.Answer_value == 1) rightAnswers++;
            }
            ViewBag.rightAnswers = rightAnswers;
            ViewBag.percentage = Math.Round(((double)rightAnswers / questions) * 100);

            return View(results);
        }
コード例 #19
0
        //functies om quizzen of rondes uit db te krijgen
        private Quiz selectQuiz(String id)
        {
            GameModel gm = new GameModel();
            Quiz quiz = new Quiz();
            //kijk of de quiz gegeven is, anders gaan we de status aanpassen naar "no quiz given"
            int quizId;
            String status;
            try
            {
                quizId = int.Parse(id);
                try
                {
                    quiz.Quiz_Id = quizId;
                    quiz = gm.getQuiz(quiz);
                    status = "success";
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    status = "no quiz given";
                }
            }
            catch (Exception e)
            {
                //als we hier terechtkomen is de id een textuele string (bv. "abc")
                try
                {
                    quiz.code = id;
                    quiz = gm.getQuizByCode(quiz);
                    status = "success";
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    //probeer op naam te zoeken (kleine kans, maar vergroot UX)
                    try
                    {
                        quiz.name = id;
                        quiz = gm.getQuizByName(quiz);
                        status = "success";
                    }
                    catch (Exception exc)
                    {
                        Console.WriteLine(exc);
                        status = "error";
                    }
                }
            }

            if (status != "success")
            {
                return new Quiz();
            }
            else
            {
                return quiz;
            }
        }
コード例 #20
0
        public ActionResult Quiz(String id)
        {
            GameModel gm = new GameModel();
            Quiz quiz = new Quiz();
            //kijk of de quiz gegeven is, anders gaan we de status aanpassen naar "no quiz given"
            int quizId;
            try
            {
                quizId = int.Parse(id);
                try
                {
                    quiz.Quiz_Id = quizId;
                    quiz = gm.getQuiz(quiz);
                    ViewBag.status = "success";
                    ViewBag.quizName = quiz.name;
                    ViewBag.quizId = quiz.Quiz_Id;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    ViewBag.status = "no quiz given";
                    ViewBag.quizName = "No Quiz found...";
                }
            }
            catch (Exception e)
            {
                //als we hier terechtkomen is de id een textuele string (bv. "abc")
                try
                {
                    quiz.code = id;
                    quiz = gm.getQuizByCode(quiz);
                    ViewBag.status = "success";
                    ViewBag.quizName = quiz.name;
                    ViewBag.quizId = quiz.Quiz_Id;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    //probeer op naam te zoeken (kleine kans, maar vergroot UX)
                    try
                    {
                        quiz.name = id;
                        quiz = gm.getQuizByName(quiz);
                        ViewBag.status = "success";
                        ViewBag.quizName = quiz.name;
                        ViewBag.quizId = quiz.Quiz_Id;
                    }
                    catch (Exception exc)
                    {
                        Console.WriteLine(exc);
                        ViewBag.status = "no quiz given";
                        ViewBag.quizName = "No Quiz found...";
                    }
                }
            }

            //get the results
            List<CompleteResult> results = new List<CompleteResult>();
            try
            {
                List<Result> resultsByQuiz = gm.getAllResultsByQuiz(quiz);
                foreach (Result r in resultsByQuiz)
                {
                    results.Add(new CompleteResult(r));
                }
                ViewBag.status = "success";
            }
            catch (Exception e)
            {
                ViewBag.status = "error";
            }

            List<Leader> leaders = new List<Leader>();
            //select all unique players
            List<int> users = results.Select(r => r.user.User_Id).Distinct().ToList<int>();
            for (int i = 0; i < users.Count(); i++)
            {
                //filter results by current user
                List<CompleteResult> crByUser = new List<CompleteResult>();
                UserModel um = new UserModel();
                User u = um.getUser(users[i]);
                crByUser = results.Where(r => r.user.User_Id == u.User_Id).ToList<CompleteResult>();

                //calculate the values
                int rightAnswers = 0;
                int questions = crByUser.Select(r => r.question.Question_Id).Distinct().Count();
                foreach (CompleteResult cr in crByUser)
                {
                    if (cr.answer.Answer_value == 1) rightAnswers++;
                }
                int score = (int)Math.Round(((double)rightAnswers / questions) * 100);

                //create the leader
                Leader l = new Leader();
                l.score = score;
                l.goodAnswers = rightAnswers;
                l.questions = questions;
                l.user = u;
                l.quiz = quiz;

                //add the leader to list
                leaders.Add(l);

            }

            leaders = leaders.OrderByDescending(l => l.score).ToList<Leader>();
            return View(leaders);
        }
コード例 #21
0
        public ActionResult Detail(FormCollection f)
        {
            GameModel gm = new GameModel();
            Quiz quiz = new Quiz();

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

            try
            {
                //to check if the round really exists
                int quizId = int.Parse(f["quizId"]);
                try
                {
                    quiz.Quiz_Id = quizId;
                    quiz = gm.getQuiz(quiz);
                    status.Add("status", "success");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    status.Add("status", "error - no quiz given");
                }
            }
            catch (Exception e)
            {
                //als we hier terechtkomen is de id een textuele string (bv. "abc")
                Console.WriteLine(e);
                status.Add("status", "error - quiz not found");
            }

            //get the rounds
            List<Round> rounds = new List<Round>();
            try { rounds = gm.getAllRounds(quiz); }
            catch (Exception e) { status["status"] = "error - rounds not found"; }

            //get the results
            List<CompleteResult> results = new List<CompleteResult>();
            try
            {
                List<Result> resultsByRound = gm.getAllResultsByRound(rounds.First());
                foreach (Result r in resultsByRound)
                {
                    results.Add(new CompleteResult(r));
                }
                status["status"] = "success";
            }
            catch (Exception e)
            {
                status["status"] = "error";
            }

            List<Leader> leaders = new List<Leader>();

            //select all unique players
            List<int> users = results.Select(r => r.user.User_Id).Distinct().ToList<int>();
            for (int i = 0; i < users.Count(); i++)
            {
                //filter results by current user
                List<CompleteResult> crByUser = new List<CompleteResult>();
                UserModel um = new UserModel();
                User u = um.getUser(users[i]);
                crByUser = results.Where(r => r.user.User_Id == u.User_Id).ToList<CompleteResult>();

                //calculate the values
                int rightAnswers = 0;
                int questions = crByUser.Select(r => r.question.Question_Id).Distinct().Count();
                foreach (CompleteResult cr in crByUser)
                {
                    if (cr.answer.Answer_value == 1) rightAnswers++;
                }
                int score = (int)Math.Round(((double)rightAnswers / questions) * 100);

                //create the leader
                Leader l = new Leader();
                l.score = score;
                l.goodAnswers = rightAnswers;
                l.questions = questions;
                l.user = u;
                l.quiz = quiz;
                l.round = rounds.First();

                //add the leader to list
                leaders.Add(l);

            }

            status.Add("data", leaders.ToString());

            return Json(status, JsonRequestBehavior.AllowGet);
        }
コード例 #22
0
        public ActionResult Index()
        {
            GameModel gm = new GameModel();

            //get the results
            List<CompleteResult> results = new List<CompleteResult>();
            try
            {
                List<Result> res = gm.getAllResults();
                foreach (Result r in res)
                {
                    results.Add(new CompleteResult(r));
                }
                ViewBag.status = "success";
            }
            catch (Exception e)
            {
                ViewBag.status = "error";
            }

            //create a leader per quiz

            List<Leader> leaders = new List<Leader>();
            //select all unique players
            List<int> users = results.Select(r => r.user.User_Id).Distinct().ToList<int>();
            for(int i = 0; i < users.Count(); i++)
            {
                //filter results by user
                List<CompleteResult> crByUser = new List<CompleteResult>();
                UserModel um = new UserModel();
                User u = um.getUser(users[i]);
                crByUser = results.Where(r => r.user.User_Id == u.User_Id).ToList<CompleteResult>();

                //filter results by quiz
                List<int> quizzes = results.Select(r => r.quiz.Quiz_Id).Distinct().ToList<int>();
                for (int j = 0; j < quizzes.Count(); j++)
                {
                    List<CompleteResult> crByUserQuiz = new List<CompleteResult>();
                    Quiz q = new Quiz();
                    q.Quiz_Id = quizzes[j];
                    q = gm.getQuiz(q);
                    crByUserQuiz = crByUser.Where(x => x.quiz.Quiz_Id == q.Quiz_Id).ToList<CompleteResult>();

                    //calculate the values
                    int rightAnswers = 0;
                    int questions = crByUserQuiz.Select(r => r.question.Question_Id).Distinct().Count();
                    foreach (CompleteResult cr in crByUserQuiz)
                    {
                        if (cr.answer.Answer_value == 1) rightAnswers++;
                    }
                    int score = (int)Math.Round(((double)rightAnswers / questions) * 100);

                    //create the leader
                    Leader l = new Leader();
                    l.score = score;
                    l.goodAnswers = rightAnswers;
                    l.questions = questions;
                    l.user = u;
                    l.quiz = q;

                    //add the leader to list
                    leaders.Add(l);
                }
            }

            leaders = leaders.OrderBy(l => l.quiz.Quiz_Id).ThenByDescending(l => l.score).ToList<Leader>();
            return View(leaders);
        }
コード例 #23
0
 partial void DeleteQuiz(Quiz instance);
コード例 #24
0
		private void attach_Quizs(Quiz entity)
		{
			this.SendPropertyChanging();
			entity.User = this;
		}
コード例 #25
0
		private void detach_Quizs(Quiz entity)
		{
			this.SendPropertyChanging();
			entity.User = null;
		}