Exemplo n.º 1
0
        /// <summary>
        ///     Update an existing row in the datasource.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="entity">GenTest.Entities.Macchina object to update.</param>
        /// <remarks>
        ///		After updating the datasource, the GenTest.Entities.Macchina object will be updated
        ///     to refelect any changes made by the datasource. (ie: identity or computed columns)
        /// </remarks>
        /// <returns>Returns true if operation is successful.</returns>
        /// <exception cref="System.Exception">The command could not be executed.</exception>
        /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
        /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
        public override bool Update(TransactionManager transactionManager, GenTest.Entities.Macchina entity)
        {
            SqlDatabase database       = new SqlDatabase(this._connectionString);
            DbCommand   commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Macchina_Update", _useStoredProcedure);

            database.AddInParameter(commandWrapper, "@Modello", DbType.String, entity.Modello);
            database.AddInParameter(commandWrapper, "@ID", DbType.Int32, entity.ID);
            database.AddInParameter(commandWrapper, "@CropAggregationMacchinaID", DbType.Int32, (entity.CropAggregationMacchinaID.HasValue ? (object)entity.CropAggregationMacchinaID : System.DBNull.Value));
            database.AddInParameter(commandWrapper, "@AssociationMotoreID", DbType.Int32, (entity.AssociationMotoreID.HasValue ? (object)entity.AssociationMotoreID : System.DBNull.Value));

            int results = 0;

            //Provider Data Requesting Command Event
            OnDataRequesting(new CommandEventArgs(commandWrapper, "Update", entity));

            if (transactionManager != null)
            {
                results = Utility.ExecuteNonQuery(transactionManager, commandWrapper);
            }
            else
            {
                results = Utility.ExecuteNonQuery(database, commandWrapper);
            }

            //Stop Tracking Now that it has been updated and persisted.
            if (DataRepository.Provider.EnableEntityTracking)
            {
                EntityManager.StopTracking(entity.EntityTrackingKey);
            }


            entity.AcceptChanges();

            //Provider Data Requested Command Event
            OnDataRequested(new CommandEventArgs(commandWrapper, "Update", entity));

            return(Convert.ToBoolean(results));
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Inserts a GenTest.Entities.Macchina object into the datasource using a transaction.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="entity">GenTest.Entities.Macchina object to insert.</param>
        /// <remarks>
        ///		After inserting into the datasource, the GenTest.Entities.Macchina object will be updated
        ///     to refelect any changes made by the datasource. (ie: identity or computed columns)
        /// </remarks>
        /// <returns>Returns true if operation is successful.</returns>
        /// <exception cref="System.Exception">The command could not be executed.</exception>
        /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
        /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
        public override bool Insert(TransactionManager transactionManager, GenTest.Entities.Macchina entity)
        {
            SqlDatabase database       = new SqlDatabase(this._connectionString);
            DbCommand   commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Macchina_Insert", _useStoredProcedure);

            database.AddInParameter(commandWrapper, "@Modello", DbType.String, entity.Modello);
            database.AddOutParameter(commandWrapper, "@ID", DbType.Int32, 4);
            database.AddInParameter(commandWrapper, "@CropAggregationMacchinaID", DbType.Int32, (entity.CropAggregationMacchinaID.HasValue ? (object)entity.CropAggregationMacchinaID  : System.DBNull.Value));
            database.AddInParameter(commandWrapper, "@AssociationMotoreID", DbType.Int32, (entity.AssociationMotoreID.HasValue ? (object)entity.AssociationMotoreID  : System.DBNull.Value));

            int results = 0;

            //Provider Data Requesting Command Event
            OnDataRequesting(new CommandEventArgs(commandWrapper, "Insert", entity));

            if (transactionManager != null)
            {
                results = Utility.ExecuteNonQuery(transactionManager, commandWrapper);
            }
            else
            {
                results = Utility.ExecuteNonQuery(database, commandWrapper);
            }

            object _iD = database.GetParameterValue(commandWrapper, "@ID");

            entity.ID = (System.Int32)_iD;


            entity.AcceptChanges();

            //Provider Data Requested Command Event
            OnDataRequested(new CommandEventArgs(commandWrapper, "Insert", entity));

            return(Convert.ToBoolean(results));
        }