Introducing jBlogMvc

by Amr Elsehemy 21. September 2008 00:03
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.

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

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

 

 

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.

Tags: , , ,

jBlogMvc

Comments

9/21/2008 2:51:01 AM #

trackback

Trackback from DotNetKicks.com

Introducing jBlogMvc

DotNetKicks.com |

9/21/2008 5:52:11 AM #

celik

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

celik Turkey |

9/21/2008 6:59:54 AM #

asp.net

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

asp.net Russia |

9/21/2008 7:41:12 AM #

Amr

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

Amr Egypt |

9/21/2008 9:25:46 AM #

Emad Ibrahim

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

Emad Ibrahim United States |

9/21/2008 3:07:46 PM #

Łukasz Sowa

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!

Łukasz Sowa Poland |

9/21/2008 4:11:13 PM #

Amr

@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.

Amr Egypt |

9/21/2008 4:14:42 PM #

Amr

@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 Smile, 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.

Amr Egypt |

9/21/2008 4:44:42 PM #

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!

Vasilio Ruzanni |

9/21/2008 10:30:20 PM #

lee

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 Smile

lee United Kingdom |

9/22/2008 12:11:14 AM #

pingback

Pingback from blog.cwa.me.uk

Reflective Perspective - Chris Alcock  » The Morning Brew #184

blog.cwa.me.uk |

9/22/2008 12:27:04 AM #

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.

CarlH Sweden |

9/22/2008 4:47:47 AM #

Amr

@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 (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.

Amr United States |

10/5/2008 10:23:41 AM #

pingback

Pingback from expertsadvice.in

Asp Web Sites - Attraction To The Site - EXPERTS ADVICE FORUM

expertsadvice.in |

10/5/2008 3:18:54 PM #

trackback

Trackback from #.think.in

#think.in Weekly Info-Dose #1 (29th Nov - 3rd Oct 2008)

#.think.in |

12/4/2008 5:05:52 AM #

trackback

Trackback from Web Development Community

Amr Elsehemy | Introducing jBlogMvc

Web Development Community |

1/26/2009 9:59:31 PM #

pingback

Pingback from icenter.eciou.net

Pro Information Center  » Blog Archive   » jBlogMvc Series Started! Keep tuned with Amr Elsehemy

icenter.eciou.net |

9/9/2009 5:13:47 PM #

pingback

Pingback from random.cgi-biz.com

JBLOGMVC -   Introducing jBlogMvc - Random Things To Blog

random.cgi-biz.com |

Comments are closed

About the author

Amr Elsehemy
MCSD C#.Net,
MCTS Sql 2005,
MCPD Enterprise
avatar
E-mail me Send mail

Calendar

<<  March 2010  >>
MoTuWeThFrSaSu
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar