//[Transactional(TransactionalTypes.TransactionScope)]
        protected void DataPortal_Delete(OrderCriteria criteria, SqlConnection connection)
        {
            bool cancel = false;

            OnDeleting(criteria, ref cancel);
            if (cancel)
            {
                return;
            }

            string commandText = String.Format("DELETE FROM [dbo].[Orders] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag));

            using (var command = new SqlCommand(commandText, connection))
            {
                command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));

                //result: The number of rows changed, inserted, or deleted. -1 for select statements; 0 if no rows were affected, or the statement failed.
                int result = command.ExecuteNonQuery();
                if (result == 0)
                {
                    throw new DBConcurrencyException("The entity is out of date on the client. Please update the entity and try again. This could also be thrown if the sql statement failed to execute.");
                }
            }

            OnDeleted();
        }
        private void DataPortal_Fetch(OrderCriteria criteria)
        {
            bool cancel = false;

            OnFetching(criteria, ref cancel);
            if (cancel)
            {
                return;
            }

            string commandText = String.Format("SELECT [OrderId], [UserId], [OrderDate], [ShipAddr1], [ShipAddr2], [ShipCity], [ShipState], [ShipZip], [ShipCountry], [BillAddr1], [BillAddr2], [BillCity], [BillState], [BillZip], [BillCountry], [Courier], [TotalPrice], [BillToFirstName], [BillToLastName], [ShipToFirstName], [ShipToLastName], [AuthorizationNumber], [Locale] FROM [dbo].[Orders] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag));

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand(commandText, connection))
                {
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    using (var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            Map(reader);
                        }
                        else
                        {
                            throw new Exception(String.Format("The record was not found in 'dbo.Orders' using the following criteria: {0}.", criteria));
                        }
                    }
                }
            }

            OnFetched();
        }
        public static async Task <OrderList> GetByOrderIdAsync(System.Int32 orderId)
        {
            var criteria = new OrderCriteria {
                OrderId = orderId
            };


            return(await DataPortal.FetchAsync <OrderList>(criteria));
        }
        /// <summary>
        /// Returns a <see cref="OrderList"/> object of the specified criteria.
        /// </summary>
        /// <param name="orderId">No additional detail available.</param>
        /// <returns>A <see cref="OrderList"/> object of the specified criteria.</returns>
        public static OrderList GetByOrderId(System.Int32 orderId)
        {
            var criteria = new OrderCriteria {
                OrderId = orderId
            };


            return(DataPortal.Fetch <OrderList>(criteria));
        }
        internal static async Task <Order> GetByOrderIdChildAsync(System.Int32 orderId)
        {
            var criteria = new OrderCriteria {
                OrderId = orderId
            };


            return(await DataPortal.FetchAsync <Order>(criteria));
        }
        /// <summary>
        /// Returns a <see cref="Order"/> object of the specified criteria.
        /// </summary>
        /// <param name="orderId">No additional detail available.</param>
        /// <returns>A <see cref="Order"/> object of the specified criteria.</returns>
        internal static Order GetByOrderIdChild(System.Int32 orderId)
        {
            var criteria = new OrderCriteria {
                OrderId = orderId
            };


            return(DataPortal.FetchChild <Order>(criteria));
        }
        public static async Task DeleteOrderAsync(System.Int32 orderId)
        {
            var criteria = new OrderCriteria {
                OrderId = orderId
            };


            await DataPortal.DeleteAsync <Order>(criteria);
        }
Example #8
0
        private void DataPortal_Fetch(OrderCriteria criteria)
        {
            bool cancel = false;

            OnFetching(criteria, ref cancel);
            if (cancel)
            {
                return;
            }

            RaiseListChangedEvents = false;

            // Fetch Child objects.
            string commandText = String.Format("SELECT [OrderId], [UserId], [OrderDate], [ShipAddr1], [ShipAddr2], [ShipCity], [ShipState], [ShipZip], [ShipCountry], [BillAddr1], [BillAddr2], [BillCity], [BillState], [BillZip], [BillCountry], [Courier], [TotalPrice], [BillToFirstName], [BillToLastName], [ShipToFirstName], [ShipToLastName], [AuthorizationNumber], [Locale] FROM [dbo].[Orders] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag));

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand(commandText, connection))
                {
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));

                    using (var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            do
                            {
                                this.Add(PetShop.Tests.ParameterizedSQL.Order.GetOrder(reader));
                            } while(reader.Read());
                        }
                    }
                }
            }

            RaiseListChangedEvents = true;

            OnFetched();
        }
 public static OrderList GetByCriteria(OrderCriteria criteria)
 {
     return(DataPortal.Fetch <OrderList>(criteria));
 }
 /// <summary>
 /// Determines if a record exists in the Order in the database for the specified criteria.
 /// </summary>
 public static async Task <bool> ExistsAsync(OrderCriteria criteria)
 {
     return(await PetShop.Tests.ParameterizedSQL.ExistsCommand.ExecuteAsync(criteria));
 }
 /// <summary>
 /// Determines if a record exists in the Order in the database for the specified criteria.
 /// </summary>
 /// <param name="criteria">The criteria parameter is a <see cref="OrderList"/> object.</param>
 /// <returns>A boolean value of true is returned if a record is found.</returns>
 public static bool Exists(OrderCriteria criteria)
 {
     return(PetShop.Tests.ParameterizedSQL.Order.Exists(criteria));
 }
 /// <summary>
 /// CodeSmith generated stub method that is called when fetching the child <see cref="Order"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="OrderCriteria"/> object containing the criteria of the object to fetch.</param>
 /// <param name="cancel">Value returned from the method indicating whether the object fetching should proceed.</param>
 partial void OnFetching(OrderCriteria criteria, ref bool cancel);
 public static async Task <OrderList> GetByCriteriaAsync(OrderCriteria criteria)
 {
     return(await DataPortal.FetchAsync <OrderList>(criteria));
 }
 /// <summary>
 /// Determines if a record exists in the Orders table in the database for the specified criteria.
 /// </summary>
 /// <param name="criteria">The criteria parameter is an <see cref="Order"/> object.</param>
 /// <returns>A boolean value of true is returned if a record is found.</returns>
 public static bool Exists(OrderCriteria criteria)
 {
     return(PetShop.Tests.ParameterizedSQL.ExistsCommand.Execute(criteria));
 }
 /// <summary>
 /// CodeSmith generated stub method that is called when deleting the <see cref="Order"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="OrderCriteria"/> object containing the criteria of the object to delete.</param>
 /// <param name="cancel">Value returned from the method indicating whether the object deletion should proceed.</param>
 partial void OnDeleting(OrderCriteria criteria, ref bool cancel);