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

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

            using (var command = new SqlCommand("[dbo].[CSLA_LineItem_Delete]", connection))
            {
                command.CommandType = CommandType.StoredProcedure;
                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(LineItemCriteria criteria)
        {
            bool cancel = false;

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

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("[dbo].[CSLA_LineItem_Select]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    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.LineItem' using the following criteria: {0}.", criteria));
                        }
                    }
                }
            }

            OnFetched();
        }
Пример #3
0
        /// <summary>
        /// Returns a <see cref="LineItem"/> object of the specified criteria.
        /// </summary>
        /// <param name="orderId">No additional detail available.</param>
        /// <returns>A <see cref="LineItem"/> object of the specified criteria.</returns>
        public static LineItem GetByOrderId(System.Int32 orderId)
        {
            var criteria = new LineItemCriteria {
                OrderId = orderId
            };


            return(DataPortal.Fetch <LineItem>(criteria));
        }
Пример #4
0
        internal static async Task <LineItem> GetByOrderIdChildAsync(System.Int32 orderId)
        {
            var criteria = new LineItemCriteria {
                OrderId = orderId
            };


            return(await DataPortal.FetchAsync <LineItem>(criteria));
        }
Пример #5
0
        /// <summary>
        /// Returns a <see cref="LineItem"/> object of the specified criteria.
        /// </summary>
        /// <param name="orderId">No additional detail available.</param>
        /// <param name="lineNum">No additional detail available.</param>
        /// <returns>A <see cref="LineItem"/> object of the specified criteria.</returns>
        internal static LineItem GetByOrderIdLineNumChild(System.Int32 orderId, System.Int32 lineNum)
        {
            var criteria = new LineItemCriteria {
                OrderId = orderId, LineNum = lineNum
            };


            return(DataPortal.FetchChild <LineItem>(criteria));
        }
Пример #6
0
        /// <summary>
        /// Returns a <see cref="LineItem"/> object of the specified criteria.
        /// </summary>
        /// <param name="orderId">No additional detail available.</param>
        /// <returns>A <see cref="LineItem"/> object of the specified criteria.</returns>
        internal static LineItem GetByOrderIdChild(System.Int32 orderId)
        {
            var criteria = new LineItemCriteria {
                OrderId = orderId
            };


            return(DataPortal.FetchChild <LineItem>(criteria));
        }
Пример #7
0
        public static async Task <LineItem> GetByOrderIdLineNumAsync(System.Int32 orderId, System.Int32 lineNum)
        {
            var criteria = new LineItemCriteria {
                OrderId = orderId, LineNum = lineNum
            };


            return(await DataPortal.FetchAsync <LineItem>(criteria));
        }
Пример #8
0
        public static async Task DeleteLineItemAsync(System.Int32 orderId, System.Int32 lineNum)
        {
            var criteria = new LineItemCriteria {
                OrderId = orderId, LineNum = lineNum
            };


            await DataPortal.DeleteAsync <LineItem>(criteria);
        }
        /// <summary>
        /// Returns a <see cref="LineItemList"/> object of the specified criteria.
        /// </summary>
        /// <param name="orderId">No additional detail available.</param>
        /// <param name="lineNum">No additional detail available.</param>
        /// <returns>A <see cref="LineItemList"/> object of the specified criteria.</returns>
        public static LineItemList GetByOrderIdLineNum(System.Int32 orderId, System.Int32 lineNum)
        {
            var criteria = new LineItemCriteria {
                OrderId = orderId, LineNum = lineNum
            };


            return(DataPortal.Fetch <LineItemList>(criteria));
        }
        public static async Task <LineItemList> GetByOrderIdAsync(System.Int32 orderId)
        {
            var criteria = new LineItemCriteria {
                OrderId = orderId
            };


            return(await DataPortal.FetchAsync <LineItemList>(criteria));
        }
Пример #11
0
        private void DataPortal_Fetch(LineItemCriteria criteria)
        {
            bool cancel = false;

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

            RaiseListChangedEvents = false;

            // Fetch Child objects.
            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("[dbo].[CSLA_LineItem_Select]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));

                    using (var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            do
                            {
                                this.Add(PetShop.Tests.StoredProcedures.LineItem.GetLineItem(reader));
                            } while(reader.Read());
                        }
                    }
                }
            }

            RaiseListChangedEvents = true;

            OnFetched();
        }
