protected void DataPortal_Fetch(CategoryCriteria criteria)
        {
            bool cancel = false;

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

            string commandText = String.Format("SELECT [CategoryId], [Name], [Descn] FROM [dbo].[Category] {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.Category' using the following criteria: {0}.", criteria));
                        }
                    }
                }
            }

            OnFetched();
        }
        protected void DataPortal_Delete(CategoryCriteria criteria)
        {
            bool cancel = false;

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

            string commandText = String.Format("DELETE FROM [dbo].[Category] {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));

                    //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();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns a <see cref="CategoryList"/> object of the specified criteria.
        /// </summary>
        /// <param name="categoryId">No additional detail available.</param>
        /// <returns>A <see cref="CategoryList"/> object of the specified criteria.</returns>
        public static CategoryList GetByCategoryId(System.String categoryId)
        {
            var criteria = new CategoryCriteria {
                CategoryId = categoryId
            };


            return(DataPortal.Fetch <CategoryList>(criteria));
        }
Exemplo n.º 4
0
        public static async Task <CategoryList> GetByCategoryIdAsync(System.String categoryId)
        {
            var criteria = new CategoryCriteria {
                CategoryId = categoryId
            };


            return(await DataPortal.FetchAsync <CategoryList>(criteria));
        }
Exemplo n.º 5
0
        public static async Task DeleteCategoryAsync(System.String categoryId)
        {
            var criteria = new CategoryCriteria {
                CategoryId = categoryId
            };


            await DataPortal.DeleteAsync <Category>(criteria);
        }
Exemplo n.º 6
0
        public static void DeleteCategory(System.String categoryId)
        {
            var criteria = new CategoryCriteria {
                CategoryId = categoryId
            };


            DataPortal.Delete <Category>(criteria);
        }
Exemplo n.º 7
0
        private void DataPortal_Fetch(CategoryCriteria criteria)
        {
            bool cancel = false;

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

            RaiseListChangedEvents = false;

            // Fetch Child objects.
            string commandText = String.Format("SELECT [CategoryId], [Name], [Descn] FROM [dbo].[Category] {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.Category.GetCategory(reader));
                            } while(reader.Read());
                        }
                    }
                }
            }

            RaiseListChangedEvents = true;

            OnFetched();
        }
Exemplo n.º 8
0
 public static CategoryList GetByCriteria(CategoryCriteria criteria)
 {
     return(DataPortal.Fetch <CategoryList>(criteria));
 }
Exemplo n.º 9
0
 /// <summary>
 /// Determines if a record exists in the Category in the database for the specified criteria.
 /// </summary>
 public static async Task <bool> ExistsAsync(CategoryCriteria criteria)
 {
     return(await PetShop.Tests.ParameterizedSQL.ExistsCommand.ExecuteAsync(criteria));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Determines if a record exists in the Category in the database for the specified criteria.
 /// </summary>
 /// <param name="criteria">The criteria parameter is a <see cref="CategoryList"/> object.</param>
 /// <returns>A boolean value of true is returned if a record is found.</returns>
 public static bool Exists(CategoryCriteria criteria)
 {
     return(PetShop.Tests.ParameterizedSQL.Category.Exists(criteria));
 }
Exemplo n.º 11
0
 /// <summary>
 /// CodeSmith generated stub method that is called when fetching the child <see cref="Category"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="CategoryCriteria"/> 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(CategoryCriteria criteria, ref bool cancel);
Exemplo n.º 12
0
 public static async Task <CategoryList> GetByCriteriaAsync(CategoryCriteria criteria)
 {
     return(await DataPortal.FetchAsync <CategoryList>(criteria));
 }
Exemplo n.º 13
0
 /// <summary>
 /// Determines if a record exists in the Category table in the database for the specified criteria.
 /// </summary>
 /// <param name="criteria">The criteria parameter is an <see cref="Category"/> object.</param>
 /// <returns>A boolean value of true is returned if a record is found.</returns>
 public static bool Exists(CategoryCriteria criteria)
 {
     return(PetShop.Tests.ParameterizedSQL.ExistsCommand.Execute(criteria));
 }
Exemplo n.º 14
0
 /// <summary>
 /// CodeSmith generated stub method that is called when deleting the <see cref="Category"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="CategoryCriteria"/> 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(CategoryCriteria criteria, ref bool cancel);
        protected override void DataPortal_Update()
        {
            bool cancel = false;

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

            if (OriginalCategoryId != CategoryId)
            {
                // Insert new child.
                Category item = new Category {
                    CategoryId = CategoryId, Name = Name, Description = Description
                };

                item = item.Save();

                // Mark editable child lists as dirty. This code may need to be updated to one-to-one relationships.
                foreach (Product itemToUpdate in Products)
                {
                    itemToUpdate.CategoryId = CategoryId;
                }

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

                // Delete the old.
                var criteria = new CategoryCriteria {
                    CategoryId = OriginalCategoryId
                };

                DataPortal_Delete(criteria);

                // Mark the original as the new one.
                OriginalCategoryId = CategoryId;

                OnUpdated();

                return;
            }

            const string commandText = "UPDATE [dbo].[Category] SET [CategoryId] = @p_CategoryId, [Name] = @p_Name, [Descn] = @p_Descn WHERE [CategoryId] = @p_OriginalCategoryId; SELECT [CategoryId] FROM [dbo].[Category] WHERE [CategoryId] = @p_OriginalCategoryId";

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand(commandText, connection))
                {
                    command.Parameters.AddWithValue("@p_OriginalCategoryId", this.OriginalCategoryId);
                    command.Parameters.AddWithValue("@p_CategoryId", this.CategoryId);
                    command.Parameters.AddWithValue("@p_Name", ADOHelper.NullCheck(this.Name));
                    command.Parameters.AddWithValue("@p_Descn", ADOHelper.NullCheck(this.Description));

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

                FieldManager.UpdateChildren(this, connection);
            }

            OnUpdated();
        }