Return to Article List

Click, Click….Shazam!


It’s the end of Coder Foundry Master Class week 3, and I’m beginning to appreciate what you can accomplish with just a few clicks in Visual Studio

Most of this week was dedicated to our blog-building venture. In a nutshell, the project (which is the software behind this blog) requires a couple of database tables for posts and comments, along with views and CRUD logic for interacting with them. Anyone can view posts, but only registered users can add comments, and of course only the Admin can add posts.  There’s also a moderator role. It’s nothing that requires software genius to design, but before meeting MVC .NET, I would have expected to spend a considerable amount of time implementing the details of creating the database tables, writing the CRUD logic, generating all the pages for viewing, editing, deleting, and putting in the code to register users and control who can do what. But that didn’t happen. Instead, I discovered the joys of scaffolding and code first development. Basically it works like this:

  • Open Visual Studio 2013 Community Edition and create a new project (a Visual C# ASP.NET Web application in this case)
  • Specify your database connection info (the database doesn’t have to exist yet)
  • Create the code for the C# objects you need (i.e. posts and comments). These are your models.
  • Go to the Controllers folder, right click and choose Add Controller, then select MVC 5 Controller with views, using Entity Framework
  • Select  one of your  models to base the controller on  (such as Post), give it a name, and click Add
  • Wait a few seconds while Visual Studio builds a complete set of Create, Delete, Detail, and Index views and loads up the controller with the logic that makes them fetch, write, and display data from the database (which you still haven’t created yet) based on your model.
  • Repeat as needed for your other models (i.e. Comments)

Now you have a fully functional web app complete with CRUD code. Equally astonishing, the first time you try to access your (still non-existent) database with this program, Entity Framework will create the database tables for you, including foreign key relationships and tables needed for user management.

Depending on your needs, you'll need to do a minor-to-major amount of editing from here to finish your app, but the out-of-the-box functionality is amazing.

As you might imagine, all this auto-magic goodness involves a whole bunch of files. At this point, my simple blog project contains over 500 - I’m so glad I didn’t have to write them all! Of course that does include a bunch of files for my two plugins, TinyMCE and SyntaxHighlighter. That's one reason that a big part of the MVC .Net learning curve is figuring out what to look for where.

That just touches the surface of what crossed my keyboard this week - for example I also experimented with Ajax and JQuery and took a first look at LINQ syntax and lambda expressions. I’m well into information overload, but in order to spare you from the same, I’ll end this blog entry here. Until next week…



On 01/30/15 David.Jolly said:
Another fine post. I will look forward to reading more of them. Good luck with the rest of boot camp.

Add Comment

Return to Article List