Пример #12
0
 /// <summary>
 /// CodeSmith generated stub method that is called when fetching the child <see cref="LineItem"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="LineItemCriteria"/> 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(LineItemCriteria criteria, ref bool cancel);
Пример #13
0
 /// <summary>
 /// CodeSmith generated stub method that is called when deleting the <see cref="LineItem"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="LineItemCriteria"/> 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(LineItemCriteria criteria, ref bool cancel);
Пример #14
0
 /// <summary>
 /// Determines if a record exists in the LineItem table in the database for the specified criteria.
 /// </summary>
 /// <param name="criteria">The criteria parameter is an <see cref="LineItem"/> object.</param>
 /// <returns>A boolean value of true is returned if a record is found.</returns>
 public static bool Exists(LineItemCriteria criteria)
 {
     return(PetShop.Tests.StoredProcedures.ExistsCommand.Execute(criteria));
 }
 public static async Task <LineItemList> GetByCriteriaAsync(LineItemCriteria criteria)
 {
     return(await DataPortal.FetchAsync <LineItemList>(criteria));
 }
        protected override void DataPortal_Update()
        {
            bool cancel = false;

            OnUpdating(ref cancel);
            if (cancel)
            {
                return;
            }

            if (OriginalOrderId != OrderId || OriginalLineNum != LineNum)
            {
                // Insert new child.
                LineItem item = new LineItem {
                    OrderId = OrderId, LineNum = LineNum, ItemId = ItemId, Quantity = Quantity, UnitPrice = UnitPrice
                };

                item = item.Save();

                // Mark editable child lists as dirty. This code may need to be updated to one-to-one relationships.

                // Create a new connection.
                using (var connection = new SqlConnection(ADOHelper.ConnectionString))
                {
                    connection.Open();
                    FieldManager.UpdateChildren(this, connection);
                }

                // Delete the old.
                var criteria = new LineItemCriteria {
                    OrderId = OriginalOrderId, LineNum = OriginalLineNum
                };

                DataPortal_Delete(criteria);

                // Mark the original as the new one.
                OriginalOrderId = OrderId;
                OriginalLineNum = LineNum;
                OnUpdated();

                return;
            }

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("[dbo].[CSLA_LineItem_Update]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@p_OriginalOrderId", this.OriginalOrderId);
                    command.Parameters.AddWithValue("@p_OrderId", this.OrderId);
                    command.Parameters.AddWithValue("@p_OriginalLineNum", this.OriginalLineNum);
                    command.Parameters.AddWithValue("@p_LineNum", this.LineNum);
                    command.Parameters.AddWithValue("@p_ItemId", this.ItemId);
                    command.Parameters.AddWithValue("@p_Quantity", this.Quantity);
                    command.Parameters.AddWithValue("@p_UnitPrice", this.UnitPrice);
                    //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.");
                    }

                    LoadProperty(_originalOrderIdProperty, this.OrderId);
                    LoadProperty(_originalLineNumProperty, this.LineNum);
                }

                FieldManager.UpdateChildren(this, connection);
            }

            OnUpdated();
        }
 /// <summary>
 /// Determines if a record exists in the LineItem in the database for the specified criteria.
 /// </summary>
 /// <param name="criteria">The criteria parameter is a <see cref="LineItemList"/> object.</param>
 /// <returns>A boolean value of true is returned if a record is found.</returns>
 public static bool Exists(LineItemCriteria criteria)
 {
     return(PetShop.Tests.StoredProcedures.LineItem.Exists(criteria));
 }
Пример #18
0
 /// <summary>
 /// Determines if a record exists in the LineItem table in the database for the specified criteria.
 /// </summary>
 public static async Task <bool> ExistsAsync(LineItemCriteria criteria)
 {
     return(await PetShop.Tests.StoredProcedures.ExistsCommand.ExecuteAsync(criteria));
 }
 public static LineItemList GetByCriteria(LineItemCriteria criteria)
 {
     return(DataPortal.Fetch <LineItemList>(criteria));
 }