Example #1
0
        public static void AddTestData(GameDBContext context)
        {
            var game1 = new Games
            {
                Id          = Guid.NewGuid(),
                Title       = "Gears of War 3",
                Description = "Lorem ipsum dolot sit amet. consectetur asipiscing elit",
                Rating      = 5
            };

            context.Games.Add(game1);

            var gameVote1 = new GameVotes
            {
                Id     = Guid.NewGuid(),
                Game   = game1,
                Rating = 5
            };

            context.GameVotes.Add(gameVote1);

            var game2 = new Games
            {
                Id          = Guid.NewGuid(),
                Title       = "Step Up for Kinnect",
                Description = "Brand new amazing Kinnect game",
                Rating      = 1
            };

            context.Games.Add(game2);

            var gameVote2 = new GameVotes
            {
                Id     = Guid.NewGuid(),
                Game   = game2,
                Rating = 1
            };

            context.GameVotes.Add(gameVote2);

            var game3 = new Games
            {
                Id          = Guid.NewGuid(),
                Title       = "Dead Island",
                Description = "Latest action game. Amazing reviews.",
                Rating      = 3
            };

            context.Games.Add(game3);

            var gameVote3 = new GameVotes
            {
                Id     = Guid.NewGuid(),
                Game   = game2,
                Rating = 3
            };

            context.GameVotes.Add(gameVote3);
            context.SaveChanges();
        }
Example #2
0
        public async Task <IActionResult> VoteGame(VoteGameModel viewModel)
        {
            try
            {
                var gameVote = new GameVotes
                {
                    Id     = Guid.NewGuid(),
                    GameId = viewModel.GameId,
                    Rating = viewModel.Rating
                };

                _context.GameVotes.Add(gameVote);
                await _context.SaveChangesAsync();

                //Update avarge rating for selected game
                var avgRating = _context.GameVotes.Where(x => x.GameId == viewModel.GameId).Average(y => y.Rating);
                var game      = GetGame(viewModel.GameId);
                game.Rating = Convert.ToInt32(avgRating);

                _context.Games.Update(game);
                await _context.SaveChangesAsync();

                return(Redirect($"~/Home"));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
            }

            return(View(viewModel));
        }
Example #3
0
        public async Task <bool> SixthManVotes(List <BoxScore> boxScores, List <int> homeStarters, List <int> awayStarters)
        {
            // NEED WAY TO KNOW WHERE WERE NOT STARTERS
            List <GameVotes> votes     = new List <GameVotes>();
            List <GameVotes> plusMinus = new List <GameVotes>();

            foreach (var bs in boxScores)
            {
                var player = await _context.Players.FirstOrDefaultAsync(x => x.FirstName == bs.FirstName && x.Surname == bs.LastName);

                if (!homeStarters.Contains(player.Id) && !awayStarters.Contains(player.Id))
                {
                    int points = bs.Points * 100;
                    int rebs   = bs.Rebounds * 75;
                    int asts   = bs.Assists * 150;
                    int stls   = bs.Steals * 200;
                    int blks   = bs.Blocks * 200;
                    int to     = bs.Turnovers * 100;

                    int score = points + rebs + asts + stls + blks - to;

                    GameVotes gv = new GameVotes
                    {
                        PlayerId = player.Id,
                        Score    = score
                    };
                    votes.Add(gv);

                    GameVotes gvPM = new GameVotes
                    {
                        PlayerId = player.Id,
                        Score    = bs.PlusMinus
                    };
                    plusMinus.Add(gvPM);
                }
            }

            // Now need to order
            var orderedVotes   = votes.OrderByDescending(x => x.Score);
            var orderedVotesPM = plusMinus.OrderByDescending(x => x.Score);

            // Now need to go through and save the records
            int votesAwarded = 3;

            foreach (var vote in orderedVotes)
            {
                if (votesAwarded > 0)
                {
                    var existing = await _context.SixthManVoting.FirstOrDefaultAsync(x => x.PlayerId == vote.PlayerId);

                    if (existing == null)
                    {
                        SixthManVote sixth = new SixthManVote
                        {
                            PlayerId = vote.PlayerId,
                            Votes    = votesAwarded
                        };
                        await _context.AddAsync(sixth);

                        await _context.SaveChangesAsync();
                    }
                    else
                    {
                        int totalVotes = existing.Votes + votesAwarded;
                        existing.Votes = totalVotes;
                        _context.Update(existing);
                        await _context.SaveChangesAsync();
                    }
                    votesAwarded--;
                }
                else
                {
                    break;
                }
            }

            votesAwarded = 3;
            foreach (var vote in orderedVotesPM)
            {
                if (votesAwarded > 0)
                {
                    var existing = await _context.SixthManVoting.FirstOrDefaultAsync(x => x.PlayerId == vote.PlayerId);

                    if (existing == null)
                    {
                        SixthManVote sixth = new SixthManVote
                        {
                            PlayerId = vote.PlayerId,
                            Votes    = votesAwarded
                        };
                        await _context.AddAsync(sixth);

                        await _context.SaveChangesAsync();
                    }
                    else
                    {
                        int totalVotes = existing.Votes + votesAwarded;
                        existing.Votes = totalVotes;
                        _context.Update(existing);
                        await _context.SaveChangesAsync();
                    }
                    votesAwarded--;
                }
                else
                {
                    break;
                }
            }

            return(true);
        }
Example #4
0
        public async Task <bool> DpoyVotes(List <BoxScore> boxScores)
        {
            List <GameVotes> votes = new List <GameVotes>();

            foreach (var bs in boxScores)
            {
                int rebs = bs.Rebounds * 25;
                int stls = bs.Steals * 200;
                int blks = bs.Blocks * 200;
                int pm   = (bs.PlusMinus * 50) / 2;

                int score = pm + rebs + stls + blks;

                var player = await _context.Players.FirstOrDefaultAsync(x => x.FirstName == bs.FirstName && x.Surname == bs.LastName);

                GameVotes gv = new GameVotes
                {
                    PlayerId = player.Id,
                    Score    = score
                };
                votes.Add(gv);
            }

            // Now need to order
            var orderedVotes = votes.OrderByDescending(x => x.Score);

            // Now need to go through and save the recxords
            int votesAwarded = 3;

            foreach (var vote in orderedVotes)
            {
                if (votesAwarded > 0)
                {
                    var existing = await _context.DpoyVoting.FirstOrDefaultAsync(x => x.PlayerId == vote.PlayerId);

                    if (existing == null)
                    {
                        DpoyVote dpoy = new DpoyVote
                        {
                            PlayerId = vote.PlayerId,
                            Votes    = votesAwarded
                        };
                        await _context.AddAsync(dpoy);

                        await _context.SaveChangesAsync();
                    }
                    else
                    {
                        int totalVotes = existing.Votes + votesAwarded;
                        existing.Votes = totalVotes;
                        _context.Update(existing);
                        await _context.SaveChangesAsync();
                    }
                    votesAwarded--;
                }
                else
                {
                    break;
                }
            }
            return(true);
        }