/// <summary> /// Loads a <see cref="ProductTypeEdit"/> object from the given <see cref="ProductTypeEditDto"/>. /// </summary> /// <param name="data">The ProductTypeEditDto to use.</param> private void Fetch(ProductTypeEditDto data) { // Value properties LoadProperty(ProductTypeIdProperty, data.ProductTypeId); LoadProperty(NameProperty, data.Name); var args = new DataPortalHookArgs(data); OnFetchRead(args); }
private ProductTypeEditDto Fetch(IDataReader data) { var productTypeEdit = new ProductTypeEditDto(); using (var dr = new SafeDataReader(data)) { if (dr.Read()) { productTypeEdit.ProductTypeId = dr.GetInt32("ProductTypeId"); productTypeEdit.Name = dr.GetString("Name"); } } return(productTypeEdit); }
/// <summary> /// Inserts a new ProductTypeEdit object in the database. /// </summary> /// <param name="productTypeEdit">The Product Type Edit DTO.</param> /// <returns>The new <see cref="ProductTypeEditDto"/>.</returns> public ProductTypeEditDto Insert(ProductTypeEditDto productTypeEdit) { using (var ctx = ConnectionManager <SqlConnection> .GetManager("Invoices")) { using (var cmd = new SqlCommand("dbo.AddProductTypeEdit", ctx.Connection)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ProductTypeId", productTypeEdit.ProductTypeId).Direction = ParameterDirection.Output; cmd.Parameters.AddWithValue("@Name", productTypeEdit.Name).DbType = DbType.String; cmd.ExecuteNonQuery(); productTypeEdit.ProductTypeId = (int)cmd.Parameters["@ProductTypeId"].Value; } } return(productTypeEdit); }
/// <summary> /// Updates in the database all changes made to the ProductTypeEdit object. /// </summary> /// <param name="productTypeEdit">The Product Type Edit DTO.</param> /// <returns>The updated <see cref="ProductTypeEditDto"/>.</returns> public ProductTypeEditDto Update(ProductTypeEditDto productTypeEdit) { using (var ctx = ConnectionManager <SqlConnection> .GetManager("Invoices")) { using (var cmd = new SqlCommand("dbo.UpdateProductTypeEdit", ctx.Connection)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ProductTypeId", productTypeEdit.ProductTypeId).DbType = DbType.Int32; cmd.Parameters.AddWithValue("@Name", productTypeEdit.Name).DbType = DbType.String; var rowsAffected = cmd.ExecuteNonQuery(); if (rowsAffected == 0) { throw new DataNotFoundException("ProductTypeEdit"); } } } return(productTypeEdit); }
protected override void DataPortal_Update() { var dto = new ProductTypeEditDto(); dto.ProductTypeId = ProductTypeId; dto.Name = Name; using (var dalManager = DalFactoryInvoices.GetManager()) { var args = new DataPortalHookArgs(dto); OnUpdatePre(args); var dal = dalManager.GetProvider <IProductTypeEditDal>(); using (BypassPropertyChecks) { var resultDto = dal.Update(dto); args = new DataPortalHookArgs(resultDto); } OnUpdatePost(args); } }