From Visual Studio, click File | New Project and select ASP.NET MVC 3 Application. Name it "Backend."
![Add New Project Add New Project](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_tHgg-2YmYQ4wm1HdZvNau0rJex_hKiMQkORKiDrFFpamLbOxU_dtqQimJrx3MMPA9AL7Ocf3UAeqbq4yMJOhz8XAwuMLCoadsJCSowCoKyCKiU5PwkHLQ_uJzoIciDJJg4DRK4TO4f9frpo4FOoRuOIj38AbeNdZ6rfs-J79yE1NMpcUshtKkxAfcwE9uxHfA2XeiWObqnegNlkV6KVTLiquFzdznkhUg1RA=s0-d)
Click Internet Application and make sure Use HTML 5 is checked.
![New ASP.NET MVC 3 Project New ASP.NET MVC 3 Project](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_vR0mBJ2cOTdbSO-P9dQ7D9jJ4BzOJQZXMUms66KkzQJKnauzCvZLdHSIpNKp2cxWqtwPOoe-vN6aMIpYs8TMG4guqN7NI5AxtcIZnmlMO_BIuwaeg3ao8Fg8zyrTBaTgvaMejQRGMxxzEAAoBs0cpeXM-W0dOm6Ro2SqBSe6Mlc0rYKDbnWlfrg7sSXbEzirYVMXaGKLTNKT512w5pMKAO7MqV7dm9INBAabJ4HZE_lTJTtmja03mjJ_gzEgFURz0Z6ECozw=s0-d)
Check out your packages.config if you like, or noticed the installed packages in NuGet.
![Add Library Package Reference Add Library Package Reference](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_sTsvukmGERQjdeBL0_71Z3BuCQbUmKRme8guBtD_l39Au-RrkfH9VmAe1Ey2E9NIERQpzfLQkZXYUIlXvERk7ofmNPf9x5r_knh_8hcYPNGqdqpfZ9nVn2duFGQkN9ODjPJyOMrereZkBz0mNHTJ77uEpGhXyFUvL21I4yfO9GZiPEEDpooGtYTFWJa6nNYirVS22Yzz9j4aEIFPIY7xEIikyHNq4q5SY0nVActtjmil_7UAy0-7Ip2cgZnH54GOwOhfNsJIto=s0-d)
Right click on Models, select Add Class. Name the file Podcast.cs. Here is your Entity Framework 4.1 Code First model:
Now, make sure you compile. I press Ctrl-Shift-B to do this, but you can also do it from the Build Menu.
Right click on Controllers, select Add Controller. Make an EpisodeController. Pick the Entity Framework template (remember you can make your own, if you like. More on this soon!) and click the Data context class dropdown and Make a PodcastContext. Your dialog will look like this.
![Add Controller Add Controller](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_tPrdErWfJ3F0imMK_nwkz9CqJxKoIrEKa-hYMs2hU50azjrG1-UXxoR5jKMOy6nlaCNeLpZCNN_YHAY4tPQRp8xk_hEhLNau9Itq_XFPlgQ-ROX8c_Xq4c1Xfqp_HSqgvQ-Gpn69g0o6qc8IgBju7om5ePOBvdIlwy_z3t9BcuUplN28T0PjImtR6ClIvlSF8NUMlpwZEZ77qj9DHKUARxEHNqKXK3ou0r-PI59jpmuAuGlA=s0-d)
Compile. Now do the same thing for MusicTrack. Now, check our your Solution Explorer and all your scaffolded code.
![Wow, that's a lot of scaffolded code! Wow, that's a lot of scaffolded code!](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_sy5Zr_25udFSF2WovKGWk6E4jPp1ygCGoDUPdBebNVI5mz_bf9Jc3K5-ZQ0rZFQ6IerpKlrxvP7DnIC0DQtxXCzFJoUX9bHrU0Nk5NVei1gt_MmHLVGRMrDUWV-tfVUhRaKyzTajqjz5Q335bN0QkdcrLHjtSS5PUPsQVNQ4AR-tfIWV_x1RxZueYkEpLa-CzvY6jBlTrq8syP1Zk=s0-d)
Right click on References and select Add Library Reference. You can also do this from the Tools | Library Package Manager menu.
Click on Online on the left side to access NuGet.org, and in the upper right corner, search for "EntityFramework.SqlServerCompact" to bring down support for SQL Server Compact Edition.
![Add Library Package Reference (52) Add Library Package Reference (52)](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_sAaQvWcHgtxqhWJupRrB2zx4GqLxsE-MYjFRluecPKsyNSDfgSxopbv-vr6UyMBLGnicZRHcSrVhGPS4eaZigNVkXEGjYEV7zvaTQCEbkOZpLmvUUWhn6O1_LaB1k2AQhnyHxTIN0bPSjH5P0_ivSK3OzchSDV82AbxZwpuYLP06qJsrlw1uxGX_uEW-Iha4PZBL6zMPB8eLiVnQUnsM-SezEvcVXkQcJBoI8maC1J4dfFFRkC_CXkkD_7KLLUZYP64HzIjiZY=s0-d)
Now, run your app and visit /Episode. Make an episode or three, then visit /MusicTrack.
![TDLAdminSite TDLAdminSite](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_v7gwLugsZ3FlJsPQvAb5q-sBeV88QEPQQUhDOUVvPSk4Q90q8IzppcUPMC3IDh-DrGgoaYVkRdUTEXu8LTcil9tFQQM5LwgHhm6RSQtSUI3zGbwb6kucZEfznNpkqBS_IOtTHp8r6Q6ZthmjKpYz6L2gUskiiCwiS61nYZAYnvDkvLkHDAyBevPTNTB-bLae3J9b29dm8_kye3N_wgcOZrWSys4XC2wQ=s0-d)
Ok, so now we need a frontend for our podcast site. We got one from http://www.templatemonster.com. They can sell you a template and then bring it down directly into Web Matrix. Since you may not want to buy a template just for this demo, you'll want to come up with some basic template for yourself. WebMatrix comes with a Bakery Template and some others, so perhaps try one of those. Perhaps the Bakery Template after clicking Web Site From Template.
We used a template like this, but like I said, I can't give it to you.
![TDL Front TDL Front](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_saIWToojNDr9_NsVviaHDmvVrhFEOL1odpKRbaKvvdmxzOT95hpDOW-IY8muZdKnfjz5S0lbi-08ZS90lyQrmHBVNvNCaCRcVe_rpiHZedicB3IFQ0sqA9tF9AqM2q0VxiWISwVfCjaU05aPWYSmlcme9_9i5R0wJb_ipbmPPqjD4hg11QoVvO7tbLYZhDThas7Q8wvxA8SJzin2wmP_BgljOnggpUn1o=s0-d)
Maybe you can start here? ;)
![Fourth Coffee - Home - Windows Internet Explorer (54) Fourth Coffee - Home - Windows Internet Explorer (54)](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_tNzksz8QDNybIpziI9JBvLu30B4WPHwzH3YFDNsa1wdhzPv-62i6t8CniWvy3hf6lT27LAQMGeX3pgS0EdZtwUUWcwMaPyj1XoGUIRgRNJVLYxzpcKOLVqywkA4xIyL50O1jojaQyjolmLZ3dZ6bSXbkHO4OJ13V9vQehLelzeRgxzKxsyl-MgyUBnRsrgM_snVPps5mN4HxgA_SZHUd6AS2yh3YNtNSZY3hYRYi4HdGZqXSLpnde5KXXfrT1lDGpgssvq8qvXE9CM-exxlc0hRrouLqgSUYSCOepTO87d_W6W=s0-d)
You can right click on App_Data and bring in the SQL Database File (Mine was called TDL.sdf, but yours may vary) from the first step with Add Existing File. Some templates include databases. You can use them if you like, or delete them.
![Files in Web Matrix Files in Web Matrix](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_sq6XQOqwDXlgzc4lMmVN6C5t6v_VGGsbwP30KkovPs9vORb3xN653oc_h7hPYnF7dvBYqkDB1de9CqfKnomkvnyHAnLLP2CsYkqmERNEDEtfqVxiRRzr2-xemYQ2KhfDz7CljDUOdyjDtXgQInplxk7CFT7EKz2egM68B17zY5qX7iVOH_ZGrek4Blaczo_D0RkiEaHymzuoiFfTbeEgTADLkY=s0-d)
For the demo, I had two database files. The one I created in the first step, and then another one that I already filled out with all our shows earlier.
![Lots of data in the database Lots of data in the database](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_sBBXqG3NM5kYduhhhlErTV-WCKh5Qooicvm-0BJRqQjMg9WYt8kMI_9SXMHwQMSCA1rTgGuAlBS7zEcZH_V3pGTbXmK7bBk-zoi4uW9Z-lzLvnyCwuETygXLYJCT0N4aBZL-Qptum5P_sSnzT15vifmT6vZDSej7PumlM0rPkQ5aSVIIaB8bnVXhhI54mkbuKIkL2o10TiKUH083rgtA=s0-d)
If you're using the Bakery Template it's a little different from our template since it's about products and includes a featured product, but it's still a cool template.
I skipped some steps in the keynote to make the demo flow, for example, my images were already in an images folder. For this blog post, I'll copy the images from http://www.thisdeveloperslife.com (or you can grab your family photos or whatever) and put them in /images.
![Show Images Show Images](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_si6vClSYU5cRVV9ILmscSKFFGPWuPUVPEAoMe0XdxbHXUOiX8PDFr0vwu2cTbOhU0nt1HoYfw_5M-sr_8Cj3lTA1RjcUu2CIWIcyrFq8M2nHbmGJAi4jfCPLlH7QIRvrQfqZ9ELWIwtz5Ty0zNXUceAu9zE1jGaAfUmWWkgvR6WLlxn0LnackMH9HZHQY_rZDhbdwm_RQxdjcXrLDeSrrgRrQrhmyKoVUO=s0-d)
Next, I'll change the Default.cshtml for my (now) Bakery Template. I'll updated things in the Razor code like Products to Episode, and making sure I'm using column names from the TDL database, and not the Bakery one.
It ends up being not much code. It's not as pretty as the more complex template we used, but you get the idea. You can take templates from anywhere (they don't need to be Razor templates, just HTML!) and then sprinkle in a little Razor code like I did.
I give you, "This Developer's Life - Cheesy Bakery Template Edition":
![This Developer's Life Site - Cheesy Bakery Edition This Developer's Life Site - Cheesy Bakery Edition](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_v13_A30eI3WuM0mgE-laAPegNowf9LMuEDczwa1wJDMw9nVIhPBlJ_2shRbEjfT9dcKl1svnR-P8O1ktpwH3LKHVWKXWCIMZzA6MjuLHFkNEf9C1iL1CcxVMt0LsfGyn1KRnKv0mOJ5YeG0Yi-c438UUrn_TiwVTvV7jUuf8CbCW02I6FczSOa7y35VdtA0nqLU0Cke9kmIn8iE5eQlBGsAYO6-wUBMxhNvwdevkAy2RgYD6YDdY4sAJz3UN0RNOyR97y2doAL2WIf2Ao5mMi3aB9y_qxtTfdCUy0ZNiv9zUE=s0-d)
Now if you like, click on Site, then ASP.NET Web Pages Administration (or, just visit /_Admin) and setup your password. I skipped the creating of a password in the keynote and used a site with an existing password we'd setup earlier. Read the instructions carefully.
![Bakery6 - Microsoft WebMatrix (57) Bakery6 - Microsoft WebMatrix (57)](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_sQmiaSv0JRG3ZwFBALtWIUzKF0xB6c_GNeDbgWggo9eKE04D2hWd5w9iarQLntYGdFsu-vLuvzRHK_2OlA0Yh7NyAcgtXFZKSjs1S4-fkHkL2-MGGKsluX7kMlFfenLM3aN-VwQidD2LLhmsfUCKcq_tZdUFXWCC7p0n8CNok_WYKw2LDvY8st9tq0lmYRtrksKwLL-Ge-0TnuejwUF-5Dr6A1qYAdAavaXtD8gHfLTQ3ZcJx5efT6wrFrmXbBrBTFzUopfmz7=s0-d)
The Web Pages Administration site runs local as part of your site, and is how WebMatrix talks to NuGet.org. From here you can get helpers like the Facebook helper, Twitter helper, Disqus helper and more. Some of these helpers, like Disqus, require more setup that I showed in the keynote. For example, you have to visit Disqus.com, sign up for an account and get an API key, then tell your site about it before you use the helper. The Facebook and Twitter helpers also include lots of options, for example, the Twitter helper can be vertical or horizontal, and look different ways. Also check out IE9ify, a jQuery plugin and NuGet package that lets you add JumpLists and IE9 stuff to your site.
![ASP.NET Web Pages Administration - Package Manager - Windows Internet Explorer (58) ASP.NET Web Pages Administration - Package Manager - Windows Internet Explorer (58)](https://lh3.googleusercontent.com/blogger_img_proxy/AEn0k_v9bzvGCtBsAv1JEaRqPek2B9Ov-YQnmEGKzlHS37UXVY-pWajKJO8P44Hq67dRCUre93FfTDzeeOSIle6-XUzeFJAevXu-mcvNIckrvVL4-aDjgw_hrmt1FtOBs5b-WEgmI2mrRAak87-Yl8ZhBe2kqR1e4RhFMQvnqmXEIvMDtscUVxN8F6mTGMhiEaGc_wHcgw085Rn4tfet5zpX8sfNWULqPWSsiaX4lNjXSVJYeTdBTvBk6via5Ej2iSuZM3OtnQcQTGBLMJFqs6eLx75NaVys3Qn42rro3UNw7hr6S6IG6ulsYAMwuRM4_fjIFyO58jG8yY1VDEx96jCg2UvVpUBc6srB=s0-d)
At the end, I clicked Publish and then just imported the settings file from my ISP. WebMatrix then used WebDeploy to send my site and database to a server. That server was internal to the Mix keynote demo network, but Rob Conery and deployed the site the exact same way at 3am Tues morning. The public site at http://www.thisdeveloperslife.com was written by Rob and I in WebMatrix, uses HTML5, jQuery with SQL CE for a database and is deployed with WebDeploy and sports a tidy HTML5 theme Rob wrote, inspired by the one from the demo.
I'll blog later in a separate post how I made the podcast player with HTML5 audio tags, jQuery and IE9 site pinning.
I hope you enjoy the products Dear Reader as much as we enjoyed building them!
© 2011 Scott Hanselman. All rights reserved.
Click Internet Application and make sure Use HTML 5 is checked.
Check out your packages.config if you like, or noticed the installed packages in NuGet.
Right click on Models, select Add Class. Name the file Podcast.cs. Here is your Entity Framework 4.1 Code First model:
namespace Backend.Models { public class Episode { public int Id { get; set; } [Required] public string Title { get; set; } public DateTime? PublishedAt { get; set; } public string Summary { get; set; } public string LeadImage { get; set; } public string ShortUrl { get; set; } public virtual ICollection<MusicTrack> MusicTracks { get; set; } } public class MusicTrack { public int Id { get; set; } public string Name { get; set; } public string URL { get; set; } public int EpisodeId { get; set; } public Episode Episode { get; set; } } }
Now, make sure you compile. I press Ctrl-Shift-B to do this, but you can also do it from the Build Menu.
Right click on Controllers, select Add Controller. Make an EpisodeController. Pick the Entity Framework template (remember you can make your own, if you like. More on this soon!) and click the Data context class dropdown and Make a PodcastContext. Your dialog will look like this.
Compile. Now do the same thing for MusicTrack. Now, check our your Solution Explorer and all your scaffolded code.
Right click on References and select Add Library Reference. You can also do this from the Tools | Library Package Manager menu.
Click on Online on the left side to access NuGet.org, and in the upper right corner, search for "EntityFramework.SqlServerCompact" to bring down support for SQL Server Compact Edition.
Now, run your app and visit /Episode. Make an episode or three, then visit /MusicTrack.
Homework for you - Extend the Backend Demo!
- Add the MvcScaffolding Nuget package and rerun the Add Controller commands. What's different?
- Add an Editor Template for DateTimes with a jQuery DatePicker
- Add different attributes like [StringLength] or [Range] to your Code First model. Delete the .SDF file in App_Data and re-run. How can you affect your database?
- Add some other NuGet packages like IE9ify. What cool features can you add like Jump Lists using Javascript?
WebMatrix - This Developer's Life Frontend Administration
Ok, so now we need a frontend for our podcast site. We got one from http://www.templatemonster.com. They can sell you a template and then bring it down directly into Web Matrix. Since you may not want to buy a template just for this demo, you'll want to come up with some basic template for yourself. WebMatrix comes with a Bakery Template and some others, so perhaps try one of those. Perhaps the Bakery Template after clicking Web Site From Template.
We used a template like this, but like I said, I can't give it to you.
Maybe you can start here? ;)
You can right click on App_Data and bring in the SQL Database File (Mine was called TDL.sdf, but yours may vary) from the first step with Add Existing File. Some templates include databases. You can use them if you like, or delete them.
For the demo, I had two database files. The one I created in the first step, and then another one that I already filled out with all our shows earlier.
If you're using the Bakery Template it's a little different from our template since it's about products and includes a featured product, but it's still a cool template.
I skipped some steps in the keynote to make the demo flow, for example, my images were already in an images folder. For this blog post, I'll copy the images from http://www.thisdeveloperslife.com (or you can grab your family photos or whatever) and put them in /images.
Next, I'll change the Default.cshtml for my (now) Bakery Template. I'll updated things in the Razor code like Products to Episode, and making sure I'm using column names from the TDL database, and not the Bakery one.
@{ Page.Title = "Home"; var db = Database.Open("TDL"); var shows = db.Query("SELECT * FROM Episodes").ToList(); } <h1>Welcome to This Developer's Life!</h1> <ul id="products"> @foreach (var s in shows) { <li class="product"> <div class="productInfo"> <h3>@s.Title</h3> <img class="product-image" src="@Href("~/Images/"+ s.LeadImage)" alt="Image of @s.Title" /> <p class="description">@s.Summary</p> </div> </li> } </ul>
It ends up being not much code. It's not as pretty as the more complex template we used, but you get the idea. You can take templates from anywhere (they don't need to be Razor templates, just HTML!) and then sprinkle in a little Razor code like I did.
I give you, "This Developer's Life - Cheesy Bakery Template Edition":
Now if you like, click on Site, then ASP.NET Web Pages Administration (or, just visit /_Admin) and setup your password. I skipped the creating of a password in the keynote and used a site with an existing password we'd setup earlier. Read the instructions carefully.
The Web Pages Administration site runs local as part of your site, and is how WebMatrix talks to NuGet.org. From here you can get helpers like the Facebook helper, Twitter helper, Disqus helper and more. Some of these helpers, like Disqus, require more setup that I showed in the keynote. For example, you have to visit Disqus.com, sign up for an account and get an API key, then tell your site about it before you use the helper. The Facebook and Twitter helpers also include lots of options, for example, the Twitter helper can be vertical or horizontal, and look different ways. Also check out IE9ify, a jQuery plugin and NuGet package that lets you add JumpLists and IE9 stuff to your site.
At the end, I clicked Publish and then just imported the settings file from my ISP. WebMatrix then used WebDeploy to send my site and database to a server. That server was internal to the Mix keynote demo network, but Rob Conery and deployed the site the exact same way at 3am Tues morning. The public site at http://www.thisdeveloperslife.com was written by Rob and I in WebMatrix, uses HTML5, jQuery with SQL CE for a database and is deployed with WebDeploy and sports a tidy HTML5 theme Rob wrote, inspired by the one from the demo.
I'll blog later in a separate post how I made the podcast player with HTML5 audio tags, jQuery and IE9 site pinning.
I hope you enjoy the products Dear Reader as much as we enjoyed building them!
© 2011 Scott Hanselman. All rights reserved.
No comments:
Post a Comment