예제 #1
0
        public async Task MakeNewQuiz(string username, string quizId, QuizOptions quizOptions)
        {
            var player = new Player
            {
                ConnectionId = Context.ConnectionId,
                Username     = username
            };

            if (QuizState.IsUsernameTaken(quizId, username).GetValueOrDefault())
            {
                await Clients.Caller.SendAsync("UsernameTaken");
            }
            var quiz = new Models.Quiz
            {
                Id      = quizId,
                Players = new List <Player>()
                {
                    player
                },
            };

            quiz.Players.Add(player);
            QuizState.GetWaitingPlayers(quizId).ForEach(player =>
            {
                quiz.Players.Add(player);
            });
            await Clients.Group(quizId).SendAsync("NewQuiz");

            QuizState.AddQuiz(quiz);
        }
        public int Add(string title)
        {
            var quiz = new Quiz.Models.Quiz
            {
                Title = title
            };

            this.applicationDbContext.Quizes.Add(quiz);
            this.applicationDbContext.SaveChanges();
            return(quiz.Id);
        }
        public int Add(string title)
        {
            var quiz = new Quiz.Models.Quiz
            {
                Title = title
            };

            this.db.Quizes.Add(quiz);
            this.db.SaveChanges();

            return(quiz.Id);
        }
예제 #4
0
 public static void RemoveQuiz(Quiz quiz)
 {
     _quizes.TryRemove(quiz.Id, out var foundQuiz);
 }
예제 #5
0
 public static void AddQuiz(Quiz quiz)
 {
     _quizes[quiz.Id] = quiz;
 }