Ejemplo n.º 1
0
        public static Game GetGameById(int id)
        {
            var  db = new GolfDB();
            Game g  = db.Games.Where(v => v.UserId.UserId == id).SingleOrDefault();

            return(g);
        }
Ejemplo n.º 2
0
        public static List <Game> GetAllGamesByUser(int id)
        {
            var         db    = new GolfDB();
            List <Game> games = db.Games.Include("UserId").Where(g => g.UserId.UserId == id).ToList();

            return(games);
        }
Ejemplo n.º 3
0
        private void btnSaveUser_Click(object sender, EventArgs e)
        {
            GolfDB db = new GolfDB();

            //create user to be saved
            User user = new User();


            //check to see if user is already present by username
            User testUser = DBHelper.GetUserByUsername(txtUsername.Text);

            if (testUser == null)
            {
                User saveUser = new User();
                saveUser.Username = txtUsername.Text;
                saveUser.Password = txtPassword.Text;

                db.Users.Add(saveUser);
                if (db.SaveChanges() == 1)
                {
                    MessageBox.Show("User saved!");
                }
            }
            else
            {
                MessageBox.Show("User already exists!");
            }
        }
Ejemplo n.º 4
0
        public static User GetUserByUsername(string username)
        {
            //create golf database context
            var db = new GolfDB();

            //search for user.  user will be set to null if not found
            User user = db.Users.Where(u => u.Username == username).SingleOrDefault();

            return(user);
        }
        private void IndividualPlayerStats_Load(object sender, EventArgs e)
        {
            GolfDB      dB    = new GolfDB();
            Game        g     = dB.Games.Include("Holes").Where(a => a.GameId == gameId).SingleOrDefault();
            List <Hole> holes = g.Holes;
            int         count = 1;

            foreach (Hole H in holes)
            {
                this.chart1.Series[""].Points.AddXY(count, H.Par);
                this.chart1.Series[""].Points.AddXY(count, H.TotalShots);
                count++;
            }
        }
Ejemplo n.º 6
0
        private void btnFinishGame_Click(object sender, EventArgs e)
        {
            var db = new GolfDB();

            db.Users.Attach(game.UserId);

            db.Games.Add(game);

            if (db.SaveChanges() == 1)
            {
                MessageBox.Show("Game saved!");
            }
            else
            {
                MessageBox.Show("Something went wrong.");
            }
        }
Ejemplo n.º 7
0
        private void btnSaveUser_Click(object sender, EventArgs e)
        {
            //create new golfDB to connect to DB?
            GolfDB db = new GolfDB();

            //create user to be saved
            User user = new User();


            if (txtPassword.Text != txtPassConfirmation.Text)
            {
                txtPassNotMatched.Visible = true;
            }

            else if (txtPassword.Text == txtPassConfirmation.Text && txtPassword.Text.Length >= 6)
            {
                //check to see if user is already present by username
                User testUser = DBHelper.GetUserByUsername(txtUsername.Text);
                if (testUser == null)
                {
                    User saveUser = new User();
                    saveUser.Username = txtUsername.Text;
                    saveUser.Password = txtPassword.Text;

                    db.Users.Add(saveUser);
                    if (db.SaveChanges() == 1)
                    {
                        MessageBox.Show("User saved!");
                    }
                }
                else
                {
                    MessageBox.Show("User already exists!");
                }
            }
            else
            {
                lblPassCharacter.Visible = true;
            }
        }