ASP project for UWS

This Academic Projects section is from the first version of this site and stays for historical completeness.

To gain academic credits during my time with UWS, as well as passing the MCTS exam I had to complete an ASP/ADO project as follows...

Scenario

You have been asked to create a web site to create a community of customers and franchisees of Fourth Coffee Ltd. Once they have registered on the site, franchisees can use it to publicise their café and customers can recommend their favourite café. People can also provide pictures of themselves enjoying your product and other profile information and comments that you can use with their permission.

At this early stage in your project you should construct a prototype of the web site, and implement enough of the functionality to obtain feedback as to whether you are on the right lines. Styling and artwork will be added later.

You should submit a zip file containing your web site project...

I've included that last line because straight off that made the decision for me to make this a VS Web Site project so I could include the database in the solution folder and just zip and mail the whole thing off. I'm not going into the database design here as that would be slightly off-topic (and it was only a couple of trivial tables) but once it was created I used aspnet_regsql to configure the membership provider to use the same one.

I used the VS ASP.NET configuration tool to create roles and, as there were only three (admins, franchisees and customers) I created a folder for each and used local web.config files for authorization.

A couple of more-or-less arbitrary decisions on the data-access side for practice and to test myself: I wanted to use the toolbox datasource controls on the .aspx pages and the LINQ 2 SQL classes on the back end. This raised an intriguing problem as to how to return a projected anonymous type to the calling ObjectDataSource control. I tried some suggestions from google that involved projecting into a custom class but that involved quite a bit of code and totally defeated the succinctness of the anonymity. I came up with simply returning an interface which is probably worth editing down to a snippet...

			
<DataObjectMethod(DataObjectMethodType.Select)> _
Shared Function GetShop(ByVal ShopId As Integer) As IQueryable
    Dim shop = (From s In ctx.Shops _
		Where s.ShopID = ShopId _
		Select New With _
		{s.ShopID, s.Name, s.Address, s.Description})
    Return shop
End Function
			

...the rest was largely drag-and-drop and configuring through the GUI.

Adding photos to the database was simply a matter of using a BinaryReader to get the stream of bytes from a FileUpload control into an array and passing it to the DataContext to convert to SQL binary, but then I had to figure out how to get them back as the binary that SQL returns appears to be a different animal to the desired byte array. The [Single] extension method of IQueryable to the rescue this time and another snippet, this one of the function the .ashx calls...

			
Shared Function GetPhotoBytes(ByVal ShopId As Integer) As Byte()
      Dim photoBytes = (From s In ctx.Shops _
                        Where s.ShopID = ShopId _
                        Select s.Photo).Single().ToArray()
      Return photoBytes
End Function
			

Finally, here's a VS screenshot to put the above into some sort of context (no pun intended).