Пример #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="ImagesWithBlocksObj">Model object.</param>
        /// <returns>The result of create query.</returns>
        //--------------------------------------------------------------------
        public bool Create(ImagesWithBlocksModel ImagesWithBlocksObj)
        {
            bool result = false;
            using (SqlConnection myConnection = GetSqlConnection())
            {
                SqlCommand myCommand = new SqlCommand("[dbo].[ImagesWithBlocks_Create]", myConnection);
                myCommand.CommandType = CommandType.StoredProcedure;
                //----------------------------------------------------------------------------------------------
                // Set the parameters
                //----------------------------------------------------------------------------------------------
				myCommand.Parameters.Add("@ID", SqlDbType.Int, 4).Direction = ParameterDirection.Output;
				myCommand.Parameters.Add("@ImageID", SqlDbType.Int, 4).Value = ImagesWithBlocksObj.ImageID;
				myCommand.Parameters.Add("@BlocKey", SqlDbType.NVarChar, 64).Value = ImagesWithBlocksObj.BlocKey;

                //----------------------------------------------------------------------------------------------
                // Execute the command
                //----------------------------------------------------------------------------------------------
                myConnection.Open();
                if (myCommand.ExecuteNonQuery() > 0)
                {
                    result = true;
                    //Get ID value from database and set it in object
				ImagesWithBlocksObj.ID = (int)myCommand.Parameters["@ID"].Value;

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

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

			//------------------------------------------------
			//[ID]
			//------------------------------------------------
			if (reader["ID"] != DBNull.Value)
			    ImagesWithBlocksObj.ID = (int)reader["ID"];
			//------------------------------------------------
			//------------------------------------------------
			//[ImageID]
			//------------------------------------------------
			if (reader["ImageID"] != DBNull.Value)
			    ImagesWithBlocksObj.ImageID = (int)reader["ImageID"];
			//------------------------------------------------
			//------------------------------------------------
			//[BlocKey]
			//------------------------------------------------
			if (reader["BlocKey"] != DBNull.Value)
			    ImagesWithBlocksObj.BlocKey = (string)reader["BlocKey"];
			//------------------------------------------------
            //Return the populated object
            return ImagesWithBlocksObj;
        }
        //------------------------------------------------------------------------------------------------------
        #endregion

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

            if (list != null && list.Count > 0)
            {
                ImagesWithBlocksObj = list[0];
            }
            return(ImagesWithBlocksObj);
        }
        //------------------------------------------------------------------------------------------------------
        #endregion

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