Check out the Latest Articles:
Mitigating Circumstances System Beta Version 2

It’s been quite a while since my last post, however I haven’t just been resting on my laurels and not doing anything. I have recently started my first role as a C# developer since graduating. Since beginning work I have continued to read many computing books, the result of this has been a rewrite of my final year project in order to capture this knowledge in a practical format.

Previously in Version 1 of the project I implemented Data Access using LinqtoSQL only using the automated objects it generated. This was all well and good and an extremely quick way of being able to perform CRUD operations for an application. The problem however was this did not really model my application in an Object Orientated way. I ended up using so many database repositories in my controllers populating objects which relationally were attached to other objects, but were not attached in my object model. This just made things messy and seriously over complicated simple things, such as outputting a students problems along with all the problem communications and assessment extensions that problem may contain.

All of my repositories and interfaces of those repositories were contained within the ASP.NET MVC Web project. I ended up with a Model folder with a ridiculous amount of classes in it and not very much logical organisation and separation.

In the rewrite of the system I have completely separated out the Model of the application. Creating this in a C# class library which is then consumed by the WebUI project. The Model project contains an Entities namespace which contains the Objects I require to build the system. These Entities also contain LINQ to Entities mapping attributes which create the data access layer for my application. I found using LINQ attribute mapping much better than simply automatically generating my access. Now when I retrieve a Problem you can access all the Assessment Extensions, and Problem Communications that are attached to it via Collections without the need for additional repository calls, whilst also accessing the individual objects it contains such as Communication Type. This made things a lot more easier when outputting data in the Views.

The Model library also contains a Concrete namespace where the repositories are stored and the LINQ commands to retrieve and manipulate data are contained. The repositories are virtually the same as the previous project. It containts a Abstract namespace which contains the interfaces to these repositories for consuming projects to use. A Services namespace which provides Static methods for consuming projects to create or update records whilst ensuring those records pass validation checks. Finally it contains Validation Helpers which enable the validation to be performed independently of the consuming technology. If I had used the MVC Data Annotations this would only have worked for MVC applications. However by performing Validation the way I have if I were to create a WinForms application which reused the model the validation should still work. I would only need to create a helper class for my WinForms project which attached the Validation Errors to the ModelState.

My Models namespace of my WebUI project now only contains ViewModels separating out the presentation logic from the core of the system.

By performing these changes it made it much easier to implement AJAX functionality through the use of JQuery! Forms with no file uploads are now submitted Asynchronously creating a much more responsive user experience. I had previously worked with AJAX by reading Head First AJAX and I feel because of this I found JQuery extremely easy to pick up. Its an extremely useful framework and allows a developer to create a responsive interface very quickly and easily. With tools such as Chrome Developer Tools and Firebug any issues could easily be debugged, the root cause traced and quickly resolved.

I have also created my PDF reports in a different fashion to previously. I could not discover a way to use the previous method of RDLC files using Objects and not a database dataset. The way I previously completed this task just no longer made sense. I was using a database view to retrieve all the information and having to create groups in the RDLC template to put related records together. This was just no longer logical when my model already did all this for me when I retrieved student objects from my repository. I managed to find an Open Source library called iTextSharp which makes it easy to create and write to PDF files. The PDF files are not overly pretty but they will improve given I have time to work on the project.

One subject of interest I found fascinating was being able to create multi-language websites. The new version of this system should translate into English, French, German, and Spanish depending on what language preference the user has their browser set to. This was extremely easy to implement, and I thought it would be much harder. It was implemented by creating a separate resource C# class library, which contains resource files. Every resource file contains the same Key which identifies a piece of text but obviously different text depending on the language the resource file is for. These keys are then used throughout the UI of the application outputting text where required.

The system also now contains the ability to send emails which I have working on my web server. Now when users create a Problem and wish to create a Follow Up Meeting they can create an Outlook Appointment, or an iCal meeting. The iCal meeting is sent as an attachment to the users registered Email address. The Outlook Appointment however requires Outlook or an Exchange Server to be installed on the Server which I don’t have so this is not functioning on my demonstration web server. Also when Reports are created beforehand the User can select additional Users they wish to mail the report to as well as themselves. The report is also sent as an attachment.

I have also used Ninject to handle my dependency injection. Creating a Ninject Controller Factory which binds my repositories to their interface implementation and injects them when a controller is instantiated.

This blog post is a high level overview of the techniques I have used in the new version of the project to allow people who may view the source (below). To have an idea of what they are looking at! However I do intend to write posts detailing and explaining the techniques that I have used when I get time (Probably over the next month or so).

Please be kind when viewing the application as it is not completely finished but is more a preview of something which I have been doing. I am aware there are still bugs within the system mainly with data creates and updates. Whilst Server Validation feedback to the view is also missing as I am trying to figure out a way to do this using AJAX. Also I have only really tested the Site in Chrome, Firefox, and IE9 please do not use an IE version lower than this as the JQuery may play up, and I really haven’t got the time to solve these niggles :-) !

Source Code: Here
Project URL: http://ajaxmcs.jonathanstowell.com
Feel free to sign up to test the Email notifications.

Thanks for reading,

Jonathan



  1. It‘s quite in here! Why not leave a response?