public ActionResult DeleteConfirmed(int id)
        {
            PlayerTournament playerTournament = db.PlayerTournaments.Find(id);

            db.PlayerTournaments.Remove(playerTournament);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "Id,TournamentId,ApsnetUserId")] PlayerTournament playerTournament)
 {
     if (ModelState.IsValid)
     {
         db.Entry(playerTournament).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.TournamentId = new SelectList(db.Tournaments, "Id", "Name", playerTournament.TournamentId);
     return(View(playerTournament));
 }
        public ActionResult Create([Bind(Include = "Id,TournamentId,ApsnetUserId")] PlayerTournament playerTournament)
        {
            if (ModelState.IsValid)
            {
                db.PlayerTournaments.Add(playerTournament);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.TournamentId = new SelectList(db.Tournaments, "Id", "Name", playerTournament.TournamentId);
            return(View(playerTournament));
        }
        // GET: PlayerTournaments/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PlayerTournament playerTournament = db.PlayerTournaments.Find(id);

            if (playerTournament == null)
            {
                return(HttpNotFound());
            }
            return(View(playerTournament));
        }
        // GET: PlayerTournaments/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PlayerTournament playerTournament = db.PlayerTournaments.Find(id);

            if (playerTournament == null)
            {
                return(HttpNotFound());
            }
            ViewBag.TournamentId = new SelectList(db.Tournaments, "Id", "Name", playerTournament.TournamentId);
            return(View(playerTournament));
        }
Ejemplo n.º 6
0
        public async Task <Tournament> UnlinkPlayerFromTournamentAsync(PlayerTournament playerTournament)
        {
            PlayerTournament playerTournamentLink = this.playerTournamentRepository.GetByPlayerAndTournamentId(playerTournament.PlayerId, playerTournament.TournamentId);

            if (playerTournamentLink != null)
            {
                await this.playerTournamentRepository.DeleteAsync(playerTournamentLink);

                // Unlink all player positions from tournament as well
                this.playerPositionTournamentRepository.DeleteByPlayerAndTournamentId(playerTournament.PlayerId, playerTournament.TournamentId);

                // Remove player ID's on tournament
                this.RemovePlayerOnTournament(playerTournament.PlayerId, playerTournament.TournamentId);
            }

            return(this.tournamentRepository.GetWithPlayersById(playerTournament.TournamentId));
        }
Ejemplo n.º 7
0
        public async Task <Tournament> LinkPlayerToTournamentAsync(PlayerTournament playerTournament)
        {
            PlayerTournament playerTournamentLink = this.playerTournamentRepository.GetByPlayerAndTournamentId(playerTournament.PlayerId, playerTournament.TournamentId);

            if (playerTournamentLink == null)
            {
                await this.playerTournamentRepository.InsertAsync(playerTournament);
            }
            else
            {
                // Mapping
                playerTournamentLink.Handicap = playerTournament.Handicap;

                await this.playerTournamentRepository.UpdateAsync(playerTournamentLink);
            }

            return(this.tournamentRepository.GetWithPlayersById(playerTournament.TournamentId));
        }
Ejemplo n.º 8
0
        // Additional functionality and overrides

        public IEnumerable <Player> GetPlayersOfFrameById(Guid id)
        {
            Frame frame = this.context.Frames.Find(id);

            if (frame == null)
            {
                return(null);
            }

            List <FramePlayer> framePlayers = this.context.FramePlayer
                                              .Include(fp => fp.Player)
                                              .Where(fp => fp.FrameId == id)
                                              .ToList();

            List <Player> players = framePlayers.Select(fp => {
                Player player = new Player()
                {
                    Id        = fp.Player.Id,
                    FirstName = fp.Player.FirstName,
                    LastName  = fp.Player.LastName,
                    Position  = fp.Position,
                    Score     = fp.Score
                };

                // Include handicaps from PlayerTournament
                PlayerTournament playerTournament = this.context.PlayerTournament
                                                    .SingleOrDefault(pt => pt.TournamentId == frame.TournamentId && pt.PlayerId == player.Id);
                if (playerTournament != null)
                {
                    player.Handicap = playerTournament.Handicap;
                }

                return(player);
            }).ToList();

            players = players.OrderBy(p => p.Position).ToList();

            return(players);
        }
Ejemplo n.º 9
0
        public SCMutation(
            LeagueBLL leagueBLL,
            PlayerBLL playerBLL,
            SettingBLL settingBLL,
            TournamentBLL tournamentBLL,
            FrameBLL frameBLL
            )
        {
            #region Leagues

            FieldAsync <LeagueType>(
                "createLeague",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <LeagueInputType> >
            {
                Name = "league"
            }
                    ),
                resolve: async context =>
            {
                League league = context.GetArgument <League>("league");

                return(await context.TryAsyncResolve(
                           async c => await leagueBLL.CreateLeagueAsync(league)
                           ));
            }
                );

            FieldAsync <LeagueType>(
                "updateLeague",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> >
            {
                Name = "id"
            },
                    new QueryArgument <NonNullGraphType <LeagueInputType> >
            {
                Name = "league"
            }
                    ),
                resolve: async context =>
            {
                Guid id       = context.GetArgument <Guid>("id");
                League league = context.GetArgument <League>("league");

                return(await context.TryAsyncResolve(
                           async c => await leagueBLL.UpdateLeagueAsync(id, league)
                           ));
            }
                );

            FieldAsync <LeagueType>(
                "linkPlayerToLeague",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <LeaguePlayerInputType> >
            {
                Name = "leaguePlayer"
            }
                    ),
                resolve: async context =>
            {
                LeaguePlayer leaguePlayer = context.GetArgument <LeaguePlayer>("leaguePlayer");

                return(await context.TryAsyncResolve(
                           async c => await leagueBLL.LinkPlayerToLeagueAsync(leaguePlayer)
                           ));
            }
                );

            FieldAsync <LeagueType>(
                "unlinkPlayerFromLeague",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <LeaguePlayerInputType> >
            {
                Name = "leaguePlayer"
            }
                    ),
                resolve: async context =>
            {
                LeaguePlayer leaguePlayer = context.GetArgument <LeaguePlayer>("leaguePlayer");

                return(await context.TryAsyncResolve(
                           async c => await leagueBLL.UnlinkPlayerFromLeagueAsync(leaguePlayer)
                           ));
            }
                );

            FieldAsync <BooleanGraphType>(
                "removeLeague",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> >
            {
                Name = "id"
            }
                    ),
                resolve: async context =>
            {
                Guid id = context.GetArgument <Guid>("id");

                return(await context.TryAsyncResolve(
                           async c => await leagueBLL.RemoveLeagueAsync(id)
                           ));
            }
                );

            #endregion

            #region Players

            FieldAsync <PlayerType>(
                "createPlayer",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <PlayerInputType> >
            {
                Name = "player"
            }
                    ),
                resolve: async context =>
            {
                Player player = context.GetArgument <Player>("player");

                return(await context.TryAsyncResolve(
                           async c => await playerBLL.CreatePlayerAsync(player)
                           ));
            }
                );

            FieldAsync <PlayerType>(
                "updatePlayer",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> >
            {
                Name = "id"
            },
                    new QueryArgument <NonNullGraphType <PlayerInputType> >
            {
                Name = "player"
            }
                    ),
                resolve: async context =>
            {
                Guid id       = context.GetArgument <Guid>("id");
                Player player = context.GetArgument <Player>("player");

                return(await context.TryAsyncResolve(
                           async c => await playerBLL.UpdatePlayerAsync(id, player)
                           ));
            }
                );

            FieldAsync <BooleanGraphType>(
                "removePlayer",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> >
            {
                Name = "id"
            }
                    ),
                resolve: async context =>
            {
                Guid id = context.GetArgument <Guid>("id");

                return(await context.TryAsyncResolve(
                           async c => await playerBLL.RemovePlayerAsync(id)
                           ));
            }
                );

            #endregion

            #region Settings

            FieldAsync <SettingType>(
                "createSetting",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <SettingInputType> >
            {
                Name = "setting"
            }
                    ),
                resolve: async context =>
            {
                Setting setting = context.GetArgument <Setting>("setting");

                return(await context.TryAsyncResolve(
                           async c => await settingBLL.CreateSettingAsync(setting)
                           ));
            }
                );

            FieldAsync <SettingType>(
                "updateSetting",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> >
            {
                Name = "id"
            },
                    new QueryArgument <NonNullGraphType <SettingInputType> >
            {
                Name = "setting"
            }
                    ),
                resolve: async context =>
            {
                Guid id         = context.GetArgument <Guid>("id");
                Setting setting = context.GetArgument <Setting>("setting");

                return(await context.TryAsyncResolve(
                           async c => await settingBLL.UpdateSettingAsync(id, setting)
                           ));
            }
                );

            FieldAsync <BooleanGraphType>(
                "removeSetting",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> >
            {
                Name = "id"
            }
                    ),
                resolve: async context =>
            {
                Guid id = context.GetArgument <Guid>("id");

                return(await context.TryAsyncResolve(
                           async c => await settingBLL.RemoveSettingAsync(id)
                           ));
            }
                );

            #endregion

            #region Tournaments

            FieldAsync <TournamentType>(
                "createTournament",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <TournamentInputType> >
            {
                Name = "tournament"
            }
                    ),
                resolve: async context =>
            {
                Tournament tournament = context.GetArgument <Tournament>("tournament");

                return(await context.TryAsyncResolve(
                           async c => await tournamentBLL.CreateTournamentAsync(tournament)
                           ));
            }
                );

            FieldAsync <TournamentType>(
                "updateTournament",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> >
            {
                Name = "id"
            },
                    new QueryArgument <NonNullGraphType <TournamentInputType> >
            {
                Name = "tournament"
            }
                    ),
                resolve: async context =>
            {
                Guid id = context.GetArgument <Guid>("id");
                Tournament tournament = context.GetArgument <Tournament>("tournament");

                return(await context.TryAsyncResolve(
                           async c => await tournamentBLL.UpdateTournamentAsync(id, tournament)
                           ));
            }
                );

            FieldAsync <TournamentType>(
                "linkPlayerToTournament",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <PlayerTournamentInputType> >
            {
                Name = "playerTournament"
            }
                    ),
                resolve: async context =>
            {
                PlayerTournament playerTournament = context.GetArgument <PlayerTournament>("playerTournament");

                return(await context.TryAsyncResolve(
                           async c => await tournamentBLL.LinkPlayerToTournamentAsync(playerTournament)
                           ));
            }
                );

            FieldAsync <TournamentType>(
                "unlinkPlayerFromTournament",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <PlayerTournamentInputType> >
            {
                Name = "playerTournament"
            }
                    ),
                resolve: async context =>
            {
                PlayerTournament playerTournament = context.GetArgument <PlayerTournament>("playerTournament");

                return(await context.TryAsyncResolve(
                           async c => await tournamentBLL.UnlinkPlayerFromTournamentAsync(playerTournament)
                           ));
            }
                );

            FieldAsync <TournamentType>(
                "linkPlayerPositionToTournament",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <PlayerPositionTournamentInputType> >
            {
                Name = "playerPositionTournament"
            }
                    ),
                resolve: async context =>
            {
                PlayerPositionTournament playerPositionTournament = context.GetArgument <PlayerPositionTournament>("playerPositionTournament");

                return(await context.TryAsyncResolve(
                           async c => await tournamentBLL.LinkPlayerPositionToTournamentAsync(playerPositionTournament)
                           ));
            }
                );

            FieldAsync <TournamentType>(
                "unlinkPlayerPositionFromTournament",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <PlayerPositionTournamentInputType> >
            {
                Name = "playerPositionTournament"
            }
                    ),
                resolve: async context =>
            {
                PlayerPositionTournament playerPositionTournament = context.GetArgument <PlayerPositionTournament>("playerPositionTournament");

                return(await context.TryAsyncResolve(
                           async c => await tournamentBLL.UnlinkPlayerPositionFromTournamentAsync(playerPositionTournament)
                           ));
            }
                );

            FieldAsync <BooleanGraphType>(
                "removeTournament",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> >
            {
                Name = "id"
            }
                    ),
                resolve: async context =>
            {
                Guid id = context.GetArgument <Guid>("id");

                return(await context.TryAsyncResolve(
                           async c => await tournamentBLL.RemoveTournamentAsync(id)
                           ));
            }
                );

            #endregion

            #region Frames

            FieldAsync <FrameType>(
                "createFrame",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <FrameInputType> >
            {
                Name = "frame"
            }
                    ),
                resolve: async context =>
            {
                Frame frame = context.GetArgument <Frame>("frame");

                return(await context.TryAsyncResolve(
                           async c => await frameBLL.CreateFrameAsync(frame)
                           ));
            }
                );

            FieldAsync <FrameType>(
                "updateFrame",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> >
            {
                Name = "id"
            },
                    new QueryArgument <NonNullGraphType <FrameInputType> >
            {
                Name = "frame"
            }
                    ),
                resolve: async context =>
            {
                Guid id     = context.GetArgument <Guid>("id");
                Frame frame = context.GetArgument <Frame>("frame");

                return(await context.TryAsyncResolve(
                           async c => await frameBLL.UpdateFrameAsync(id, frame)
                           ));
            }
                );

            FieldAsync <BooleanGraphType>(
                "removeFrame",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> >
            {
                Name = "id"
            }
                    ),
                resolve: async context =>
            {
                Guid id = context.GetArgument <Guid>("id");

                return(await context.TryAsyncResolve(
                           async c => await frameBLL.RemoveFrameAsync(id)
                           ));
            }
                );

            #endregion
        }
