Introducing jBlogMvc

ok

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

  1. Storefront MVC Series by Rob Conery.
  2. Stephen Walther Excellent MVC Tips and Forum series.
  3. Of course Scott Gu's mvc announcements and demos.
  4. Phil Haack blog.
  5. Steve Sanderson
  6. Emad Ibrahim the creator of Yonkly the open source twitter clone built on ASP.NET MVC and jQuery.
  7. Matt Hawley
  8. ASP.NET MVC tagged articles on DotNetKicks
  9. 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 :

 solution

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.

database

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.


Posted

in

,

by

Tags:

Comments

11 responses to “Introducing jBlogMvc”

  1. celik Avatar

    It is actually a great idea. Best way to learn something is using it.

  2. asp.net Avatar

    Good idea for blog based on MVC and jQuery. Good luck!

  3. Amr Avatar

    @celik , @asp.net
    Thank you I really hope this project ends with something useful not only for me but for the community as well.

  4. Emad Ibrahim Avatar

    I love jQuery and asp.net mvc. I can’t wait for the next post…

  5. Łukasz Sowa Avatar

    I’ve written blog engine that I’m currently using (unfortunately in Polish ;)) and it was great joy (sources here: http://lukaszsowa.pl/Content/downloads/hLog.zip – however it’s not the most recent version). I wish you the same, good luck! I’m waiting for the next post! And I suggest you to add some unit tests to the code, it’s also interesting subject!

  6. Amr Avatar

    @Emad
    I am one of the fans of your blog, and I am learning a lot from yonkly.
    Thanks for the comment, hope you like the rest of the series.

  7. Amr Avatar

    @Likasz
    Yes actually I found like 3 to 6 blog engines projects that are found on codeplex (not complete) but I having fun while developing it :), and like I said, the main thing behind this project is learning, I just downloaded your blog it looks nice on your site I’ll definitely look into it and get back to you.
    About unit tests I will consider them, in my next or after next posts don’t know yet.
    Thanks for the comment.

  8. Vasilio Ruzanni Avatar
    Vasilio Ruzanni

    Nice post! Especially good for those who want to learn AspnetMvc and jQuery the same way.

    But what about testing? The beauty of MVC Framework is also in it’s great testability!

  9. lee Avatar

    Excellent… I was thinking about doing something similar to learn myself, this is going to be a great help in my learning curve – Thanks again, and I’ll keep popping back in for the next installments 🙂

  10. CarlH Avatar
    CarlH

    Why ain’t site.master and error404.aspx in /views/shared/? and why are some of the filenames all lowercase? Shouldn’t the Body field in the database be a Text, nvarchar(max) holds only 4000 chars.

  11. Amr Avatar

    @Vasilio Ruzanni,
    @lee
    Thank you very much hope next parts will hold much extra stuff.

    @CarlH
    There is no constraints to put my master page or error page in the shared folder or not, actually its just a folder where the view engine looks inside it to find the files.
    About the casing, there is no other requirements its just I got used to them, however I might change them in next version.
    Finally about the nText and nvarchar(max) it is recommended to use nvarchar(max) rather than text (http://msdn.microsoft.com/en-us/library/ms178158.aspx) as it will be removed in next versions and they already have equal capacity. which is up to 2^31 bytes of character.

Leave a Reply

Your email address will not be published. Required fields are marked *