コード例 #1
0
        //[Transactional(TransactionalTypes.TransactionScope)]
        protected void DataPortal_Delete(ItemCriteria criteria, SqlConnection connection)
        {
            bool cancel = false;

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

            string commandText = String.Format("DELETE FROM [dbo].[Item] {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();
        }
コード例 #2
0
        private void DataPortal_Fetch(ItemCriteria criteria)
        {
            bool cancel = false;

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

            string commandText = String.Format("SELECT [ItemId], [ProductId], [ListPrice], [UnitCost], [Supplier], [Status], [Name], [Image] FROM [dbo].[Item] {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.Item' using the following criteria: {0}.", criteria));
                        }
                    }
                }
            }

            OnFetched();
        }
コード例 #3
0
        /// <summary>
        /// Returns a <see cref="Item"/> object of the specified criteria.
        /// </summary>
        /// <param name="productId">No additional detail available.</param>
        /// <returns>A <see cref="Item"/> object of the specified criteria.</returns>
        internal static Item GetByProductIdChild(System.String productId)
        {
            var criteria = new ItemCriteria {
                ProductId = productId
            };


            return(DataPortal.FetchChild <Item>(criteria));
        }
コード例 #4
0
        internal static async Task <ItemList> GetByProductIdAsync(System.String productId)
        {
            var criteria = new ItemCriteria {
                ProductId = productId
            };


            return(await DataPortal.FetchAsync <AsyncChildLoader <ItemList> >(criteria).ContinueWith(t => t.Result.Child));
        }
コード例 #5
0
        public static async Task DeleteItemAsync(System.String itemId)
        {
            var criteria = new ItemCriteria {
                ItemId = itemId
            };


            await DataPortal.DeleteAsync <Item>(criteria);
        }
コード例 #6
0
        /// <summary>
        /// Returns a <see cref="Item"/> object of the specified criteria.
        /// </summary>
        /// <param name="itemId">No additional detail available.</param>
        /// <returns>A <see cref="Item"/> object of the specified criteria.</returns>
        internal static Item GetByItemIdChild(System.String itemId)
        {
            var criteria = new ItemCriteria {
                ItemId = itemId
            };


            return(DataPortal.FetchChild <Item>(criteria));
        }
コード例 #7
0
        /// <summary>
        /// Returns a <see cref="Item"/> object of the specified criteria.
        /// </summary>
        /// <param name="productId">No additional detail available.</param>
        /// <returns>A <see cref="Item"/> object of the specified criteria.</returns>
        public static Item GetByProductId(System.String productId)
        {
            var criteria = new ItemCriteria {
                ProductId = productId
            };


            return(DataPortal.Fetch <Item>(criteria));
        }
コード例 #8
0
        public static async Task <Item> GetByItemIdAsync(System.String itemId)
        {
            var criteria = new ItemCriteria {
                ItemId = itemId
            };


            return(await DataPortal.FetchAsync <Item>(criteria));
        }
コード例 #9
0
        /// <summary>
        /// Returns a <see cref="Item"/> object of the specified criteria.
        /// </summary>
        /// <param name="itemId">No additional detail available.</param>
        /// <returns>A <see cref="Item"/> object of the specified criteria.</returns>
        public static Item GetByItemId(System.String itemId)
        {
            var criteria = new ItemCriteria {
                ItemId = itemId
            };


            return(DataPortal.Fetch <Item>(criteria));
        }
コード例 #10
0
        internal static async Task <Item> GetByProductIdChildAsync(System.String productId)
        {
            var criteria = new ItemCriteria {
                ProductId = productId
            };


            return(await DataPortal.FetchAsync <Item>(criteria));
        }
コード例 #11
0
        /// <summary>
        /// Returns a <see cref="Item"/> object of the specified criteria.
        /// </summary>
        /// <param name="supplier">No additional detail available.</param>
        /// <returns>A <see cref="Item"/> object of the specified criteria.</returns>
        internal static Item GetBySupplierChild(System.Int32?supplier)
        {
            var criteria = new ItemCriteria {
            };

            if (supplier.HasValue)
            {
                criteria.Supplier = supplier.Value;
            }

            return(DataPortal.FetchChild <Item>(criteria));
        }
