//------------------------------------------------------------------------------------------------------ #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="RequestsObj">Model object.</param> /// <returns>The result of create query.</returns> //-------------------------------------------------------------------- public bool Create(RequestsModel RequestsObj) { bool result = false; using (SqlConnection myConnection = GetSqlConnection()) { SqlCommand myCommand = new SqlCommand("[dbo].[Requests_Create]", myConnection); myCommand.CommandType = CommandType.StoredProcedure; //---------------------------------------------------------------------------------------------- // Set the parameters //---------------------------------------------------------------------------------------------- myCommand.Parameters.Add("@RequestID", SqlDbType.Int, 4).Value = RequestsObj.RequestID; myCommand.Parameters.Add("@RequestTime", SqlDbType.DateTime2, 8).Value = RequestsObj.RequestTime; //---------------------------------------------------------------------------------------------- // 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; //---------------------------------------------------------------------------------------------- } }
//------------------------------------------------------------------------------------------------------ #endregion #region --------------GetObject-------------- //------------------------------------------------------------------------------------------------------ /// <summary> /// Gets the spesific record. /// </summary> /// <param name="ID">The model id.</param> /// <returns>Model object.</returns> //-------------------------------------------------------------------- public static RequestsModel GetObject(int RequestID) { RequestsModel RequestsObj = null; List <RequestsModel> list = RequestsSqlDataPrvider.Instance.Get(RequestID); if (list != null && list.Count > 0) { RequestsObj = list[0]; } return(RequestsObj); }
//------------------------------------------------------------------------------------------------------ #endregion #region /*--------- PopulateModelFromIDataReader ---------*\ //------------------------------------------------------------------------------------------------------ /// <summary> /// Populates model from IDataReader . /// </summary> /// <param name="reader"></param> /// <returns>Model object.</returns> //-------------------------------------------------------------------- private RequestsModel PopulateModelFromIDataReader(IDataReader reader) { //Create a new object RequestsModel RequestsObj = new RequestsModel(); //Fill the object with data //------------------------------------------------ //[RequestID] //------------------------------------------------ if (reader["RequestID"] != DBNull.Value) RequestsObj.RequestID = (int)reader["RequestID"]; //------------------------------------------------ //------------------------------------------------ //[RequestTime] //------------------------------------------------ if (reader["RequestTime"] != DBNull.Value) RequestsObj.RequestTime = (DateTime)reader["RequestTime"]; //------------------------------------------------ //Return the populated object return RequestsObj; }
//------------------------------------------------------------------------------------------------------ #endregion #region --------------Update-------------- //------------------------------------------------------------------------------------------------------ /// <summary> /// Updates model object by calling sql data provider update method. /// </summary> /// <param name="RequestsObj">The model object.</param> /// <returns>The result of update operation.</returns> //-------------------------------------------------------------------- public static bool Update(RequestsModel RequestsObj) { return(RequestsSqlDataPrvider.Instance.Update(RequestsObj)); }