Пример #1
0
        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();
        }
Пример #2
0
        //[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();
        }
Пример #3
0
        internal static async Task <Order> GetByOrderIdChildAsync(System.Int32 orderId)
        {
            var criteria = new OrderCriteria {
                OrderId = orderId
            };


            return(await DataPortal.FetchAsync <Order>(criteria));
        }
Пример #4
0
        public static async Task DeleteOrderAsync(System.Int32 orderId)
        {
            var criteria = new OrderCriteria {
                OrderId = orderId
            };


            await DataPortal.DeleteAsync <Order>(criteria);
        }
Пример #5
0
        /// <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));
        }
        internal static async Task <OrderList> GetByOrderIdAsync(System.Int32 orderId)
        {
            var criteria = new OrderCriteria {
                OrderId = orderId
            };


            return(await DataPortal.FetchAsync <AsyncChildLoader <OrderList> >(criteria).ContinueWith(t => t.Result.Child));
        }
Пример #7
0
        /// <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>
        public static Order GetByOrderId(System.Int32 orderId)
        {
            var criteria = new OrderCriteria {
                OrderId = orderId
            };


            return(DataPortal.Fetch <Order>(criteria));
        }
Пример #8
0
        public static void GetOrder(string uniqueId, EventHandler <DataPortalResult <Order> > handler)
        {
            var criteria = new OrderCriteria {
                UserId = uniqueId
            };


            var dp = new DataPortal <Order>();

            dp.FetchCompleted += handler;
            dp.BeginFetch(criteria);
        }
Пример #9
0
        private void Child_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.Business.Order.GetOrder(reader));
                            } while(reader.Read());
                        }
                    }
                }
            }

            RaiseListChangedEvents = true;

            OnFetched();
        }
Пример #10
0
 /// <summary>
 /// Determines if a record exists in the Orders table in the database for the specified criteria.
 /// </summary>
 public static async Task <bool> ExistsAsync(OrderCriteria criteria)
 {
     return(await PetShop.Business.ExistsCommand.ExecuteAsync(criteria));
 }
Пример #11
0
 /// <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.Business.ExistsCommand.Execute(criteria));
 }
Пример #12
0
 /// <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 OnChildFetching(OrderCriteria criteria, ref bool cancel);
Пример #13
0
 /// <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);
 internal static async Task <OrderList> GetByCriteriaAsync(OrderCriteria criteria)
 {
     return(await DataPortal.FetchAsync <AsyncChildLoader <OrderList> >(criteria).ContinueWith(t => t.Result.Child));
 }
 internal 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>
 /// <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.Business.Order.Exists(criteria));
 }