Beispiel #1
0
        public void SaveMatchupsForWeek([FromBody] Object gameWeeks)
        {
            var       jsonString = gameWeeks.ToString();
            GameWeeks result     = JsonConvert.DeserializeObject <GameWeeks>(jsonString);

            GameRepo.SaveGamesForWeek(result);
        }
Beispiel #2
0
 public ServiceAll(PlayerRepo pr, GameRepo gr, ActivePlayerRepo apr, TeamRepo tr)
 {
     playerRepo       = pr;
     gameRepo         = gr;
     activePlayerRepo = apr;
     teamRepo         = tr;
 }
Beispiel #3
0
        public override void Update(PlayerGame playerGame)
        {
            PlayerRepo pr = new PlayerRepo();
            TeamRepo   tr = new TeamRepo();
            GameRepo   gr = new GameRepo();

            if (null != pr.FindBy(p => p.UserName == playerGame.Player.UserName).FirstOrDefault())
            {
                pr.Add(playerGame.Player);
                pr.Save();
            }

            if (null != tr.FindBy(p => p.Id == playerGame.Team.Id).FirstOrDefault())
            {
                tr.Add(playerGame.Team);
                tr.Save();
            }
            if (null != gr.FindBy(g => g.Name == playerGame.GameName).FirstOrDefault())
            {
                gr.Add(playerGame.Game);
                gr.Save();
            }

            Context.PlayerGames.Update(playerGame);
            Save();
        }
        public ActionResult Create(OrderModel order, ICollection <OrderGamesImp> placeholder)
        {
            try
            {
                var stores = _db.Stores.ToList();
                stores.AddRange(_db.Stores.ToList());
                order.Stores = new List <StoreImp>();

                if (order.Stores == null)
                {
                    foreach (var s in stores)
                    {
                        var tempStore = new StoreImp
                        {
                            IDNumber      = s.StoreId,
                            Location      = s.Location,
                            DeluxeInStock = s.DeluxePackageRemaining,
                            //Items = Mapper.Map(s.Inventory.First(i => i.StoreId == order.OrderStoreId)),
                        };
                        order.Stores.Add(tempStore);
                    }
                }


                // TODO: Add insert logic here
                var ord = new OrderImp
                {
                    StoreId   = order.OrderStoreId,
                    OrderDate = DateTime.Now,
                };

                ord.GamesInOrder = new List <OrderGamesImp>();
                ord.GamesInOrder = order.OrderGames;
                ord.OrderCost    = 0.00m;
                for (int i = 0; i < ord.GamesInOrder.Count; i++)
                {
                    ord.GamesInOrder[i].Game = GameRepo.GetGameById(ord.GamesInOrder[i].GameId);
                    //ord.OrderCost += item.Price;
                }
                ord.OrderCost = ord.TotalOrderCost();

                if (TempData.ContainsKey("Current Customer"))
                {
                    ord.OrderCustomer = int.Parse(TempData.Peek("Current Customer").ToString());
                }
                Repo.AddOrder(ord);

                foreach (var item in ord.GamesInOrder)
                {
                    Repo.AddOrderItem(item);
                }

                return(RedirectToAction("Index", "Orders"));
            }
            catch (InvalidOperationException ex)
            {
                return(RedirectToAction("Index", "Orders"));
            }
        }
Beispiel #5
0
 public GameService(IPlayParser playReader, GameRepo gameRepo, PlayerRepo playerRepo, IUserService userRepo, IPlayService playerService)
 {
     _gameRepo     = gameRepo;
     _playerRepo   = playerRepo;
     _userRepo     = userRepo;
     _playReader   = playReader;
     _playsService = playerService;
 }
Beispiel #6
0
        public UnitOfWork(DataContext context)
        {
            _context = context;

            Games   = new GameRepo(_context);
            Players = new PlayerRepo(_context);
            Moves   = new MoveRepo(_context);
        }
