Inheritance: OrdersBase
Esempio n. 1
0
        /// <summary>
        ///     Update an existing row in the datasource.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="entity">PetShop.Business.Orders object to update.</param>
        /// <remarks>
        ///		After updating the datasource, the PetShop.Business.Orders 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, PetShop.Business.Orders entity)
        {
            SqlDatabase database       = new SqlDatabase(this._connectionString);
            DbCommand   commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Orders_Update", _useStoredProcedure);

            database.AddInParameter(commandWrapper, "@OrderId", DbType.Int32, entity.OrderId);
            database.AddInParameter(commandWrapper, "@UserId", DbType.AnsiString, entity.UserId);
            database.AddInParameter(commandWrapper, "@OrderDate", DbType.DateTime, entity.OrderDate);
            database.AddInParameter(commandWrapper, "@ShipAddr1", DbType.AnsiString, entity.ShipAddr1);
            database.AddInParameter(commandWrapper, "@ShipAddr2", DbType.AnsiString, entity.ShipAddr2);
            database.AddInParameter(commandWrapper, "@ShipCity", DbType.AnsiString, entity.ShipCity);
            database.AddInParameter(commandWrapper, "@ShipState", DbType.AnsiString, entity.ShipState);
            database.AddInParameter(commandWrapper, "@ShipZip", DbType.AnsiString, entity.ShipZip);
            database.AddInParameter(commandWrapper, "@ShipCountry", DbType.AnsiString, entity.ShipCountry);
            database.AddInParameter(commandWrapper, "@BillAddr1", DbType.AnsiString, entity.BillAddr1);
            database.AddInParameter(commandWrapper, "@BillAddr2", DbType.AnsiString, entity.BillAddr2);
            database.AddInParameter(commandWrapper, "@BillCity", DbType.AnsiString, entity.BillCity);
            database.AddInParameter(commandWrapper, "@BillState", DbType.AnsiString, entity.BillState);
            database.AddInParameter(commandWrapper, "@BillZip", DbType.AnsiString, entity.BillZip);
            database.AddInParameter(commandWrapper, "@BillCountry", DbType.AnsiString, entity.BillCountry);
            database.AddInParameter(commandWrapper, "@Courier", DbType.AnsiString, entity.Courier);
            database.AddInParameter(commandWrapper, "@TotalPrice", DbType.Decimal, entity.TotalPrice);
            database.AddInParameter(commandWrapper, "@BillToFirstName", DbType.AnsiString, entity.BillToFirstName);
            database.AddInParameter(commandWrapper, "@BillToLastName", DbType.AnsiString, entity.BillToLastName);
            database.AddInParameter(commandWrapper, "@ShipToFirstName", DbType.AnsiString, entity.ShipToFirstName);
            database.AddInParameter(commandWrapper, "@ShipToLastName", DbType.AnsiString, entity.ShipToLastName);
            database.AddInParameter(commandWrapper, "@AuthorizationNumber", DbType.Int32, entity.AuthorizationNumber);
            database.AddInParameter(commandWrapper, "@Locale", DbType.AnsiString, entity.Locale);

            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));
        }
Esempio n. 2
0
        /// <summary>
        ///     Inserts a PetShop.Business.Orders object into the datasource using a transaction.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="entity">PetShop.Business.Orders object to insert.</param>
        /// <remarks>
        ///		After inserting into the datasource, the PetShop.Business.Orders 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, PetShop.Business.Orders entity)
        {
            SqlDatabase database       = new SqlDatabase(this._connectionString);
            DbCommand   commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Orders_Insert", _useStoredProcedure);

            database.AddOutParameter(commandWrapper, "@OrderId", DbType.Int32, 4);
            database.AddInParameter(commandWrapper, "@UserId", DbType.AnsiString, entity.UserId);
            database.AddInParameter(commandWrapper, "@OrderDate", DbType.DateTime, entity.OrderDate);
            database.AddInParameter(commandWrapper, "@ShipAddr1", DbType.AnsiString, entity.ShipAddr1);
            database.AddInParameter(commandWrapper, "@ShipAddr2", DbType.AnsiString, entity.ShipAddr2);
            database.AddInParameter(commandWrapper, "@ShipCity", DbType.AnsiString, entity.ShipCity);
            database.AddInParameter(commandWrapper, "@ShipState", DbType.AnsiString, entity.ShipState);
            database.AddInParameter(commandWrapper, "@ShipZip", DbType.AnsiString, entity.ShipZip);
            database.AddInParameter(commandWrapper, "@ShipCountry", DbType.AnsiString, entity.ShipCountry);
            database.AddInParameter(commandWrapper, "@BillAddr1", DbType.AnsiString, entity.BillAddr1);
            database.AddInParameter(commandWrapper, "@BillAddr2", DbType.AnsiString, entity.BillAddr2);
            database.AddInParameter(commandWrapper, "@BillCity", DbType.AnsiString, entity.BillCity);
            database.AddInParameter(commandWrapper, "@BillState", DbType.AnsiString, entity.BillState);
            database.AddInParameter(commandWrapper, "@BillZip", DbType.AnsiString, entity.BillZip);
            database.AddInParameter(commandWrapper, "@BillCountry", DbType.AnsiString, entity.BillCountry);
            database.AddInParameter(commandWrapper, "@Courier", DbType.AnsiString, entity.Courier);
            database.AddInParameter(commandWrapper, "@TotalPrice", DbType.Decimal, entity.TotalPrice);
            database.AddInParameter(commandWrapper, "@BillToFirstName", DbType.AnsiString, entity.BillToFirstName);
            database.AddInParameter(commandWrapper, "@BillToLastName", DbType.AnsiString, entity.BillToLastName);
            database.AddInParameter(commandWrapper, "@ShipToFirstName", DbType.AnsiString, entity.ShipToFirstName);
            database.AddInParameter(commandWrapper, "@ShipToLastName", DbType.AnsiString, entity.ShipToLastName);
            database.AddInParameter(commandWrapper, "@AuthorizationNumber", DbType.Int32, entity.AuthorizationNumber);
            database.AddInParameter(commandWrapper, "@Locale", DbType.AnsiString, entity.Locale);

            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 _orderId = database.GetParameterValue(commandWrapper, "@OrderId");

            entity.OrderId = (int)_orderId;


            entity.AcceptChanges();

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

            return(Convert.ToBoolean(results));
        }