Exemple #1
0
        private GameCode(string code, int game)
        {
            Id = DbGameCodes.InsertCode(code, game);

            Code   = code;
            GameId = game;

            Used         = false;
            RedeemedById = -1;
        }
Exemple #2
0
        /// <summary>
        /// Redeems a code for a user and gives him the game
        /// </summary>
        /// <param name="user">id of user</param>
        /// <param name="code">code string</param>
        /// <returns>-1 if code was already redeemed or invalid else the id of the game that user bought</returns>
        public static int RedeemCode(int user, string code)
        {
            if (!DbGameCodes.CodeUnredeemed(code))
            {
                return(-1);
            }
            if (!DbGameCodes.UseGameCode(code, user))
            {
                return(-1);
            }

            int game = DbGameCodes.GetGameFromCode(code);

            UserGame.AddGame(user, game, 0);

            return(game);
        }