RSS feed icon BTB Shadow Man BiteTheBullet.co.uk logo

Page 1 2 3 4 5 6 7 8

DotNetNuke Random Image Tutorial - Part 3

PART 3

Generating The Data Access Layer

Right using CodeSmith we are going to create the stored procedures for our module first.
Start up CodeSmith and select the Stored Procedures Template, if this is the first time you have used CodeSmith with your current DNN database then you’ll need to define a data source as shown below.

Defining a Datasource for CodeSmith

  1. To define a data source, click the button in the MultiTable Source field.
  2. You'll now see the Table Picker dialog box , again click the button next to the drop down list.
  3. Now we can define a connection string for the database by clicking the Add button. Name your new connection, select SqlSchemaProvider as the type. Then to enter the connection string I normal just copy my connection string from the web.config of DotNetNuke since we know this is correct. You should end up with something like this.

Codesmith data source setup

Creating the Stored Procedures

Select the Stored Procedures Template.
Select the table we are going to create the stored procedures for from the dropdown MultiSource Table column. This should be BTBRandomImage since this is our table used by the module.

Then we just need to supply an object qualifier, hit generate and we’ve got all our stored procedures created.
There is one problem in that the stored procedures are generated for execution by the DNN installer, hence the tokens {databaseOwner} and {objectQualifier} in the script.
I’m going to replace databaseOwner with dbo. and remove the objectQualifier completely since my database doesn’t have an object qualifier, after doing this we execute the script using Query Analyser.

Ok that’s the stored procedures in the database, lets continue and make the other data access layers in the module.

 

Creating the BLL Info Class

  1. Select the C# BLL Info Class template from CodeSmith.
  2. Select the source table used to create the class, i.e the table called BTBRandomImage.
  3. Copy your namespace from your existing BTBRandomImageInfo.cs object
  4. ObjectQualifier not sure why we need this since it doesn’t get used. I’m just going to enter REPLACE
  5. Then we are going to copy the code into your class file in Visual Studio, the file to copy this code to is BTBRandomImageInfo.cs.

BLL Info Class generation

 

Creating the BLL Controller Class

  1. Select the C# BLL Controller template
  2. Select the source table
  3. Set the IsSearchable option to false since we aren’t going to need to search our module
  4. Copy the namespace of the existing controller class into the NameSpace parameter
  5. Copy the namespace of the data provider class into the NameSpaceData parameter
  6. ObjectQualifier not sure why we need this since it doesn’t get used. I’m just going to enter REPLACE.
  7. Then I’m going to hit generate and copy only the class generated code into my existing controller class in Visual Studio called BTBRandomImageController.cs.

Genrating the controller class in CodeSmith

 

Creating the Data Provider Class

  1. Select the C# DataProvider template
  2. Select the source table for class
  3. ObjectQualifier not sure why we need this since it doesn’t get used. I’m just going to enter REPLACE.
  4. Hit generate then copy the abstract method region over the top of the existing region in your class file in Visual Studio called DataProvider.cs.

Generating the data provider methods in CodeSmith

Creating the SqlDataProvider

  1. Select the C# SqlDataProvider template
  2. Select the source table for class
  3. ObjectQualifier not sure why we need this since it doesn’t get used. I’m just going to enter REPLACE.
  4. Select all the generated code and replace the existing “BTBRandom Image” region in the SqlDataProvider.cs class.
  5. We need to do a find and replace since we don’t need the object qualifier that was inserted in front of all the usp names in this code.

Generating the SqlDataProvider methods with CodeSmith

 

Right if you’re still with me we’ve created a good base that we can now get started with developing our module. Before we do let’s try a build to make sure everything is ok.

Did you get some errors when you tried to build? That’s ok, the Visual Studio wizard creates some code in the user controls which will be invalid now since we have changed the underlying controller, info and data access objects.

So let’s go ahead and fix these things so we can at least get our module to build.

First delete the Settings.ascx control, our module will not have any specific module settings so we don’t need this.

Next take a look at the BTBRandomImageEdit.ascx.cs file at line 98, here we have the code created by the wizard that is causing a problem since we have changed the info object properties. Comment out line 98 and 99 for now.

Now if you try building the module again you should now be ok.

<< Previous Page   Next Page >>

Privacy PolicyTerms and ConditionsCopyright © 2005 - 2010 BiteTheBullet.co.uk