Beispiel #7
0
        public bool StoreResults(string name)
        {
            if (!GameOver)
            {
                throw new GameException("Game is not over yet");
            }
            bool stored = GameRepo.StoreInformation(name, Target, Attempts);

            return(stored);
        }
Beispiel #8
0
        private bool SaveGame(Game game)
        {
            if (game.IsTournamentGame)
            {
                TournamentRepo.AddTournamentGame(game);
            }

            Console.WriteLine("Saving game to database");
            return(GameRepo.SaveGame(game));
        }
Beispiel #9
0
 static void Main(string[] args)
 {
     var gameRepo       = new GameRepo();
     var matchRepo      = new MatchRepo();
     var playerGameRepo = new PlayerGameRepo();
     var playerRepo     = new PlayerRepo();
     var playerStats    = new PlayerStatsRepo();
     var teamRepo       = new TeamRepo();
     var teamMatchReop  = new TeamMatchRepo();
     var TournamentRepo = new TournamentRepo();
 }
Beispiel #10
0
        public static List <Game> GetGamesForWeek(int week, int year)
        {
            var games = GameRepo.GetGamesForWeek(week, year);
            var teams = TeamRepo.GetTeams();

            foreach (var game in games)
            {
                game.HomeTeam = teams.GetValueOrDefault(game.HomeId);
                game.AwayTeam = teams.GetValueOrDefault(game.AwayId);
            }

            return(games);
        }
        public ActionResult AddGames(OrderModel Order, ICollection <OrderImp> placeholder)
        {
            if (Order.OrderGames == null)
            {
                Order.OrderGames = new List <OrderGamesImp>();
            }

            Order.NextOrderGame.Game      = GameRepo.GetGameById(Order.NextOrderGame.GameId);
            Order.NextOrderGame.Price     = Order.NextOrderGame.GetCostOfPurchase();
            Order.NextOrderGame.Game.Name = Order.NextOrderGame.Game.Name;
            Order.NextOrderGame.OrderId   = _db.Orders.Max(o => o.OrderId) + 1;

            //var OrderItems = new List<OrderGames>();
            //OrderItems.AddRange(_db.OrderGames.Where(o => o.OrderId == _db.Orders.Max(r => r.OrderId) + 1).ToList());

            if (TempData.ContainsKey("Current Customer")) //populates the fields'  initial values
            {
                CustomerImp cust = CustomerRepo.GetCustomerById(int.Parse(TempData.Peek("Current Customer").ToString()));
                Order.OrderStoreId    = StoreRepo.GetStoreByLocation(cust.DefaultStoreId).IDNumber;
                Order.OrderDate       = DateTime.Now;
                Order.OrderCustomerId = int.Parse(TempData.Peek("Current Customer").ToString());
                Order.OrderId         = _db.Orders.Max(o => o.OrderId) + 1;
            }

            Order.OrderCost = Order.NextOrderGame.Price + Order.OrderCost;
            Order.OrderGames.Add(Order.NextOrderGame);

            if (Order.Stores == null)
            {
                var stores = _db.Stores.ToList();
                Order.Stores = new List <StoreImp>();

                foreach (var s in stores)
                {
                    var tempStore = new StoreImp
                    {
                        IDNumber      = s.StoreId,
                        Location      = s.Location,
                        DeluxeInStock = s.DeluxePackageRemaining,
                        //Items = Mapper.Map(s.Inventory.First(i => i.StoreId == order.OrderStoreId)),
                    };
                    Order.Stores.Add(tempStore);
                }
            }

            return(View("Create", Order));
        }
        // GET: Orders/AddGames
        public ActionResult AddGames(OrderModel Order)
        {
            Order.Games = GameRepo.GetAllGames().ToList();

            Order.Editions = new Dictionary <int, string>();
            Order.Editions.Add(1, "Standard Edition");
            Order.Editions.Add(2, "Advanced Edition");
            Order.Editions.Add(3, "Deluxe Edition");

            Order.NextOrderGame = new OrderGamesImp
            {
                Price   = 19.99m,
                Edition = 1,
                GameId  = 2
            };

            if (Order.OrderGames == null)
            {
                Order.OrderGames = new List <OrderGamesImp>();
            }

            return(View(Order));
        }