コード例 #12
0
        internal static async Task <ItemList> GetBySupplierAsync(System.Int32?supplier)
        {
            var criteria = new ItemCriteria {
            };

            if (supplier.HasValue)
            {
                criteria.Supplier = supplier.Value;
            }

            return(await DataPortal.FetchAsync <AsyncChildLoader <ItemList> >(criteria).ContinueWith(t => t.Result.Child));
        }
コード例 #13
0
        internal static async Task <Item> GetBySupplierChildAsync(System.Int32?supplier)
        {
            var criteria = new ItemCriteria {
            };

            if (supplier.HasValue)
            {
                criteria.Supplier = supplier.Value;
            }

            return(await DataPortal.FetchAsync <Item>(criteria));
        }
コード例 #14
0
        /// <summary>
        /// Returns a <see cref="Item"/> object of the specified criteria.
        /// </summary>
        /// <param name="productId">No additional detail available.</param>
        /// <param name="itemId">No additional detail available.</param>
        /// <param name="listPrice">No additional detail available.</param>
        /// <param name="name">No additional detail available.</param>
        /// <returns>A <see cref="Item"/> object of the specified criteria.</returns>
        public static Item GetByProductIdItemIdListPriceName(System.String productId, System.String itemId, System.Decimal?listPrice, System.String name)
        {
            var criteria = new ItemCriteria {
                ProductId = productId, ItemId = itemId, Name = name
            };

            if (listPrice.HasValue)
            {
                criteria.ListPrice = listPrice.Value;
            }

            return(DataPortal.Fetch <Item>(criteria));
        }
コード例 #15
0
        internal static async Task <ItemList> GetByProductIdItemIdListPriceNameAsync(System.String productId, System.String itemId, System.Decimal?listPrice, System.String name)
        {
            var criteria = new ItemCriteria {
                ProductId = productId, ItemId = itemId, Name = name
            };

            if (listPrice.HasValue)
            {
                criteria.ListPrice = listPrice.Value;
            }

            return(await DataPortal.FetchAsync <AsyncChildLoader <ItemList> >(criteria).ContinueWith(t => t.Result.Child));
        }
コード例 #16
0
        internal static async Task <Item> GetByProductIdItemIdListPriceNameChildAsync(System.String productId, System.String itemId, System.Decimal?listPrice, System.String name)
        {
            var criteria = new ItemCriteria {
                ProductId = productId, ItemId = itemId, Name = name
            };

            if (listPrice.HasValue)
            {
                criteria.ListPrice = listPrice.Value;
            }

            return(await DataPortal.FetchAsync <Item>(criteria));
        }
コード例 #17
0
        private void Child_Fetch(ItemCriteria criteria)
        {
            bool cancel = false;

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

            RaiseListChangedEvents = false;

            // Fetch Child objects.
            string commandText = String.Format("SELECT [ItemId], [ProductId], [ListPrice], [UnitCost], [Supplier], [Status], [Name], [Image] FROM [dbo].[Item] {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.Item.GetItem(reader));
                            } while(reader.Read());
                        }
                    }
                }
            }

            RaiseListChangedEvents = true;

            OnFetched();
        }
コード例 #18
0
 internal static ItemList GetByCriteria(ItemCriteria criteria)
 {
     return(DataPortal.Fetch <ItemList>(criteria));
 }
コード例 #19
0
 /// <summary>
 /// Determines if a record exists in the Item in the database for the specified criteria.
 /// </summary>
 /// <param name="criteria">The criteria parameter is a <see cref="ItemList"/> object.</param>
 /// <returns>A boolean value of true is returned if a record is found.</returns>
 public static bool Exists(ItemCriteria criteria)
 {
     return(PetShop.Business.Item.Exists(criteria));
 }
