Overview Support Download Purchase

Contact Database Example

The contact database in this example will store basic information (first name, last name, etc.) about the contacts and also their home and work address. The site includes a password protected area where you can edit contacts and see their history, edit security access, and change the objects themselves. The site is globalized and currently has translations for Spanish. The ContactDatabase project is located in the Examples folder. All further references to files in this example are assuming the ContactDatabase project.

Part 1 (Object Usage)

Before looking at the web controls in this example, we will focus on working with the objects directly. This allows for maximum flexibility in using the TurnObject in your custom code while still retaining their ability to change on the fly. The ObjectUsage.aspx page shows various methods for using the TurnObjects.

To start, run the application as in the first contact form example and enter some contacts to work with.

Creating an Instance of A TurnObject

Creating an empty TurnObject is easily done by specifing the system and the object schema name. In the ObjectUsage.aspx.cs file a ContactPerson object is created when the page loads.

Copy 

Loading an Object

An example of loading an object is shown in the loadButton_Click method. Make sure the data type of the primary key is correct. You can check if the object was loaded by checking the IsLoaded property.

Copy 

Load a Collection of Objects

You can load all the objects of a collection or filter the objects to just load the ones you want. The first this you will need is an empty collection. We can see the code to do this in the getContacts_Click method.

Copy 

Once you have an empty collection you can fill it by calling the Load method to load all items or the LoadBy method to filter by a property. In the ObjectUsage.aspx page all the items are loaded if a filter is not specified. If a filter is specifed then the filter property is set and the items are loaded by the filter.

Copy 

Using a Collection of Objects

Once the collection is loaded you can access the items of the collection by using an indexer. The ObjectUsage.aspx lists the items by "FirstName" and "LastName".

Copy 

Creating a View from a Collection of Objects

The CollectionView allows you to create a DataTable that contains only columns of data that you want to use. It also allows you to show columns that are in a child objects of the main object. The address object in the contact database is a good example of this.

The getContactGrid_Click method uses the CollectionView to bind the view to a GridView. The first thing it does is get a collection using the same method as in the getContacts_Click method. The following code is then used to create a DataTable containing the view.

Copy 

Part 2 (Contact Database Admin)

In this example:

  1. Create an admin user in the AdminUser database.
  2. Examine the LogIn control.
  3. Run the application log into the admin.

For this part of the example we will look at the protected part of the application. The TurnObjects system has a login control, and a masterpage control to check that a user has logged in and has access to the current page. The combination of these two controls allows you to easily create an protected section of your application.

Create an Admin User

You will need an initial user in the database that will be used to log into the protected area for the first time. Manually add a record to the AdminUser table that you will want to use as your login. Use the following SQL to insert a new user.

Copy 

The LogIn Control

The login control needs to know the name of the system and the name of the object that will hold the user login information. The object must be of the type IUser (this is indicated by the BaseSchema of the AdminUser being set to 'UserItem'. In the contact example the system is ContactData and the object is the AdminUser. The cssPrefix has been set to LogIn so that the style of the login control can be different from the rest of the site.

Contact Form Interface

UserPage MasterPage

The UserPage is a .NET master page that has a check to see if the user is logged in and has access to the current page. The SecurityPrefix is the security item that holds access information for the admin site and the pages in it. Security will be explained in depth during part 3. Looking at the AdminPage.master.cs file we see the following:

Copy 

The above code sets the system and schema for the user object, the security prefix for user access, and the page for the login control if the user is not logged in. The name of the page will be used to determine if the user has access to that page. In part 3 you will see that the page names and their access are defined in the AdminSite section of the security configuration.

User Menu

The UserMenu control allows you to create a menu with links that are presented to the user only if they have access to that page in the protected area. The SecurityPrefix of the menu will be set to 'AdminSite' just like the master page. If a link starts with http it is accepted as a public external link and no security check is done.

Copy 

Security Control

The security control is a web interface to change the security access for users. It directly changes the SecurityRoles.xml file. The contact database admin uses the control on the Security.aspx page.

System Editor

The system editor control is a web interface to chnage the system configuration files for all the systems in the TurnObjects config folder. It directly changes each XML file for the systems. The contact database admin uses the control on the SystemEditor.aspx page.

Part 3 (Security)

Security in the contact database example is setup for the user with an ID of 1. This should be the user that you created in part 2. If you look at the SecurityRoles.xml file you can see the access that this user has.

The rights are hierarchical in nature so that rights assigned to a system are applied to all it's schemas, rights applied to a schema are applied to all the items that are stored in that schema. You can also apply rights to individual items by referring to their ID's. Access can be yes, no or none. None signifies that access will be deferred to the child object.

In the contact security configuration you can see that the user with ID of 1 is a member of the AdminUser role. This role has all the access set to yes meaning the user has full access to the system. Try changing some of the access item properties to see how they effect the grid and forms.

Part 4 (Globalization)

The globalization files for the contact database are in the App_GlobalResources folder. There is a TurnObjects.resx file that translates the built-in controls and individual .resx files for translating the contact objects.

TurnObjects.resx

Opening the TurnObjects.es.resx file you will see the Spanish translations for all the text on the built-in web controls. You can use this file as a template for translating more languages or for use in other applications.

TurnObject Resource Files

Each TurnObject has a .resx file of it's own. If you look at ContactPerson.es.resx you will see that each property name in the ContactPerson schema has been translated to Spanish. This translation is what will be displayed instead of the InputPrompt text for the property.

Options Resource Files

The ContactStatus.es.resx and Prefix.es.resx have also been supplied to provide the translations for the ContactStatus and Prefix options for the contact data. The name of the resource, not the text, is used as the identifier and must be present in the system XML file. You can see this in the ContactData.xml file.


© 2008 TurnObjects All rights reserved.  Legal  |  Privacy