Exemplo n.º 1
0
        public IEnumerable<Game> GetGames(string userName)
        {
            try
            {
                var results = (from g in _context.Games
                               join s in _context.Stats.Where(t => t.Player == userName)
                                on g.Order equals s.GameNumber into tbl
                               from od in tbl.DefaultIfEmpty()
                               where od == null
                               select new
                               {
                                   g.Id,
                                   g.Order,
                                   g.Opponent,
                                   od
                               }).ToList();
                var games = new List<Game>();
                foreach (var item in results)
                {
                    var newGame = new Game();
                    newGame.Id = item.Id;
                    newGame.Opponent = item.Opponent;
                    newGame.Order = item.Order;
                    games.Add(newGame);
                }

                return games;

                //return _context.Games
                //   .OrderBy(t => t.Order)
                //   .ToList();
            }
            catch (Exception ex)
            {

                _logger.LogError("Could not get games from database.", ex);
                return null;
            }
        }
Exemplo n.º 2
0
        public async Task EnsureSeedDataAsync()
        {
            if (await _userManager.FindByEmailAsync("*****@*****.**") == null)
            {
                var newPlayer = new Player()
                {
                    UserName = "******",
                    Email = "*****@*****.**",
                    HeightFeet = 6,
                    HeightInches = 4,
                    Position = "Shooting Guard"
                };
                await _userManager.CreateAsync(newPlayer, "P@ssw0rd!");
            }

            if (!_context.Games.Any())
            {
                var game1 = new Game()
                {
                    Order = 1,
                    Opponent = "Warriors"
                };
                _context.Games.Add(game1);
                var game2 = new Game()
                {
                    Order = 2,
                    Opponent = "Spurs"
                };
                _context.Games.Add(game2);
                var game3 = new Game()
                {
                    Order = 3,
                    Opponent = "Bulls"
                };
                _context.Games.Add(game3);
                _context.SaveChanges();
            }

            if (!_context.Stats.Any())
            {
                var statLine1 = new StatLine()
                {
                    GameNumber = 1,
                    Opponent = "Warriors",
                    Player = "jasonholdridge",
                    Points = 11,
                    FieldGoals = 3,
                    FieldGoalsAttempted = 5,
                    FGPercentage = 0.6,
                    Assists = 2,
                    Rebounds = 8
                };
                _context.Stats.Add(statLine1);
                var statLine2 = new StatLine()
                {
                    GameNumber = 2,
                    Opponent = "Spurs",
                    Player = "jasonholdridge",
                    Points = 25,
                    FieldGoals = 12,
                    FieldGoalsAttempted = 36,
                    FGPercentage = 0.333,
                    Assists = 1,
                    Rebounds = 15
                };
                _context.Stats.Add(statLine2);
                var statLine3 = new StatLine()
                {
                    GameNumber = 3,
                    Opponent = "Bulls",
                    Player = "stevesmith",
                    Points = 18,
                    FieldGoals = 5,
                    FieldGoalsAttempted = 10,
                    FGPercentage = 0.5,
                    Assists = 5,
                    Rebounds = 17
                };
                _context.Stats.Add(statLine3);
                _context.SaveChanges();
            }
        }
Exemplo n.º 3
0
 public void AddGame(Game newGame)
 {
     _context.Add(newGame);
 }