Platinum Partner
dotnet,frameworks,javascript,jquery,asp.net,.net & windows,client-side,ajax & scripting

Introducing jBlogMvc

In this part, I announced jBlogMvc the ASP.NET MVC and jQuery blogengine which I build in order to learn more about the two new technologies, and discuss the version zero of the blog engine.

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!


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

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 = "" }
);

}

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.

 

public partial class Post
{
public string RelativeLink
{
get
{
return VirtualPathUtility.ToAbsolute("~/post/") + Slug;
}
}
}

 

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.

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");
}
}

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

 

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"; } }
}

 

Published at DZone with permission of {{ articles[0].authors[0].realName }}, DZone MVB. (source)

Opinions expressed by DZone contributors are their own.

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}