/// <summary> /// Factory method. Loads a <see cref="D10_City"/> object from the given D10_CityDto. /// </summary> /// <param name="data">The <see cref="D10_CityDto"/>.</param> /// <returns>A reference to the fetched <see cref="D10_City"/> object.</returns> internal static D10_City GetD10_City(D10_CityDto data) { D10_City obj = new D10_City(); obj.Fetch(data); return(obj); }
private void Child_Update() { if (!IsDirty) { return; } var dto = new D10_CityDto(); dto.City_ID = City_ID; dto.City_Name = City_Name; using (var dalManager = DalFactorySelfLoad.GetManager()) { var args = new DataPortalHookArgs(dto); OnUpdatePre(args); var dal = dalManager.GetProvider <ID10_CityDal>(); using (BypassPropertyChecks) { var resultDto = dal.Update(dto); args = new DataPortalHookArgs(resultDto); } OnUpdatePost(args); // flushes all pending data operations FieldManager.UpdateChildren(this); } }
/// <summary> /// Loads a <see cref="D10_City"/> object from the given <see cref="D10_CityDto"/>. /// </summary> /// <param name="data">The D10_CityDto to use.</param> private void Fetch(D10_CityDto data) { // Value properties LoadProperty(City_IDProperty, data.City_ID); LoadProperty(City_NameProperty, data.City_Name); var args = new DataPortalHookArgs(data); OnFetchRead(args); }
private D10_CityDto Fetch(SafeDataReader dr) { var d10_City = new D10_CityDto(); // Value properties d10_City.City_ID = dr.GetInt32("City_ID"); d10_City.City_Name = dr.GetString("City_Name"); return(d10_City); }
/// <summary> /// Factory method. Loads a <see cref="D10_City"/> object from the given D10_CityDto. /// </summary> /// <param name="data">The <see cref="D10_CityDto"/>.</param> /// <returns>A reference to the fetched <see cref="D10_City"/> object.</returns> internal static D10_City GetD10_City(D10_CityDto data) { D10_City obj = new D10_City(); // show the framework that this is a child object obj.MarkAsChild(); obj.Fetch(data); obj.MarkOld(); return(obj); }
/// <summary> /// Inserts a new D10_City object in the database. /// </summary> /// <param name="d10_City">The D10 City DTO.</param> /// <returns>The new <see cref="D10_CityDto"/>.</returns> public D10_CityDto Insert(D10_CityDto d10_City) { using (var ctx = ConnectionManager <SqlConnection> .GetManager("DeepLoad")) { using (var cmd = new SqlCommand("AddD10_City", ctx.Connection)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Parent_Region_ID", d10_City.Parent_Region_ID).DbType = DbType.Int32; cmd.Parameters.AddWithValue("@City_ID", d10_City.City_ID).Direction = ParameterDirection.Output; cmd.Parameters.AddWithValue("@City_Name", d10_City.City_Name).DbType = DbType.String; cmd.ExecuteNonQuery(); d10_City.City_ID = (int)cmd.Parameters["@City_ID"].Value; } } return(d10_City); }
/// <summary> /// Updates in the database all changes made to the D10_City object. /// </summary> /// <param name="d10_City">The D10 City DTO.</param> /// <returns>The updated <see cref="D10_CityDto"/>.</returns> public D10_CityDto Update(D10_CityDto d10_City) { using (var ctx = ConnectionManager <SqlConnection> .GetManager("DeepLoad")) { using (var cmd = new SqlCommand("UpdateD10_City", ctx.Connection)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@City_ID", d10_City.City_ID).DbType = DbType.Int32; cmd.Parameters.AddWithValue("@City_Name", d10_City.City_Name).DbType = DbType.String; var rowsAffected = cmd.ExecuteNonQuery(); if (rowsAffected == 0) { throw new DataNotFoundException("D10_City"); } } } return(d10_City); }
private void Child_Insert(D08_Region parent) { var dto = new D10_CityDto(); dto.Parent_Region_ID = parent.Region_ID; dto.City_Name = City_Name; using (var dalManager = DalFactorySelfLoad.GetManager()) { var args = new DataPortalHookArgs(dto); OnInsertPre(args); var dal = dalManager.GetProvider <ID10_CityDal>(); using (BypassPropertyChecks) { var resultDto = dal.Insert(dto); LoadProperty(City_IDProperty, resultDto.City_ID); args = new DataPortalHookArgs(resultDto); } OnInsertPost(args); // flushes all pending data operations FieldManager.UpdateChildren(this); } }