//------------------------------------------------------------------------------------------------------ #endregion #region /*--------- Update ---------*\ //------------------------------------------------------------------------------------------------------ /// <summary> /// Converts the object properties to SQL paramters and executes the update procedure. /// </summary> /// <param name="IndexersOwnersObj">Model object.</param> /// <returns>The result of update query.</returns> //-------------------------------------------------------------------- public bool Update(IndexersOwnersModel IndexersOwnersObj) { bool result = false; using (SqlConnection myConnection = GetSqlConnection()) { SqlCommand myCommand = new SqlCommand("[dbo].[IndexersOwners_Update]", myConnection); myCommand.CommandType = CommandType.StoredProcedure; //---------------------------------------------------------------------------------------------- // Set the parameters //---------------------------------------------------------------------------------------------- myCommand.Parameters.Add("@OwnerID", SqlDbType.Int).Value = IndexersOwnersObj.OwnerID; myCommand.Parameters.Add("@Name", SqlDbType.VarChar).Value = IndexersOwnersObj.Name; //---------------------------------------------------------------------------------------------- // Execute the command //---------------------------------------------------------------------------------------------- myConnection.Open(); if (myCommand.ExecuteNonQuery() > 0) { result = true; } myConnection.Close(); return result; //---------------------------------------------------------------------------------------------- } }
//------------------------------------------------------------------------------------------------------ #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="IndexersOwnersObj">Model object.</param> /// <returns>The result of create query.</returns> //-------------------------------------------------------------------- public bool Create(IndexersOwnersModel IndexersOwnersObj) { bool result = false; using (SqlConnection myConnection = GetSqlConnection()) { SqlCommand myCommand = new SqlCommand("[dbo].[IndexersOwners_Create]", myConnection); myCommand.CommandType = CommandType.StoredProcedure; //---------------------------------------------------------------------------------------------- // Set the parameters //---------------------------------------------------------------------------------------------- myCommand.Parameters.Add("@OwnerID", SqlDbType.Int).Direction = ParameterDirection.Output; myCommand.Parameters.Add("@Name", SqlDbType.VarChar).Value = IndexersOwnersObj.Name; //---------------------------------------------------------------------------------------------- // Execute the command //---------------------------------------------------------------------------------------------- myConnection.Open(); if (myCommand.ExecuteNonQuery() > 0) { result = true; //Get ID value from database and set it in object IndexersOwnersObj.OwnerID = (int)myCommand.Parameters["@OwnerID"].Value; } myConnection.Close(); return result; //---------------------------------------------------------------------------------------------- } }
public ActionResult Create(IndexersOwnersModel IndexersOwnersObj) { //------------------------------------------ //Check ModelState //------------------------------------------ if (!ModelState.IsValid) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "Invalid data")); } //------------------------------------------ try { bool result = IndexersOwnersFactor.Create(IndexersOwnersObj); if (result == true) { return(List(1, 25, null, null, null, null)); } else { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "Saving operation faild")); } } catch (Exception ex) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message)); } }
//------------------------------------------------------------------------------------------------------ #endregion #region --------------GetObject-------------- //------------------------------------------------------------------------------------------------------ /// <summary> /// Gets the spesific record. /// </summary> /// <param name="ID">The model id.</param> /// <returns>Model object.</returns> //-------------------------------------------------------------------- public static IndexersOwnersModel GetObject(int OwnerID) { IndexersOwnersModel IndexersOwnersObj = null; List <IndexersOwnersModel> list = IndexersOwnersSqlDataPrvider.Instance.Get(OwnerID); if (list != null && list.Count > 0) { IndexersOwnersObj = list[0]; } return(IndexersOwnersObj); }
public ActionResult GetObject(int id) { try { IndexersOwnersModel IndexersOwnersObj = IndexersOwnersFactor.GetObject(id); if (IndexersOwnersObj == null) { IndexersOwnersObj = new IndexersOwnersModel(); } return(Json(IndexersOwnersObj, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message)); } }
//------------------------------------------------------------------------------------------------------ #endregion #region /*--------- PopulateModelFromIDataReader ---------*\ //------------------------------------------------------------------------------------------------------ /// <summary> /// Populates model from IDataReader . /// </summary> /// <param name="reader"></param> /// <returns>Model object.</returns> //-------------------------------------------------------------------- private IndexersOwnersModel PopulateModelFromIDataReader(IDataReader reader) { //Create a new object IndexersOwnersModel IndexersOwnersObj = new IndexersOwnersModel(); //Fill the object with data //------------------------------------------------ //[OwnerID] //------------------------------------------------ if (reader["OwnerID"] != DBNull.Value) IndexersOwnersObj.OwnerID = (int)reader["OwnerID"]; //------------------------------------------------ //------------------------------------------------ //[Name] //------------------------------------------------ if (reader["Name"] != DBNull.Value) IndexersOwnersObj.Name = (string)reader["Name"]; //------------------------------------------------ //Return the populated object return IndexersOwnersObj; }
//------------------------------------------------------------------------------------------------------ #endregion #region --------------Update-------------- //------------------------------------------------------------------------------------------------------ /// <summary> /// Updates model object by calling sql data provider update method. /// </summary> /// <param name="IndexersOwnersObj">The model object.</param> /// <returns>The result of update operation.</returns> //-------------------------------------------------------------------- public static bool Update(IndexersOwnersModel IndexersOwnersObj) { return(IndexersOwnersSqlDataPrvider.Instance.Update(IndexersOwnersObj)); }