コード例 #20
0
        protected override void DataPortal_Update()
        {
            bool cancel = false;

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

            if (OriginalItemId != ItemId)
            {
                // Insert new child.
                Item item = new Item {
                    ItemId = ItemId, ProductId = ProductId, Status = Status, Name = Name, Image = Image
                };
                if (ListPrice.HasValue)
                {
                    item.ListPrice = ListPrice.Value;
                }
                if (UnitCost.HasValue)
                {
                    item.UnitCost = UnitCost.Value;
                }
                if (Supplier.HasValue)
                {
                    item.Supplier = Supplier.Value;
                }
                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 ItemCriteria {
                    ItemId = OriginalItemId
                };

                DataPortal_Delete(criteria);

                // Mark the original as the new one.
                OriginalItemId = ItemId;

                OnUpdated();

                return;
            }

            const string commandText = "UPDATE [dbo].[Item] SET [ItemId] = @p_ItemId, [ProductId] = @p_ProductId, [ListPrice] = @p_ListPrice, [UnitCost] = @p_UnitCost, [Supplier] = @p_Supplier, [Status] = @p_Status, [Name] = @p_Name, [Image] = @p_Image WHERE [ItemId] = @p_OriginalItemId; SELECT [ItemId] FROM [dbo].[Item] WHERE [ItemId] = @p_OriginalItemId";

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand(commandText, connection))
                {
                    command.Parameters.AddWithValue("@p_OriginalItemId", this.OriginalItemId);
                    command.Parameters.AddWithValue("@p_ItemId", this.ItemId);
                    command.Parameters.AddWithValue("@p_ProductId", this.ProductId);
                    command.Parameters.AddWithValue("@p_ListPrice", ADOHelper.NullCheck(this.ListPrice));
                    command.Parameters.AddWithValue("@p_UnitCost", ADOHelper.NullCheck(this.UnitCost));
                    command.Parameters.AddWithValue("@p_Supplier", ADOHelper.NullCheck(this.Supplier));
                    command.Parameters.AddWithValue("@p_Status", ADOHelper.NullCheck(this.Status));
                    command.Parameters.AddWithValue("@p_Name", ADOHelper.NullCheck(this.Name));
                    command.Parameters.AddWithValue("@p_Image", ADOHelper.NullCheck(this.Image));

                    //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(_originalItemIdProperty, this.ItemId);
                }

                FieldManager.UpdateChildren(this, connection);
            }

            OnUpdated();
        }
コード例 #21
0
 /// <summary>
 /// Determines if a record exists in the Item table in the database for the specified criteria.
 /// </summary>
 public static async Task <bool> ExistsAsync(ItemCriteria criteria)
 {
     return(await PetShop.Business.ExistsCommand.ExecuteAsync(criteria));
 }
コード例 #22
0
 /// <summary>
 /// Determines if a record exists in the Item table in the database for the specified criteria.
 /// </summary>
 /// <param name="criteria">The criteria parameter is an <see cref="Item"/> object.</param>
 /// <returns>A boolean value of true is returned if a record is found.</returns>
 public static bool Exists(ItemCriteria criteria)
 {
     return(PetShop.Business.ExistsCommand.Execute(criteria));
 }
コード例 #23
0
 /// <summary>
 /// CodeSmith generated stub method that is called when fetching the child <see cref="Item"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="ItemCriteria"/> 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(ItemCriteria criteria, ref bool cancel);
コード例 #24
0
 /// <summary>
 /// CodeSmith generated stub method that is called when deleting the <see cref="Item"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="ItemCriteria"/> 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(ItemCriteria criteria, ref bool cancel);
コード例 #25
0
 internal static async Task <ItemList> GetByCriteriaAsync(ItemCriteria criteria)
 {
     return(await DataPortal.FetchAsync <AsyncChildLoader <ItemList> >(criteria).ContinueWith(t => t.Result.Child));
 }