Ejemplo n.º 1
0
        private Score UpdateScore(int scoreId, int newValue,
                                  IScoreRepository scoreRepository,
                                  IBracketRepository bracketRepository,
                                  ITeamRepository teamRepository)
        {
            var score   = scoreRepository.GetScoreByID(scoreId);
            var bracket = bracketRepository.GetBracketByID(score.BracketID);

            if (!bracket.Finished && newValue >= 0)
            {
                score.Value = newValue;
                scoreRepository.UpdateScore(score);
            }

            ConnectionHub.SendToAll(UPDATE);

            var scores = (List <Score>)scoreRepository.GetScores(_ => _.BracketID == score.BracketID);
            var score1 = scores[0];
            var score2 = scores[1];
            var team   = teamRepository.GetTeamByID(score.TeamID);
            var team1  = teamRepository.GetTeamByID(score1.TeamID);
            var team2  = teamRepository.GetTeamByID(score2.TeamID);

            var body = string.Format("{0} ({1}) - ({2}) {3}", team1.Name, score1.Value, score2.Value, team2.Name);

            var notification = new Notification()
            {
                Title  = string.Format("{0} scored!", team.Name),
                Body   = body,
                Params = { bracket.TournamentID.ToString() }
            };

            PushHub.Send(notification);

            return(score);
        }
Ejemplo n.º 2
0
        public ChallengerMutation(ITournamentRepository tournamentRepository,
                                  ITeamRepository teamRepository,
                                  IBracketRepository bracketRepository,
                                  IScoreRepository scoreRepository,
                                  IUserRepository userRepository)
        {
            Field <TournamentType>(
                "createTournament",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <TournamentInputType> > {
                Name = "tournament"
            },
                    new QueryArgument <NonNullGraphType <ListGraphType <TeamInputType> > > {
                Name = "teams"
            },
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "categoryId"
            },
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "userId"
            }),
                resolve: context =>
            {
                var tournament = context.GetArgument <Tournament>("tournament");
                var teamsNames = context.GetArgument <Team[]>("teams");
                var categoryId = context.GetArgument <int>("categoryId");
                var userId     = context.GetArgument <int>("userId");
                return(CreateTournament(tournamentRepository,
                                        teamRepository, bracketRepository, scoreRepository,
                                        tournament, teamsNames, categoryId, userId));
            });
            Field <ScoreType>(
                "updateScore",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id"
            },
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "value"
            }),
                resolve: context =>
            {
                var scoreId  = context.GetArgument <int>("id");
                var newValue = context.GetArgument <int>("value");
                return(UpdateScore(scoreId, newValue, scoreRepository,
                                   bracketRepository, teamRepository));
            });
            Field <BracketType>(
                "updateBracket",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id"
            },
                    new QueryArgument <NonNullGraphType <BooleanGraphType> > {
                Name = "finished"
            }),
                resolve: context =>
            {
                var bracketId = context.GetArgument <int>("id");
                var finished  = context.GetArgument <bool>("finished");
                var bracket   = bracketRepository.GetBracketByID(bracketId);
                return(UpdateBracket(bracket, finished, bracketId,
                                     bracketRepository, scoreRepository, teamRepository));
            });
            Field <UserType>(
                "signup",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "name"
            },
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "password"
            }),
                resolve: context =>
            {
                var name     = context.GetArgument <string>("name");
                var password = context.GetArgument <string>("password");
                var user     = new User {
                    Name = name, Password = password
                };
                var createdUser = userRepository.InsertUser(user);
                return(createdUser);
            });

            Field <UserType>(
                "login",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "name"
            },
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "password"
            }),
                resolve: context =>
            {
                var name     = context.GetArgument <string>("name");
                var password = context.GetArgument <string>("password");
                return(userRepository.GetUsers(_ => _.Name == name && _.Password == password).First());
            });
        }