Esempio n. 1
0
        //INSERT
        public static int Save(GameBO gameToSave)
        {
            ExecuteTypeEnum queryId = ExecuteTypeEnum.InsertItem;
            int result = 0;

            if (gameToSave.GameId > 0)
            {
                queryId = ExecuteTypeEnum.UpdateItem;
            }

            using (SqlConnection myConnection = new SqlConnection(AppConfiguration.ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("usp_ExecuteGame", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

                    myCommand.Parameters.AddWithValue("@QueryId", queryId);
                    myCommand.Parameters.AddWithValue("@GameId", gameToSave.GameId);

                    if (gameToSave.GameName != null)
                    {
                        myCommand.Parameters.AddWithValue("@GameName", gameToSave.GameName);
                    }

                    //add return output parameter to command object
                    myCommand.Parameters.Add(HelperDAL.GetReturnParameterInt("ReturnValue"));

                    //Opens connection and executes query
                    myConnection.Open();
                    myCommand.ExecuteNonQuery();

                    //Get return value from stored procedure and return Id
                    result = Convert.ToInt32(myCommand.Parameters["@ReturnValue"].Value);

                }
                myConnection.Close();
            }
            return result;
        }
Esempio n. 2
0
        /// <Summary Fill Data Record>
        /// Initializes a new instance of the Game class and fills it with the data from the IDataRecord
        /// </summary>
        /// <param name="myDataRecord"></param>
        /// <returns></returns>
        private static GameBO FillDataRecord(IDataRecord myDataRecord)
        {
            GameBO myGameObject = new GameBO();
            myGameObject.GameDescription = new GameDescription();

            myGameObject.GameId = myDataRecord.GetInt32(myDataRecord.GetOrdinal("GameId"));

            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("GameName")))
            {
                myGameObject.GameName = myDataRecord.GetString(myDataRecord.GetOrdinal("GameName"));
            }
            return myGameObject;
        }
        /// <Summary Fill Data Record>
        /// Initializes a new instance of the Game class and fills it with the data from the IDataRecord
        /// </summary>
        /// <param name="myDataRecord"></param>
        /// <returns></returns>
        private static GameBO FillDataRecord(IDataRecord myDataRecord)
        {
            GameBO myGameObject = new GameBO();
            myGameObject.GameDescription = new GameDescription();

            myGameObject.GameId = myDataRecord.GetInt32(myDataRecord.GetOrdinal("GameId"));

            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("GameName")))
            {
                myGameObject.GameName = myDataRecord.GetString(myDataRecord.GetOrdinal("GameName"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("GameDescriptionId")))
            {
                myGameObject.GameDescription.GameDescriptionId = myDataRecord.GetInt32(myDataRecord.GetOrdinal("GameDescriptionId"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("HowToPlay")))
            {
                myGameObject.GameDescription.HowToPlay = myDataRecord.GetString(myDataRecord.GetOrdinal("HowToPlay"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("GameDescription")))
            {
                myGameObject.GameDescription.GameDescript = myDataRecord.GetString(myDataRecord.GetOrdinal("GameDescription"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("GameCost")))
            {
                myGameObject.GameDescription.GameCost = myDataRecord.GetInt32(myDataRecord.GetOrdinal("GameCost"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("NumberOfBalls")))
            {
                myGameObject.GameDescription.NumberOfBalls = myDataRecord.GetInt32(myDataRecord.GetOrdinal("NumberOfBalls"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("SpecialBall")))
            {
                myGameObject.GameDescription.SpecialBall = myDataRecord.GetInt32(myDataRecord.GetOrdinal("SpecialBall"));
            }
            return myGameObject;
        }