コード例 #1
0
        public Answer AddAnswer(Answer answer)
        {
            Answer foundAnswer = context.Answer.Where(a => a.QuestionId == answer.QuestionId && a.Text == answer.Text).FirstOrDefault();

            if (foundAnswer != null)
            {
                return(null);
            }
            context.Answer.Add(answer);
            context.SaveChanges();
            return(answer);
        }
コード例 #2
0
        public User CreateUser(User user)
        {
            User foundUser = context.User.Where(usr => usr.Email == user.Email).FirstOrDefault();

            if (foundUser != null)
            {
                return(null);
            }
            context.Add(user);
            context.SaveChanges();
            return(user);
        }
コード例 #3
0
        public Question AddQuestion(int quizId, Question question)
        {
            List <Question> allExistingQuestions = this.GetAllByQuizId(quizId);
            Question        foundQuestion        = allExistingQuestions.Where(q => q.Text == question.Text).FirstOrDefault();

            if (foundQuestion != null)
            {
                return(null);
            }
            context.Question.Add(question);
            context.QuizQuestion.Add(new QuizQuestion
            {
                QuestionId = question.Id,
                QuizId     = quizId
            });
            context.SaveChanges();
            return(question);
        }
コード例 #4
0
        public Player AddPlayer(Player player, string code)
        {
            if (FindGameByCode(code) == null)
            {
                return(null);
            }
            Game foundGame = FindGameByCode(code);

            context.Player.Add(player);
            context.SaveChanges();
            PlayerGame newPlayerGame = new PlayerGame
            {
                GameId   = foundGame.Id,
                PlayerId = player.Id,
                Score    = 0
            };

            context.PlayerGame.Add(newPlayerGame);
            return(player);
        }
コード例 #5
0
 public Game Create(Game game)
 {
     context.Add(game);
     context.SaveChanges();
     return(game);
 }
コード例 #6
0
 public PlayerGame Create(PlayerGame playergame)
 {
     context.Add(playergame);
     context.SaveChanges();
     return(playergame);
 }
コード例 #7
0
 public Quiz CreateQuiz(Quiz quiz)
 {
     context.Add(quiz);
     context.SaveChanges();
     return(quiz);
 }