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

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

            using (var command = new SqlCommand("[dbo].[CSLA_Item_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();
        }
        internal static async Task <Item> GetByProductIdChildAsync(System.String productId)
        {
            var criteria = new ItemCriteria {
                ProductId = productId
            };


            return(await DataPortal.FetchAsync <Item>(criteria));
        }
        public static async Task DeleteItemAsync(System.String itemId)
        {
            var criteria = new ItemCriteria {
                ItemId = itemId
            };


            await DataPortal.DeleteAsync <Item>(criteria);
        }
        public static async Task <Item> GetByItemIdAsync(System.String itemId)
        {
            var criteria = new ItemCriteria {
                ItemId = itemId
            };


            return(await DataPortal.FetchAsync <Item>(criteria));
        }
        /// <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));
        }
        /// <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));
        }
Example #7
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));
        }
Example #8
0
        /// <summary>
        /// Returns a <see cref="ItemList"/> object of the specified criteria.
        /// </summary>
        /// <param name="productId">No additional detail available.</param>
        /// <returns>A <see cref="ItemList"/> object of the specified criteria.</returns>
        internal static ItemList GetByProductId(System.String productId)
        {
            var criteria = new ItemCriteria {
                ProductId = productId
            };


            return(DataPortal.FetchChild <ItemList>(criteria));
        }
Example #9
0
        /// <summary>
        /// Returns a <see cref="ItemList"/> object of the specified criteria.
        /// </summary>
        /// <param name="itemId">No additional detail available.</param>
        /// <returns>A <see cref="ItemList"/> object of the specified criteria.</returns>
        internal static ItemList GetByItemId(System.String itemId)
        {
            var criteria = new ItemCriteria {
                ItemId = itemId
            };


            return(DataPortal.FetchChild <ItemList>(criteria));
        }
        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));
        }
        /// <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>
        public static Item GetBySupplier(System.Int32?supplier)
        {
            var criteria = new ItemCriteria {
            };

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

            return(DataPortal.Fetch <Item>(criteria));
        }
Example #12
0
        /// <summary>
        /// Returns a <see cref="ItemList"/> object of the specified criteria.
        /// </summary>
        /// <param name="supplier">No additional detail available.</param>
        /// <returns>A <see cref="ItemList"/> object of the specified criteria.</returns>
        internal static ItemList GetBySupplier(System.Int32?supplier)
        {
            var criteria = new ItemCriteria {
            };

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

            return(DataPortal.FetchChild <ItemList>(criteria));
        }
Example #13
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));
        }
Example #14
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));
        }
Example #15
0
        /// <summary>
        /// Returns a <see cref="ItemList"/> 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="ItemList"/> object of the specified criteria.</returns>
        internal static ItemList 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.FetchChild <ItemList>(criteria));
        }
        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));
        }
        private void Child_Fetch(ItemCriteria 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_Item_Select]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    command.Parameters.AddWithValue("@p_ListPriceHasValue", criteria.ListPriceHasValue);
                    command.Parameters.AddWithValue("@p_UnitCostHasValue", criteria.UnitCostHasValue);
                    command.Parameters.AddWithValue("@p_SupplierHasValue", criteria.SupplierHasValue);
                    command.Parameters.AddWithValue("@p_StatusHasValue", criteria.StatusHasValue);
                    command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue);
                    command.Parameters.AddWithValue("@p_ImageHasValue", criteria.ImageHasValue);
                    using (var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            do
                            {
                                this.Add(PetShop.Tests.StoredProcedures.Item.GetItem(reader));
                            } while(reader.Read());
                        }
                    }
                }
            }

            RaiseListChangedEvents = true;

            OnFetched();
        }
Example #18
0
        private void Child_Fetch(ItemCriteria criteria)
        {
            bool cancel = false;

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

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("[dbo].[CSLA_Item_Select]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    command.Parameters.AddWithValue("@p_ListPriceHasValue", criteria.ListPriceHasValue);
                    command.Parameters.AddWithValue("@p_UnitCostHasValue", criteria.UnitCostHasValue);
                    command.Parameters.AddWithValue("@p_SupplierHasValue", criteria.SupplierHasValue);
                    command.Parameters.AddWithValue("@p_StatusHasValue", criteria.StatusHasValue);
                    command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue);
                    command.Parameters.AddWithValue("@p_ImageHasValue", criteria.ImageHasValue);
                    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));
                        }
                    }
                }
            }

            OnChildFetched();


            MarkAsChild();
        }
 /// <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);
Example #20
0
 /// <summary>
 /// Determines if a record exists in the Item in the database for the specified criteria.
 /// </summary>
 public static async Task <bool> ExistsAsync(ItemCriteria criteria)
 {
     return(await PetShop.Tests.StoredProcedures.ExistsCommand.ExecuteAsync(criteria));
 }
Example #21
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.Tests.StoredProcedures.Item.Exists(criteria));
 }
Example #22
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 OnFetching(ItemCriteria criteria, ref bool cancel);
Example #23
0
 internal static async Task <ItemList> GetByCriteriaAsync(ItemCriteria criteria)
 {
     return(await DataPortal.FetchAsync <AsyncChildLoader <ItemList> >(criteria).ContinueWith(t => t.Result.Child));
 }
Example #24
0
 internal static ItemList GetByCriteria(ItemCriteria criteria)
 {
     return(DataPortal.Fetch <ItemList>(criteria));
 }
 /// <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.Tests.StoredProcedures.ExistsCommand.Execute(criteria));
 }
Example #26
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;
            }

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("[dbo].[CSLA_Item_Update]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    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();
        }