コード例 #1
0
        public static int Save(GameDescription gameToSave)
        {
            int returnValue;
            returnValue = GameDescriptionDAL.Save(gameToSave);

            return returnValue;
        }
コード例 #2
0
        //INSERT
        public static int Save(GameDescription gameDescriptionToSave)
        {
            ExecuteTypeEnum queryId = ExecuteTypeEnum.InsertItem;
            int result = 0;

            if (gameDescriptionToSave.GameDescriptionId > 0)
            {
                queryId = ExecuteTypeEnum.UpdateItem;
            }

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

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

                    if (gameDescriptionToSave.HowToPlay != null)
                    {
                        myCommand.Parameters.AddWithValue("@HowToPlay", gameDescriptionToSave.HowToPlay);
                    }
                    if (gameDescriptionToSave.GameDescript != null)
                    {
                        myCommand.Parameters.AddWithValue("@GameDescription", gameDescriptionToSave.GameDescript);
                    }
                    if (gameDescriptionToSave.GameCost != null)
                    {
                        myCommand.Parameters.AddWithValue("@GameCost", gameDescriptionToSave.GameCost);
                    }
                    if (gameDescriptionToSave.NumberOfBalls != null)
                    {
                        myCommand.Parameters.AddWithValue("@NumberOfBalls", gameDescriptionToSave.NumberOfBalls);
                    }
                    if (gameDescriptionToSave.SpecialBall != null)
                    {
                        myCommand.Parameters.AddWithValue("@SpecialBall", gameDescriptionToSave.SpecialBall);
                    }

                    //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;
        }