Long time no posts, well I was studying Sharepoint 2007 technologies and actually started a series for development a while ago I just managed to write two introductory posts and didn't write more I have some ideas I'd love to share in sharepoint development which I hope to write about them some time in the future and complete the series. However, recently the new ASP.NET MVC framework has gathered some fame and actually I too got attached to it and I am keen to learn new technologies and so, also the jQuery javascript library has been the choice of most the .NET web developers community.
Its Time to Learn
So, I have read alot of blogs and articles on ASP.NET MVC which has a massive amount of resources (while not being beta yet), I also read the excellent book "jQuery in Action" and learned a lot from it I do recommend it for learning jquery. Now its time to utilize this learning in a simple application that experience the stuff I read about, then I stumbled across this article Want To Learn Web Programming? Write A Blog Engine so be it, I will build a (Simple-Fully featured) blog engine in order to learn more and use these two new kids on the block.
Of course, I will use ASP.NET MVC, jquery and finally I will use Sql Express as the datastore and Linq to Sql for dal.[more]
Where I learn from
Before starting building my blog series I would like to share the blogs I read to learn from ASP.NET MVC
- Storefront MVC Series by Rob Conery.
- Stephen Walther Excellent MVC Tips and Forum series.
- Of course Scott Gu's mvc announcements and demos.
- Phil Haack blog.
- Steve Sanderson
- Emad Ibrahim the creator of Yonkly the open source twitter clone built on ASP.NET MVC and jQuery.
- Matt Hawley
- ASP.NET MVC tagged articles on DotNetKicks
- The Official ASP.NET MVC forums.
Let's start
So, what's jBlogMvc? its a small blogengine I am going to build in an agile process, jBlogMvc if you haven't notice j stands for jQuery, Blog for the engine itself and Mvc for the ASP.NET MVC. I say here that this engine will be simple and complete I will try to add features as much as possible and build it in an extensible way like modern blog engines to enable themes, widgets and plugins. Also I need to point that the work on this blog engine is totally inspired from the great open source blog engines which include BlogEngine.NET, WordPress and other non blog engines as yonkly and many others.
What will part 0 cover ?
Other than announcing the blog engine, in this part I will have a version 0 that will have the following:
- Vistor
- Viewing posts By Chronological order.
- Viewing individual posts.
Ok show me some code!
Too much talking lets get to the code now, ok the solution is as shown in the figure consisting of the following :
The database
For this ZERO part I didn't include much for the blog engine, the only table I included is the Post table as shown below, I do believe this table will be expanded more by time and more parts in the series.
Routes
[code:c#]
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Posts",
"post/{slug}",
new { controller = "Home", action = "post" }
);
routes.MapRoute(
"Default",
"{action}/{id}",
new { controller = "Home", action = "Index", id = "" }
);
}
[/code]
Models
Just added here a dbml file (Linq to Sql DataContext) , and I added a PostEx.cs file and added a property for the Post, God Bless partial classes. PostEx.cs as shown in Listing 2.
[code:c#]
public partial class Post
{
public string RelativeLink
{
get
{
return VirtualPathUtility.ToAbsolute("~/post/") + Slug;
}
}
}
[/code]
Controllers
For now I only have one controller the HomeController which has simply 3 actions for now.
- index : Renders a view with all posts sorted in a chronological order
- post(slug) : Renders a view for the post with a matching slug if not found it renders error404 view
- premalink(guid) : Renders a view for the post with a matching guid if not found it renders error404 view
HomeController as shown in Listing 2.
[code:c#]
public class HomeController : Controller
{
/// <summary>
/// Renders a view with all posts sorted in a chronological order
/// </summary>
/// <returns></returns>
public ActionResult index()
{
var posts = Helpers.GetPostList() ?? new List<Post>();
return View(posts);
}
/// <summary>
/// Renders a view for the post with a matching slug
/// if not found it renders error404 view
/// </summary>
/// <param name="slug">Post slug to be matched</param>
public ActionResult post(string slug)
{
var post = Helpers.GetPostBySlug(slug);
return post != null ? View("single", post) : View("error404");
}
/// <summary>
/// Renders a view for the post with a matching premalink
/// if not found it renders error404 view
/// </summary>
/// <param name="id">Post premalink to be matched</param>
public ActionResult premalink(Guid id)
{
var post = Helpers.GetPostByPemalink(id);
return post != null ? View("single", post) : View("error404");
}
}
[/code]
Views
The solution now contains one master page for the overall site, three views, and one usercontrol
- site.Master : gives the overall look and feel for the site
- index.aspx : renders all posts.
- single.aspx : renders a single post.
- error404.aspx : to be rendered when a request to a non matching post slug or premalink
- _postView.ascx : the post template to be used
Utils
Two classes that help me
- Config: Contains some static properties that read from hard coded strings (in a version coming up should read from the web.config or even a database table).
- Helpers: just some common helper methods.
Config File
[code:c#]
public class Config
{
static public string BlogName { get { return "My Blog Name"; } }
static public string BlogDescription { get { return "This blog is built using the ASP.NET MVC framework."; } }
static public string BlogUrl { get { return VirtualPathUtility.ToAbsolute("~/"); } }
static public string Version { get { return "0.1.0.0"; } }
}
[/code]
Summary
In this part, I just announced jBlogMvc the ASP.NET MVC and jQuery blogengine which I build in order to learn more about the two new technologies (at least for me), so what do you think? you are most welcomed to leave comments.
Download version zero : jBlogMvc_version_0.zip (624.80 kb)
If you liked this blog post then please subscribe to this blog.
Leave a Reply