Ejemplo n.º 10
0
        public ActionResult Index(int?id)
        {
            var tournament = db.Tournaments.SingleOrDefault(x => x.IsActive);

            if (tournament != null)
            {
                id = tournament.Id;
            }
            if (id == null)
            {
                return(RedirectToAction("List", "Home"));
            }
            var userId = User.Identity.GetUserId();

            if (userId == null)
            {
                return(RedirectToAction("Login", "Account"));
            }
            var userGuid = new Guid(userId);

            var result = new TournamentMain();

            result.Tournament          = db.Tournaments.Include(t => t.Country).Include(t => t.Matchups).Where(x => x.Id == id).First();
            result.Tournament.Matchups = result.Tournament.Matchups.OrderBy(x => x.GameTime).ToList();

            var isInTournament = db.PlayerTournaments.Any(x => x.TournamentId == id.Value && x.ApsnetUserId == userGuid);

            if (!isInTournament)
            {
                var playerTournament = new PlayerTournament()
                {
                    TournamentId = id.Value,
                    ApsnetUserId = userGuid,
                };
                db.PlayerTournaments.Add(playerTournament);
                foreach (var matchup in result.Tournament.Matchups)
                {
                    var prediction = new Prediction()
                    {
                        AspNetUserId = userGuid,
                        MatchupId    = matchup.Id,
                    };
                    db.Predictions.Add(prediction);
                }
                db.SaveChanges();
            }

            foreach (var matchup in result.Tournament.Matchups)
            {
                if (matchup.GameTime > DateTime.UtcNow.AddHours(3).AddMinutes(result.Tournament.MatchupClosingTime))
                {
                    matchup.CanVote = true;
                }
            }
            var allCountries = db.Countries.ToList();
            var cc           = allCountries.Last();
            var players      = db.PlayerTournaments.Where(x => x.TournamentId == id).ToList();

            result.PlayerPredictions = new List <PlayerPredictions>();
            foreach (var player in players)
            {
                var playerPrediction = new PlayerPredictions();
                playerPrediction.Name = db.Users.Find(player.ApsnetUserId.ToString()).UserName;
                var predictions = db.Predictions.Include(t => t.Matchup).Include(t => t.Matchup.Country).Where(x => x.AspNetUserId == player.ApsnetUserId).OrderBy(x => x.Matchup.GameTime).ToList();
                playerPrediction.Predictions = predictions;
                playerPrediction.Total       = predictions.Sum(x => x.PointsEarned ?? 0);
                playerPrediction.UserId      = player.ApsnetUserId;
                foreach (var prediction in predictions)
                {
                    if (prediction.Matchup.GameTime > DateTime.UtcNow.AddHours(3).AddMinutes(result.Tournament.MatchupClosingTime) && prediction.AspNetUserId != userGuid)
                    {
                        prediction.EnemyTeamScoreText = GetHiddenScoreText(prediction.EnemyTeamScore);
                        prediction.HomeTeamScoreText  = GetHiddenScoreText(prediction.HomeTeamScore);
                    }
                    else
                    {
                        prediction.EnemyTeamScoreText = prediction.EnemyTeamScore?.ToString() ?? "-";
                        prediction.HomeTeamScoreText  = prediction.HomeTeamScore?.ToString() ?? "-";
                    }
                }

                result.PlayerPredictions.Add(playerPrediction);
            }
            result.PlayerPredictions = result.PlayerPredictions.OrderByDescending(x => x.UserId == userGuid).ThenByDescending(x => x.Total).ToList();
            return(View(result));
        }