Exemplo n.º 1
0
        public void PopulatePlayers()
        {
            using (var _context = new CrapsContext())
            {
                var PlayerNames = _context.Player.Select(x => new ComboBoxItem()
                {
                    Text  = x.Name,
                    Value = x.PlayerId
                }).ToList();

                //Adding one here to handle the default value without outOfRanging in the for loop
                ComboBoxItem[] _dataSource = new ComboBoxItem[PlayerNames.Count() + 1];

                _dataSource[0] = new ComboBoxItem {
                    Text = "Please select a player.", Value = 9999999
                };

                for (var i = 1; i <= PlayerNames.Count(); i++)
                {
                    _dataSource[i] = PlayerNames[i - 1];
                }

                accountDropDown.DisplayMember = "Text";
                accountDropDown.ValueMember   = "Value";
                accountDropDown.DataSource    = _dataSource;
                accountDropDown.SelectedIndex = 0;
            }
        }
Exemplo n.º 2
0
 public void FinalizeRoundRolls()
 {
     using (var _context = new CrapsContext())
     {
         _context.Rolls.AddRange(Rolls);
         _context.SaveChanges();
         Rolls = new List <Rolls>();
     }
 }
Exemplo n.º 3
0
        private void EditButton_Click(object sender, EventArgs e)
        {
            using (var _context = new CrapsContext())
            {
                var playerToEdit = _context.Player.Where(x => x.PlayerId == SelectedPlayerId).FirstOrDefault();

                playerToEdit.Name = accountDropDown.Text;
                _context.SaveChanges();
                MessageBox.Show("Player Edited");
                PopulatePlayers();
            }
        }
Exemplo n.º 4
0
        private void DeleteButton_Click(object sender, EventArgs e)
        {
            using (var _context = new CrapsContext())
            {
                var playerToDelete = _context.Player.Where(x => x.PlayerId == SelectedPlayerId).FirstOrDefault();

                _context.Player.Remove(playerToDelete);
                _context.SaveChanges();
                MessageBox.Show("Player Removed");
                PopulatePlayers();
            }
        }
Exemplo n.º 5
0
        public void UpdateRound(RoundOutcome outcome)
        {
            using (var _context = new CrapsContext())
            {
                var currentRound = _context.Round.Where(d => d.RoundId == (int)CurrentRoundId).FirstOrDefault();
                currentRound.Outcome = outcome;
                _context.SaveChanges();
            }

            FinalizeRoundRolls();
            CurrentRoundId = null;
        }
Exemplo n.º 6
0
        public void CreateRound()
        {
            var round = new Round()
            {
                GameId = GameId
            };

            using (var _context = new CrapsContext())
            {
                _context.Round.Add(round);
                _context.SaveChanges();
                CurrentRoundId = round.RoundId;
            }
        }
Exemplo n.º 7
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            Player playerToAdd = new Player
            {
                Name     = accountDropDown.Text,
                Password = "******"
            };

            using (var _context = new CrapsContext())
            {
                _context.Player.Add(playerToAdd);
                _context.SaveChanges();
                PlayerID = playerToAdd.PlayerId;
                MessageBox.Show("Player Added");
                PopulatePlayers();
            }
        }
Exemplo n.º 8
0
        public void NewGame()
        {
            isFirstRoll     = true;
            isFirstRound    = true;
            isGameOver      = false;
            rollButton.Text = "Roll";
            label1.Text     = "";
            label2.Text     = "";
            pointSet        = 0;

            Game newGame = new Game
            {
                PlayerId = SelectedPlayerId,
            };

            using (var _context = new CrapsContext())
            {
                _context.Game.Add(newGame);
                _context.SaveChanges();
                GameId = newGame.GameId;
            }
        }