Beispiel #13
0
 public GamesController(GameRepo gameRepo)
 {
     _gameRepo = gameRepo;
 }
Beispiel #14
0
 public HomePageController()
 {
     _gameRepo = new GameRepo();
 }
Beispiel #15
0
 /// <summary>
 /// Controller ofr the Challenge table
 /// </summary>
 /// <param name="challengeRepo"></param>
 /// <param name="gameRepo"></param>
 /// <param name="playerRepo"></param>
 public ChallengeController(ChallengeRepo challengeRepo, GameRepo gameRepo, PlayerRepo playerRepo) : base(playerRepo)
 {
     _challengeRepo = challengeRepo;
     _gameRepo      = gameRepo;
 }
Beispiel #16
0
 public static bool IsWeekLocked(int week, int year)
 {
     return(GameRepo.IsWeekLocked(week, year));
 }
Beispiel #17
0
        public static ResultsResponse GetResultsForWeek(int week, int year)
        {
            var result     = new ResultsResponse();
            var resultRows = new List <ResultsRow>();

            var users    = UserRepo.GetUsers();
            var games    = GameRepo.GetGamesForWeek(week, year);
            var teams    = TeamRepo.GetTeams();
            var matchups = ScheduleRepo.GetMatchupsForWeek(week, year);

            foreach (var game in games)
            {
                game.HomeTeam = teams.GetValueOrDefault(game.HomeId);
                game.AwayTeam = teams.GetValueOrDefault(game.AwayId);
                game.DateTime = matchups.Where(x => x.HomeTeamID == game.HomeId).Select(x => x.DateTime).FirstOrDefault();
                game.Day      = matchups.Where(x => x.HomeTeamID == game.HomeId).Select(x => x.Day).FirstOrDefault();

                if (game.Outcome == "Home")
                {
                    game.HomeTeam.Outcome = "Win";
                    game.AwayTeam.Outcome = "Lose";
                }
                else if (game.Outcome == "Away")
                {
                    game.AwayTeam.Outcome = "Win";
                    game.HomeTeam.Outcome = "Lose";
                }
            }

            foreach (var user in users)
            {
                if (user.Picks != null)
                {
                    var pick = user.Picks.Where(x => x.WeekNum == week && x.Year == year).FirstOrDefault();
                    if (pick != null)
                    {
                        var prevPick = new Pick();
                        if (week == 1)
                        {
                            prevPick = pick;
                        }
                        else
                        {
                            prevPick = user.Picks.Where(x => x.WeekNum == week - 1 && x.Year == year).FirstOrDefault();
                        }

                        var userTeams = new List <Team>();

                        foreach (var game in pick.Winners)
                        {
                            userTeams.Add(teams[game]);
                        }

                        user.Password = "";
                        user.Picks    = null;

                        resultRows.Add(new ResultsRow()
                        {
                            BestBetId = pick.BestBet,
                            Rank      = prevPick.Rank,
                            Teams     = userTeams,
                            User      = user
                        });
                    }
                }
            }

            result.Rows = resultRows.OrderBy(x => x.Rank).ToList();

            result.Games = games;

            return(result);
        }
 public void Setup()
 {
     _testRepo = new GameRepo();
     _gameService = new GameService(_testRepo);
 }
 /// <summary>
 /// Controller for the Game table
 /// </summary>
 /// <param name="gameRepo"></param>
 /// <param name="boardRepo"></param>
 /// <param name="playerRepo"></param>
 public GameController(GameRepo gameRepo, BoardRepo boardRepo, PlayerRepo playerRepo) : base(playerRepo)
 {
     _playerRepo = playerRepo;
     _gameRepo   = gameRepo;
 }
