John,
Hope the following helps, I can't really go into much more details without actually implementing this within TBH (and I dont even need a store :))
Lets forget about the Category table and related classes and just look at the Departments table/classes as this is the where the problem is at the moment. Basically we need to pull out all the departments for a particular category.
1 > Create a new field CategoryID (int) within your TBH_Departments table.
2 > Next we need a stored procedure to extract all Departments for a specific category. I would use something like:
Code:
CREATE PROCEDURE dbo.tbh_Store_GetDepartmentsByCategoryID
{
@CategoryID int
}
AS
SET NOCOUNT ON
SELECT DepartmentID, CategoryID, AddedDate, AddedBy, Title, Importance, Description, ImageUrl
FROM dbo.tbh_Departments
WHERE CategoryID = @CategoryID
ORDER BY Importance DESC, Title ASC
3 > Now we have created our Stored Procedure we need to add a function in our SQLClient/SqlStoreProvider class to pass the required paramaters and return the results as a list (of DepartmentDetails):
Code:
Public Overrides Function GetDepartmentByCategoryID(ByVal categoryID As Integer) As System.Collections.Generic.List(Of DepartmentDetails)
Using cn As New SqlConnection(Me.ConnectionString)
Dim cmd As New SqlCommand("tbh_Store_GetDepartments", cn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@CategoryID", SqlDbType.Int).Value = categoryID
cn.Open()
Return GetDepartmentCollectionFromReader(ExecuteReader(cmd))
End Using
End Function
4 > Now we need to add a new method to our DAL StoreProvider class:
Code:
Public MustOverride Function GetDepartments(ByVal categoryID As Integer) As List(Of DepartmentDetails)
5 > Modify Function GetDepartmentFromReader(ByVal reader As IDataReader) As DepartmentDetails (in storeprovider class) to include additional CategoryID field
6 > Make the following changes to your DAL DepartmentDetails class:
1 > Add new private variable _categoryID
2 > Modify your New(ByVal ID as Integer....) constructor to include categoryID
3 > Add new public property CategoryID
7 > Make the following changes to your BLL Department class:
1 > Add new private variable _categoryID
2 > Add new public property CategoryID
3 > Modify New Constructor to include CategoryID
4 > Add new public shared function (method) GetDepartmentsByCategoryID(ByVal categoryID as integer) - returns list (of department)
The code is in
vb.net (cause thats what I know) but you should be able to adapt. I may have missed something out as have not looked at in too much details but essentially the steps are simple.
> You need a new field in your departments table
> You need a stored proc to get departments where the categoryID = value
> You need to create a new method in your sqlstoresprovider class that uses this new stored proc and passes the correct parameter returning a list of departmentdetails (just like your normal GetDepartments() method)
> Now you obviously need to add the new field to your departmentdetails class - so will need to create a new property for it. You will also need to add it to the new() constructor
> Then you need to create similar methods for your BLL
Once this is done you should be able to create a new page. Add a DataGridView control. Add a ObjectDataSource control using the GetDepartmentsByCategoryID(byVal CategoryID as Integer) method. Bind your gridview to this. Add a querystring paramater to your object datasource for CategoryID.
Finally test your work. Call: WhatEverYourPageIsCalled.aspx?CategoryID=#
passing a categoryID that you added to one of your department records and see if the correct data is returned.
One final point to mention is that I am still learning myself so invite anyone else to point out any errors I have made. I have been developing apps off and on for some time but only started working with ASP.net (and .net in general) about 1 year ago.
The great thing about this book (and TBH in general) is that all the different components of the site i.e. Articles, Store, Forum are developed using the same methodology. I recently added a resources section to my site allowing administrators to add "related downloads" to an article so that when users view an article they can download additional resources (but only if they're a member :D)
I achieved this by looking at the existing classes resulting in new functionality that ties in with the existing base classes taking full advantage of things like caching and membership that are already implemented in the site.
Thanks,