private ProductTypeItemDto Fetch(SafeDataReader dr) { var productTypeItem = new ProductTypeItemDto(); // Value properties productTypeItem.ProductTypeId = dr.GetInt32("ProductTypeId"); productTypeItem.Name = dr.GetString("Name"); return(productTypeItem); }
/// <summary> /// Loads a <see cref="ProductTypeItem"/> object from the given <see cref="ProductTypeItemDto"/>. /// </summary> /// <param name="data">The ProductTypeItemDto to use.</param> private void Child_Fetch(ProductTypeItemDto data) { // Value properties LoadProperty(ProductTypeIdProperty, data.ProductTypeId); LoadProperty(NameProperty, data.Name); var args = new DataPortalHookArgs(data); OnFetchRead(args); // check all object rules and property rules BusinessRules.CheckRules(); }
/// <summary> /// Inserts a new ProductTypeItem object in the database. /// </summary> /// <param name="productTypeItem">The Product Type Item DTO.</param> /// <returns>The new <see cref="ProductTypeItemDto"/>.</returns> public ProductTypeItemDto Insert(ProductTypeItemDto productTypeItem) { using (var ctx = ConnectionManager <NpgsqlConnection> .GetManager("Invoices")) { using (var cmd = new NpgsqlCommand("dbo.AddProductTypeItem", ctx.Connection)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ProductTypeId", productTypeItem.ProductTypeId).Direction = ParameterDirection.Output; cmd.Parameters.AddWithValue("@Name", productTypeItem.Name).DbType = DbType.String; cmd.ExecuteNonQuery(); productTypeItem.ProductTypeId = (int)cmd.Parameters["@ProductTypeId"].Value; } } return(productTypeItem); }
/// <summary> /// Updates in the database all changes made to the ProductTypeItem object. /// </summary> /// <param name="productTypeItem">The Product Type Item DTO.</param> /// <returns>The updated <see cref="ProductTypeItemDto"/>.</returns> public ProductTypeItemDto Update(ProductTypeItemDto productTypeItem) { using (var ctx = ConnectionManager<SQLiteConnection>.GetManager("Invoices")) { using (var cmd = new SQLiteCommand("dbo.UpdateProductTypeItem", ctx.Connection)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ProductTypeId", productTypeItem.ProductTypeId).DbType = DbType.Int32; cmd.Parameters.AddWithValue("@Name", productTypeItem.Name).DbType = DbType.String; var rowsAffected = cmd.ExecuteNonQuery(); if (rowsAffected == 0) throw new DataNotFoundException("ProductTypeItem"); } } return productTypeItem; }
private void Child_Insert() { var dto = new ProductTypeItemDto(); dto.Name = Name; using (var dalManager = DalFactoryInvoices.GetManager()) { var args = new DataPortalHookArgs(dto); OnInsertPre(args); var dal = dalManager.GetProvider <IProductTypeItemDal>(); using (BypassPropertyChecks) { var resultDto = dal.Insert(dto); LoadProperty(ProductTypeIdProperty, resultDto.ProductTypeId); args = new DataPortalHookArgs(resultDto); } OnInsertPost(args); } }
private void Child_Update() { if (!IsDirty) { return; } var dto = new ProductTypeItemDto(); dto.ProductTypeId = ProductTypeId; dto.Name = Name; using (var dalManager = DalFactoryInvoices.GetManager()) { var args = new DataPortalHookArgs(dto); OnUpdatePre(args); var dal = dalManager.GetProvider <IProductTypeItemDal>(); using (BypassPropertyChecks) { var resultDto = dal.Update(dto); args = new DataPortalHookArgs(resultDto); } OnUpdatePost(args); } }