Пример #1
0
        //------------------------------------------------------------------------------------------------------
        #endregion

        #region /*--------- Create ---------*\
        //------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Converts the  object properties to SQL paramters and executes the create  procedure 
        /// and updates the object with the SQL data by reference.
        /// </summary>
        /// <param name="ContentBlocksObj">Model object.</param>
        /// <returns>The result of create query.</returns>
        //--------------------------------------------------------------------
        public bool Create(ContentBlocksModel ContentBlocksObj)
        {
            bool result = false;
            using (SqlConnection myConnection = GetSqlConnection())
            {
                SqlCommand myCommand = new SqlCommand("[dbo].[ContentBlocks_Create]", myConnection);
                myCommand.CommandType = CommandType.StoredProcedure;
                //----------------------------------------------------------------------------------------------
                // Set the parameters
                //----------------------------------------------------------------------------------------------
				myCommand.Parameters.Add("@BlockID", SqlDbType.Int, 4).Value = ContentBlocksObj.BlockID;
				myCommand.Parameters.Add("@BlocKey", SqlDbType.NVarChar, 64).Value = ContentBlocksObj.BlocKey;

                //----------------------------------------------------------------------------------------------
                // Execute the command
                //----------------------------------------------------------------------------------------------
                myConnection.Open();
                if (myCommand.ExecuteNonQuery() > 0)
                {
                    result = true;
                    //Get ID value from database and set it in object

                }
                myConnection.Close();
                return result;
                //----------------------------------------------------------------------------------------------
            }
        }
Пример #2
0
        //------------------------------------------------------------------------------------------------------
        #endregion

        #region --------------GetObject--------------
        //------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the spesific record.
        /// </summary>
        /// <param name="ID">The model id.</param>
        /// <returns>Model object.</returns>
        //--------------------------------------------------------------------
        public static ContentBlocksModel GetObject(int BlockID)
        {
            ContentBlocksModel        ContentBlocksObj = null;
            List <ContentBlocksModel> list             = ContentBlocksSqlDataPrvider.Instance.Get(BlockID);

            if (list != null && list.Count > 0)
            {
                ContentBlocksObj = list[0];
            }
            return(ContentBlocksObj);
        }
Пример #3
0
        //------------------------------------------------------------------------------------------------------
        #endregion

        #region /*--------- PopulateModelFromIDataReader ---------*\
        //------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Populates model from IDataReader .
        /// </summary>
        /// <param name="reader"></param>
        /// <returns>Model object.</returns>
        //--------------------------------------------------------------------
        private ContentBlocksModel PopulateModelFromIDataReader(IDataReader reader)
        {
            //Create a new object
            ContentBlocksModel ContentBlocksObj = new ContentBlocksModel();
            //Fill the object with data

			//------------------------------------------------
			//[BlockID]
			//------------------------------------------------
			if (reader["BlockID"] != DBNull.Value)
			    ContentBlocksObj.BlockID = (int)reader["BlockID"];
			//------------------------------------------------
			//------------------------------------------------
			//[BlocKey]
			//------------------------------------------------
			if (reader["BlocKey"] != DBNull.Value)
			    ContentBlocksObj.BlocKey = (string)reader["BlocKey"];
			//------------------------------------------------
            //Return the populated object
            return ContentBlocksObj;
        }
Пример #4
0
        //------------------------------------------------------------------------------------------------------
        #endregion

        #region --------------Update--------------
        //------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Updates model object by calling sql data provider update method.
        /// </summary>
        /// <param name="ContentBlocksObj">The model object.</param>
        /// <returns>The result of update operation.</returns>
        //--------------------------------------------------------------------
        public static bool Update(ContentBlocksModel ContentBlocksObj)
        {
            return(ContentBlocksSqlDataPrvider.Instance.Update(ContentBlocksObj));
        }