示例#1
0
        //Update

        public void UpdateScore(int GameID, int userID, int points, int time)
        {
            if (GameID == 0)
            {
                throw new Exception("The ID of the game cannot be 0");
            }
            if (userID == 0)
            {
                throw new Exception("The ID of the user cannot be 0");
            }
            if (points == 0)
            {
                throw new Exception("Time cannot be 0");
            }
            if (time == 0)
            {
                throw new Exception("Points cannot be 0");
            }
            if (dbContext.Game.Where(g => g.ID == GameID).Count() == 0)
            {
                throw new Exception("There is no record of that game!");
            }
            if (dbContext.User.Where(u => u.ID == userID).Count() == 0)
            {
                throw new Exception("There is no record of that user!");
            }

            Models.DataModels.HighScore highScore = dbContext.HighScore.Where(hs => hs.GameID == GameID && hs.UserID == userID).First();
            if (highScore.Points < points)
            {
                highScore.Points = points;
                highScore.Time   = time;
                dbContext.SaveChanges();
                //SQL.Update("UPDATE `highscore` SET `points` = '" + points.ToString() + "', `time` = '" + time.ToString() + "' WHERE `gameID` = '" + GameID.ToString() + "' AND `userID` = '" + userID.ToString() + "'");
            }

            dbContext.SaveChanges();
        }
示例#2
0
        //Update

        public void UpdateScore(int GameID, int UserID, int Points, int Time)
        {
            if (GameID == 0)
            {
                throw new Exception("The ID of the Game cannot be 0");
            }
            if (UserID == 0)
            {
                throw new Exception("The ID of the user cannot be 0");
            }
            if (Points == 0)
            {
                throw new Exception("Time cannot be 0");
            }
            if (Time == 0)
            {
                throw new Exception("Points cannot be 0");
            }
            if (_dbContext.Game.Where(g => g.ID == GameID).Count() == 0)
            {
                throw new Exception("There is no record of that Game!");
            }
            if (_dbContext.User.Where(u => u.ID == UserID).Count() == 0)
            {
                throw new Exception("There is no record of that user!");
            }

            Models.DataModels.HighScore HighScore = _dbContext.HighScore.Where(hs => hs.GameID == GameID && hs.UserID == UserID).First();
            if (HighScore.Points < Points)
            {
                HighScore.Points = Points;
                HighScore.Time   = Time;
                _dbContext.SaveChanges();
            }

            _dbContext.SaveChanges();
        }