private ProductSupplierItemDto FetchProductSupplierItem(SafeDataReader dr)
        {
            var productSupplierItem = new ProductSupplierItemDto();

            // Value properties
            productSupplierItem.ProductSupplierId = dr.GetInt32("ProductSupplierId");
            productSupplierItem.SupplierId        = dr.GetInt32("SupplierId");

            return(productSupplierItem);
        }
        /// <summary>
        /// Loads a <see cref="ProductSupplierItem"/> object from the given <see cref="ProductSupplierItemDto"/>.
        /// </summary>
        /// <param name="data">The ProductSupplierItemDto to use.</param>
        private void Child_Fetch(ProductSupplierItemDto data)
        {
            // Value properties
            LoadProperty(ProductSupplierIdProperty, data.ProductSupplierId);
            LoadProperty(SupplierIdProperty, data.SupplierId);
            var args = new DataPortalHookArgs(data);

            OnFetchRead(args);
            // check all object rules and property rules
            BusinessRules.CheckRules();
        }
 /// <summary>
 /// Inserts a new ProductSupplierItem object in the database.
 /// </summary>
 /// <param name="productSupplierItem">The Product Supplier Item DTO.</param>
 /// <returns>The new <see cref="ProductSupplierItemDto"/>.</returns>
 public ProductSupplierItemDto Insert(ProductSupplierItemDto productSupplierItem)
 {
     using (var ctx = ConnectionManager <FbConnection> .GetManager("Invoices"))
     {
         using (var cmd = new FbCommand("dbo.AddProductSupplierItem", ctx.Connection))
         {
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.AddWithValue("@ProductId", productSupplierItem.Parent_ProductId).DbType             = DbType.Guid;
             cmd.Parameters.AddWithValue("@ProductSupplierId", productSupplierItem.ProductSupplierId).Direction = ParameterDirection.Output;
             cmd.Parameters.AddWithValue("@SupplierId", productSupplierItem.SupplierId).DbType = DbType.Int32;
             cmd.ExecuteNonQuery();
             productSupplierItem.ProductSupplierId = (int)cmd.Parameters["@ProductSupplierId"].Value;
         }
     }
     return(productSupplierItem);
 }
 /// <summary>
 /// Updates in the database all changes made to the ProductSupplierItem object.
 /// </summary>
 /// <param name="productSupplierItem">The Product Supplier Item DTO.</param>
 /// <returns>The updated <see cref="ProductSupplierItemDto"/>.</returns>
 public ProductSupplierItemDto Update(ProductSupplierItemDto productSupplierItem)
 {
     using (var ctx = ConnectionManager <FbConnection> .GetManager("Invoices"))
     {
         using (var cmd = new FbCommand("dbo.UpdateProductSupplierItem", ctx.Connection))
         {
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.AddWithValue("@ProductSupplierId", productSupplierItem.ProductSupplierId).DbType = DbType.Int32;
             cmd.Parameters.AddWithValue("@SupplierId", productSupplierItem.SupplierId).DbType = DbType.Int32;
             var rowsAffected = cmd.ExecuteNonQuery();
             if (rowsAffected == 0)
             {
                 throw new DataNotFoundException("ProductSupplierItem");
             }
         }
     }
     return(productSupplierItem);
 }
        private void Child_Insert(ProductEdit parent)
        {
            var dto = new ProductSupplierItemDto();

            dto.Parent_ProductId = parent.ProductId;
            dto.SupplierId       = SupplierId;
            using (var dalManager = DalFactoryInvoices.GetManager())
            {
                var args = new DataPortalHookArgs(dto);
                OnInsertPre(args);
                var dal = dalManager.GetProvider <IProductSupplierItemDal>();
                using (BypassPropertyChecks)
                {
                    var resultDto = dal.Insert(dto);
                    LoadProperty(ProductSupplierIdProperty, resultDto.ProductSupplierId);
                    args = new DataPortalHookArgs(resultDto);
                }
                OnInsertPost(args);
            }
        }
        private void Child_Update()
        {
            if (!IsDirty)
            {
                return;
            }

            var dto = new ProductSupplierItemDto();

            dto.ProductSupplierId = ProductSupplierId;
            dto.SupplierId        = SupplierId;
            using (var dalManager = DalFactoryInvoices.GetManager())
            {
                var args = new DataPortalHookArgs(dto);
                OnUpdatePre(args);
                var dal = dalManager.GetProvider <IProductSupplierItemDal>();
                using (BypassPropertyChecks)
                {
                    var resultDto = dal.Update(dto);
                    args = new DataPortalHookArgs(resultDto);
                }
                OnUpdatePost(args);
            }
        }