Beispiel #20
0
        public static void ScoreGamesForWeek(int week, int year)
        {
            var users        = UserRepo.GetUsers();
            var gamesForWeek = GameRepo.GetGamesForWeek(week, year);

            var winnersPicked = new Dictionary <int, int>();
            var usersScores   = new List <UserPoints>();

            // Fill up the winners picked dictionary
            foreach (var user in users)
            {
                Pick pick = null;
                if (user.Picks != null)
                {
                    pick = user.Picks.Where(x => x.Year == year && x.WeekNum == week).FirstOrDefault();
                }
                else
                {
                    user.Picks = new List <Pick>();
                }

                if (pick == null)
                {
                    // Select all the Home Teams
                    var winners = gamesForWeek.Select(x => x.HomeId).ToList();
                    pick = new Pick()
                    {
                        Correct = 0,
                        Points  = 0,
                        Rank    = 0,
                        BestBet = -1,
                        WeekNum = week,
                        Year    = year,
                        Winners = winners
                    };

                    user.Picks.Add(pick);
                }

                foreach (int winner in pick.Winners)
                {
                    if (winnersPicked.ContainsKey(winner))
                    {
                        winnersPicked[winner]++;
                    }
                    else
                    {
                        winnersPicked.Add(winner, 1);
                    }
                }
            }

            // Score each user, if user does not have a pick then default them to the home teams
            foreach (var user in users)
            {
                var pick = user.Picks.Where(x => x.Year == year && x.WeekNum == week).FirstOrDefault();

                // Reset user to 0 points
                pick.Correct = 0;
                pick.Points  = 0;
                pick.Total   = 0;

                foreach (var game in gamesForWeek)
                {
                    if (game.Outcome == "Home")
                    {
                        if (pick.Winners.Contains(game.HomeId))
                        {
                            if (!winnersPicked.TryGetValue(game.AwayId, out int oppPoints))
                            {
                                oppPoints = 0;
                            }

                            double points = (users.Count + oppPoints) * game.Multiplier;

                            if (game.HomeId == pick.BestBet)
                            {
                                points = points * 2;
                            }

                            pick.Points = pick.Points + points;

                            pick.Correct++;
                        }
                        pick.Total++;
                    }
                    else if (game.Outcome == "Away")
                    {
                        if (pick.Winners.Contains(game.AwayId))
                        {
                            if (!winnersPicked.TryGetValue(game.HomeId, out int oppPoints))
                            {
                                oppPoints = 0;
                            }

                            double points = (users.Count + oppPoints) * game.Multiplier;

                            if (game.AwayId == pick.BestBet)
                            {
                                points = points * 2;
                            }

                            pick.Points = pick.Points + points;

                            pick.Correct++;
                        }
                        pick.Total++;
                    }
                }

                double totalPoint = user.Picks.Where(x => x.WeekNum <= week && x.Year == year).Sum(x => x.Points);

                usersScores.Add(new UserPoints()
                {
                    Email  = user.Email,
                    Points = totalPoint
                });
            }

            // Calculate the Rankings
            usersScores = usersScores.OrderByDescending(n => n.Points).Select((n, index) => new UserPoints()
            {
                Email  = n.Email,
                Points = n.Points,
                Rank   = index + 1
            }).ToList();

            // Update rank
            foreach (var user in users)
            {
                var pick = user.Picks.Where(x => x.Year == year && x.WeekNum == week).FirstOrDefault();
                pick.Rank = usersScores.Where(x => x.Email == user.Email).Select(x => x.Rank).FirstOrDefault();
                UserRepo.SaveUser(user);
            }
        }
 public GameListService(GameRepo gameRepo, IUserService userRepo)
 {
     _gameRepo = gameRepo;
     _userRepo = userRepo;
 }