<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Brian David Berman: Technical Blog</title>
	<atom:link href="http://briandberman.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://briandberman.wordpress.com</link>
	<description></description>
	<lastBuildDate>Sun, 22 Jan 2012 01:26:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='briandberman.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Brian David Berman: Technical Blog</title>
		<link>http://briandberman.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://briandberman.wordpress.com/osd.xml" title="Brian David Berman: Technical Blog" />
	<atom:link rel='hub' href='http://briandberman.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Killing multiple birds with one Picasa</title>
		<link>http://briandberman.wordpress.com/2012/01/22/killing-multiple-birds-with-one-picasa/</link>
		<comments>http://briandberman.wordpress.com/2012/01/22/killing-multiple-birds-with-one-picasa/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 00:18:45 +0000</pubDate>
		<dc:creator>briandberman</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Business]]></category>

		<guid isPermaLink="false">http://briandberman.wordpress.com/?p=27</guid>
		<description><![CDATA[Last year, my wife Justine and I started a photography business. To be fair, she is the real talent of the company while I just handle the finances, legal, and web presence (social media, website, etc.) We quickly realized that we needed a way to attract clients and after doing extensive research we agreed that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briandberman.wordpress.com&amp;blog=7478844&amp;post=27&amp;subd=briandberman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Last year, my wife Justine and I started a photography business.  To be fair, she is the real talent of the company while I just handle the finances, legal, and web presence (social media, website, etc.)  We quickly realized that we needed a way to attract clients and after doing extensive research we agreed that online advertising was the way to go and defined our primary marketing conversion path as such:</p>
<ol>
<li>Potential client finds us through a website that we advertise on</li>
<li>Potential client decides, based on our ad, that we fit their style and seem like a good fit</li>
<li>Potential client clicks a link in our ad and is brought to our website</li>
<li>Our website immediately shows various image galleries of our work</li>
<li>Potential client enjoys what they see and fills out the contact form on our website</li>
<li>We are notified by email that someone is interested in our services</li>
<li>Conversion complete</li>
</ol>
<p>The area that I am going to touch on today is step 4 from above, the <strong>image gallery</strong>.  Now, this seems like a no brainer to implement.  There are literally hundreds of image gallery projects out there that I can download, extend and use on our site, right?  Wrong.</p>
<p>By &#8220;wrong&#8221;, I mean &#8220;wrong, if you are me&#8221; and by &#8220;me&#8221;, I mean &#8220;married to my wife&#8221;.  Let&#8217;s just say she is particular when it comes to her work and what we were seeing out there for existing photo galleries just wasn&#8217;t doing it for us.  The only exception would have been a couple Flash-based photo galleries and that was obviously out of the question.  So one thing led to another and I built a home-grown photo gallery in jQuery and everyone was happy.</p>
<table>
<tbody>
<tr>
<td><a href="http://briandberman.files.wordpress.com/2012/01/screen-shot-2012-01-14-at-12-45-04-pm1.png"><img class="alignnone size-medium wp-image-35" title="Photo Gallery" src="http://briandberman.files.wordpress.com/2012/01/screen-shot-2012-01-14-at-12-45-04-pm1.png?w=300&#038;h=201" alt="Screenshot of Photo Gallery" width="300" height="201" /></a></td>
<td>The gallery code I designed was powered by a collection of JSON objects.  The JSON object looks as follows:</p>
<pre style="overflow:scroll;background:#FFFFE0;border:1px black solid;font-weight:bold;font-family:Courier, 'Courier New', monospace;padding:4px;">{
  LargeImage: "http://test.com/largeImage.jpg",
  ThumbImage: "http://test.com/thumbImage.jpg"
  AlternateText: "Some alt text",
  Order: 6,
  Page: 1,
}</pre>
</td>
</tr>
</tbody>
</table>
<p>But the happiness was short-lived.  Short-lived because I didn&#8217;t consider the workflow for updating the galleries.    How would she update the galleries?  Would I have to be involved every time?  Can the sizing of the thumbnails be automated at least?</p>
<p>It turned out that I would have to be involved every time she wanted to add photos to a gallery.  Let&#8217;s say for example, she wanted to add 10 photos from a wedding photo shoot.  She would provide me with the images and thumbnails (custom cropped thumbnails which means automation wasn&#8217;t possible.)  I would then have to upload the new images to our development environment to view them with the other photos.  If this was the end of this manual process, I probably would have been ok with it, but it wasn&#8217;t.  Now I needed to work with her while she had me try different arrangements of thumbnails to see what looked right together.  At the time, this involved me manually updating the JSON object, changing the &#8220;Order&#8221; property over and over until she was happy with the arrangement of the thumbnails.  As you can imagine, this process was rather time consuming, especially at the frequency in which she wanted to update and keep the galleries fresh.  So I had to think of a solution.</p>
<p>At one point, I played with the idea of creating a user interface that allowed her to upload images and thumbnails and have her move images around (drag and drop) until she was happy with the arrangement, then she could press &#8220;submit&#8221; or &#8220;save&#8221; and it would generate the JSON collection that the site would read.  I was very close to implementing this but then it hit me.  I had previously been unsuccessful when trying to incorporate a third party tool, but I had an idea that I knew would end this manual process and allow me to completely remove myself from it.  Enter Google!</p>
<p><a href="http://picasaweb.google.com" target="_blank"><img class="alignnone size-full wp-image-63" title="pwa-en_US" src="http://briandberman.files.wordpress.com/2012/01/pwa-en_us.gif?w=720" alt=""   /></a></p>
<p>If you don&#8217;t know already, Google offers a pretty nice service for hosting images called <a title="Picasa Web Albums" href="picasaweb.google.com" target="_blank">Picasa Web Albums</a> (PWA).  It allows you to store, tag, share and host images for free.  It even includes a very cool drag-and-drop HTML5 uploader in the browser.  But the most important feature, and the key to bringing this altogether, was something called the <a href="http://code.google.com/apis/gdata/" target="_blank">Google Data Protocol</a>.  Specifically, the APIs within the <strong>Google.GData.Photos</strong> namespace.  What this allows us to do is set up galleries within Picasa Web Albums and have the order, configuration, and even meta data entered there drive our website with very little code.</p>
<table>
<tbody>
<tr>
<td><a href="http://briandberman.files.wordpress.com/2012/01/thumbsblog1.jpg"><img class="alignnone size-medium wp-image-54" title="Thumbnails in Picasa Web Albums" src="http://briandberman.files.wordpress.com/2012/01/thumbsblog1.jpg?w=300&#038;h=245" alt="Thumbnails in Picasa Web Albums" width="300" height="245" /></a></td>
<td><a href="http://briandberman.files.wordpress.com/2012/01/thumbsblog2.jpg"><img class="alignnone size-medium wp-image-59" title="Website gallery" src="http://briandberman.files.wordpress.com/2012/01/thumbsblog2.jpg?w=300&#038;h=245" alt="Website gallery" width="300" height="245" /></a></td>
</tr>
<tr>
<td style="text-align:center;font-style:italic;" colspan="2">left: album set up in Picasa Web Albumsright: website automatically driven from Picasa Web Albums</td>
</tr>
</tbody>
</table>
<p>So how does all this work?  It&#8217;s really quite simple.  In order to create and manage a gallery, you have to do the following:</p>
<ul>
<li>Create 2 new albums in PWA, one for large images and another for thumbnails.  Name the albums something such as <em>FuzzyOnes</em> and <em>FuzzyOnesThumbs </em>respectively.</li>
<li>Upload thumbnail images into <em>FuzzyOnesThumbs</em> first.  This is where we will manage the order of images.  We can drag, drop, move, arrange, etc. until we are happy with everything.  The only thing we need to be concerned with is that the uploaded images are sized properly and have <em>-Thumb</em> in the filename, such as <em>HappyDog-Thumb.jpg</em>.</li>
<li>Upload large images into <em>FuzzyOnes</em> next.  Once again, we need to make sure the images are sized properly and that they <strong>don&#8217;t</strong> have <em>-Thumb</em> in the filename, such as <em>HappyDog.jpg</em>.  The naming is what ties the images together later on.</li>
</ul>
<div>Once the albums are set up, the website does the rest of the work.  Remember before how I mentioned that our gallery code simply takes a collection of JSON objects?  The gallery code doesn&#8217;t care where the images come from or where they are hosted.  If they are in the collection of JSON objects, they will be rendered.</div>
<div></div>
<div>So the only work that remains is consuming the data from PWA via the APIs within Google.GData.Photos, mapping them to a model that mirrors my JSON object and serializing it so my gallery code can do it&#8217;s thing.</div>
<div></div>
<div>My jQuery image gallery calls out to the following ASP.NET MVC route:</div>
<div>
<pre style="overflow:scroll;background:#FFFFE0;border:1px black solid;font-weight:bold;font-family:Courier, 'Courier New', monospace;padding:4px;">$(document).ready(function () {
     $.ajax({
          async: true,
          type: "POST",
          url: "../Galleries/Load/" + GalleryName,
          dataType: "json",
          complete: function (data) {
...</pre>
<p>The ajax requests calls out to GalleriesController and executes the Load() method:</p>
<pre style="overflow:scroll;background:#FFFFE0;border:1px black solid;font-weight:bold;font-family:Courier, 'Courier New', monospace;padding:4px;">public class GalleriesController : Controller
{
     public JsonResult Load(string galleryName)
     {
          var galleryService = new GalleryService();
          return Json(galleryService.GetPhotos(galleryName), JsonRequestBehavior.AllowGet);
     }
}</pre>
</div>
<div>The Load() method instantiates GalleryService and calls the GetPhotos() method, which returns a collection GalleryImage:</div>
<div>
<pre style="overflow:scroll;background:#FFFFE0;border:1px black solid;font-weight:bold;font-family:Courier, 'Courier New', monospace;padding:4px;">public class GalleryImage
{
     public string LargeImage { get; set; }
     public string ThumbImage { get; set; }
     public string AlternateText { get; set; }
     public int Order { get; set; }
     public int Page { get; set; }
}</pre>
</div>
<pre style="overflow:scroll;background:#FFFFE0;border:1px black solid;font-weight:bold;font-family:Courier, 'Courier New', monospace;padding:4px;">public class GalleryService
{
     public List GetPhotos(string galleryName)
     {
          var picasaGalleryService = new PicasaGalleryService(galleryName);
          return picasaGalleryService.GalleryImages;
     }
}</pre>
<p>GalleryService instantiates a more specific PicasaGalleryService, which exposes a GalleryImages property of type List</p>
<pre style="overflow:scroll;background:#FFFFE0;border:1px black solid;font-weight:bold;font-family:Courier, 'Courier New', monospace;padding:4px;">public class PicasaGalleryService
{
     private const int ImagesPerPage = 24;
     public List GalleryImages;

     public PicasaGalleryService(string galleryName)
     {
          GalleryImages = new List();

          var orderCounter = 1;
          var pageCounter = 1;

          foreach (var image in getImageSets(galleryName))
          {
               GalleryImages.Add(new GalleryImage
                    {
                         LargeImage = image.Value,
                         ThumbImage = image.Key,
                         Order = orderCounter,
                         Page = pageCounter
                    });

              pageCounter = ((orderCounter%ImagesPerPage) == 0) ? (pageCounter + 1) : pageCounter;
              orderCounter++;
          }
     }

     private static Dictionary getImageSets(string galleryName)
     {
          var picasaService = new PicasaService("Gallery");

          var thumbnailImageQuery = new PhotoQuery(PicasaQuery.CreatePicasaUri(ConfigurationSettings.AppSettings["GoogleUsername"], ConfigurationSettings.AppSettings[galleryName + "Thumbs"]));
          var thumbnailImageFeed = picasaService.Query(thumbnailImageQuery);

          var largePhotoQuery = new PhotoQuery(PicasaQuery.CreatePicasaUri(ConfigurationSettings.AppSettings["GoogleUsername"], ConfigurationSettings.AppSettings[galleryName]));
          var largePhotoFeed = picasaService.Query(largePhotoQuery);

          var imageSets = new Dictionary();

          foreach (var thumbnailImage in thumbnailImageFeed.Entries)
          {
               var proposedLargeImage = thumbnailImage.Title.Text.Replace("-Thumb", "");

               var largeImage = largePhotoFeed.Entries.Where(lpf =&gt; lpf.Content.AbsoluteUri.Contains(proposedLargeImage));

               if (largeImage.Count() == 1)
               {
                    imageSets.Add(thumbnailImage.Content.AbsoluteUri, largeImage.Single().Content.AbsoluteUri);
               }
          }

          return imageSets;
     }
}</pre>
<p><em>Note:  I have created app settings in the web.config to hold the Google username and the numeric representations of the PWA album name.</em></p>
<p>We are now in &#8220;set it and forget it&#8221; mode.</p>
<p>Now, the title of the blog post alludes to killing multiple birds with one stone (Picasa), so let&#8217;s recap what we have accomplished:</p>
<ul>
<li>My wife can now manage her photo galleries via her Google account with Picasa Web Albums and our website will mirror it automatically.</li>
<li>I no longer have to be involved in the process of managing these galleries.</li>
<li>Less files to manage when creating builds, since all the gallery images exist on Google&#8217;s servers now.</li>
<li>I was able to remove all our photo gallery images from our hosting server, which saves space, bandwidth and money.</li>
<li>The content distribution of these images is now managed by Google, which means a faster and more reliable experience for our users.</li>
<li>The backup and maintenance of these images is now managed by Google, which again means more reliability.</li>
</ul>
<p>That&#8217;s it.  Thanks.  If anyone out there has any comments, please let me know.</p>
<br />Filed under: <a href='http://briandberman.wordpress.com/category/asp-net-mvc/'>ASP.NET MVC</a>, <a href='http://briandberman.wordpress.com/category/business/'>Business</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/briandberman.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/briandberman.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/briandberman.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/briandberman.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/briandberman.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/briandberman.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/briandberman.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/briandberman.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/briandberman.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/briandberman.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/briandberman.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/briandberman.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/briandberman.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/briandberman.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briandberman.wordpress.com&amp;blog=7478844&amp;post=27&amp;subd=briandberman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://briandberman.wordpress.com/2012/01/22/killing-multiple-birds-with-one-picasa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/989981e8c41a8df14685a57217a98a46?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brian Berman</media:title>
		</media:content>

		<media:content url="http://briandberman.files.wordpress.com/2012/01/screen-shot-2012-01-14-at-12-45-04-pm1.png?w=300" medium="image">
			<media:title type="html">Photo Gallery</media:title>
		</media:content>

		<media:content url="http://briandberman.files.wordpress.com/2012/01/pwa-en_us.gif" medium="image">
			<media:title type="html">pwa-en_US</media:title>
		</media:content>

		<media:content url="http://briandberman.files.wordpress.com/2012/01/thumbsblog1.jpg?w=300" medium="image">
			<media:title type="html">Thumbnails in Picasa Web Albums</media:title>
		</media:content>

		<media:content url="http://briandberman.files.wordpress.com/2012/01/thumbsblog2.jpg?w=300" medium="image">
			<media:title type="html">Website gallery</media:title>
		</media:content>
	</item>
		<item>
		<title>Super Simple Repository Pattern Example</title>
		<link>http://briandberman.wordpress.com/2009/05/07/super-simple-repository-pattern-example/</link>
		<comments>http://briandberman.wordpress.com/2009/05/07/super-simple-repository-pattern-example/#comments</comments>
		<pubDate>Thu, 07 May 2009 20:52:57 +0000</pubDate>
		<dc:creator>briandberman</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>

		<guid isPermaLink="false">http://briandberman.wordpress.com/2009/05/07/super-simple-repository-pattern-example/</guid>
		<description><![CDATA[After reading Chapter 1 of Professional ASP.NET MVC 1.0, I got a nice introduction to the “repository” pattern.  Using a repository helps us separate concerns, which is a big part of (but not limited to) ASP.NET MVC.  Let’s start off really simple by looking at a table (called Employees) I created and dragged into the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briandberman.wordpress.com&amp;blog=7478844&amp;post=21&amp;subd=briandberman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After reading <a href="http://www.tinyurl.com/aspnetmvc" target="_blank">Chapter 1</a> of <em><a href="http://www.amazon.com/Professional-ASP-NET-MVC-1-0-Conery/dp/0470384611" target="_blank">Professional ASP.NET MVC 1.0</a></em>, I got a nice introduction to the “repository” pattern.  Using a repository helps us separate concerns, which is a big part of (but not limited to) ASP.NET MVC.  Let’s start off really simple by looking at a table (called <em>Employees</em>) I created and dragged into the LINQ to SQL Designer in Visual Studio 2008:</p>
<p><a href="http://briandberman.files.wordpress.com/2009/05/image.png"><img style="display:inline;border-width:0;" title="image" src="http://briandberman.files.wordpress.com/2009/05/image_thumb.png?w=244&#038;h=217" alt="image" width="244" height="217" border="0" /></a></p>
<p>Once we save our .dbml file, Visual Studio 2008 creates an “Employee” class that exposes the available properties, allowing us to persist data back to our database.  A simple way to add a new record to this table is as follows:</p>
<div id="codeSnippetWrapper" style="font-size:8pt;overflow:auto;width:97.5%;cursor:text;direction:ltr;max-height:200px;line-height:12pt;">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 1:</span> CompanyDataContext companyDataContext = <span style="color:#0000ff;">new</span> CompanyDataContext();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 2:</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 3:</span> Employee employee = <span style="color:#0000ff;">new</span> Employee();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 4:</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 5:</span> employee.LastName = <span style="color:#006080;">"Berman"</span>;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 6:</span> employee.FirstName = <span style="color:#006080;">"Brian"</span>;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 7:</span> employee.JobTitle = <span style="color:#006080;">"Software Engineer"</span>;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 8:</span> employee.Extension = <span style="color:#006080;">"1234"</span>;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 9:</span> employee.HireDate = DateTime.Parse(<span style="color:#006080;">"01/01/2006"</span>);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 10:</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 11:</span> companyDataContext.Employees.InsertOnSubmit(employee);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 12:</span> companyDataContext.SubmitChanges();</pre>
</div>
</div>
<p>The above produces the following result in the database:</p>
<p><a href="http://briandberman.files.wordpress.com/2009/05/image1.png"><img style="display:inline;border-width:0;" title="image" src="http://briandberman.files.wordpress.com/2009/05/image_thumb1.png?w=710&#038;h=69" alt="image" width="710" height="69" border="0" /></a></p>
<p>While this may be a fine way to update a table, it is difficult to test and requires mention of the data context, as well as data storage implementation (LINQ to SQL) methods.  To fix this, we can add a “repository” layer:</p>
<div id="codeSnippetWrapper" style="font-size:8pt;overflow:auto;width:97.5%;cursor:text;direction:ltr;max-height:200px;line-height:12pt;">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 1:</span> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> EmployeeRepository</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 2:</span> {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 3:</span>     CompanyDataContext companyDataContext = <span style="color:#0000ff;">new</span> CompanyDataContext();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 4:</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 5:</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> Add(Employee employee)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 6:</span>     {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 7:</span>         companyDataContext.Employees.InsertOnSubmit(employee);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 8:</span>     }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 9:</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 10:</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> Save()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 11:</span>     {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 12:</span>         companyDataContext.SubmitChanges();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 13:</span>     }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 14:</span> }</pre>
</div>
</div>
<p>The repository class contains the data storage implementation activity, including the data context and methods.  We can then change our original code to the following:</p>
<div id="codeSnippetWrapper" style="font-size:8pt;overflow:auto;width:97.5%;cursor:text;direction:ltr;max-height:200px;line-height:12pt;">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 1:</span> EmployeeRepository employeeRepository = <span style="color:#0000ff;">new</span> EmployeeRepository();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 2:</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 3:</span> Employee employee = <span style="color:#0000ff;">new</span> Employee();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 4:</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 5:</span> employee.LastName = <span style="color:#006080;">"Yandle"</span>;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 6:</span> employee.FirstName = <span style="color:#006080;">"Justine"</span>;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 7:</span> employee.JobTitle = <span style="color:#006080;">"Teacher"</span>;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 8:</span> employee.Extension = <span style="color:#006080;">"5678"</span>;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 9:</span> employee.HireDate = DateTime.Parse(<span style="color:#006080;">"01/01/2008"</span>);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 10:</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 11:</span> employeeRepository.Add(employee);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 12:</span> employeeRepository.Save();</pre>
</div>
</div>
<p>While this example doesn’t use less code, you will notice the “insert” and “save” functionality is handled through the database repository methods Add() and Save().  The result of running this code (along with our original code) produces the following in the database:</p>
<p><a href="http://briandberman.files.wordpress.com/2009/05/image2.png"><img style="display:inline;border-width:0;" title="image" src="http://briandberman.files.wordpress.com/2009/05/image_thumb2.png?w=707&#038;h=92" alt="image" width="707" height="92" border="0" /></a></p>
<p>This allows our code to be more testable since we could now write unit tests against our objects without a database (mock objects).  Although less likely, we are also able to swap out our data storage implementation (e.g. going from LINQ to SQL to LINQ to Entities) at a later time in a much smoother fashion.  Some other example methods within the EmployeeRepository class are as follows:</p>
<div id="codeSnippetWrapper" style="font-size:8pt;overflow:auto;width:97.5%;cursor:text;direction:ltr;max-height:200px;line-height:12pt;">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 1:</span> <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> EmployeeRepository</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 2:</span>     {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 3:</span>         CompanyDataContext companyDataContext = <span style="color:#0000ff;">new</span> CompanyDataContext();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 4:</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 5:</span>         <span style="color:#0000ff;">public</span> IQueryable&lt;Employee&gt; FindAllEmployees()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 6:</span>         {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 7:</span>             <span style="color:#0000ff;">return</span> companyDataContext.Employees;</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 8:</span>         }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 9:</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 10:</span>         <span style="color:#0000ff;">public</span> Employee GetEmployee(<span style="color:#0000ff;">int</span> id)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 11:</span>         {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 12:</span>             <span style="color:#0000ff;">return</span> companyDataContext.Employees.SingleOrDefault(e =&gt; e.EmployeeId == id);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 13:</span>         }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 14:</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 15:</span>         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> Add(Employee employee)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 16:</span>         {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 17:</span>             companyDataContext.Employees.InsertOnSubmit(employee);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 18:</span>         }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 19:</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 20:</span>         <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> Save()</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 21:</span>         {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 22:</span>             companyDataContext.SubmitChanges();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 23:</span>         }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;"><span style="color:#606060;"> 24:</span>     }</pre>
</div>
</div>
<p>Hopefully this explains the repository pattern in the simplest way possible.  Please feel free to leave comments.  I am still learning and wouldn’t mind learning more through comments!  <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<br />Posted in ASP.NET, ASP.NET MVC  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/briandberman.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/briandberman.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/briandberman.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/briandberman.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/briandberman.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/briandberman.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/briandberman.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/briandberman.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/briandberman.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/briandberman.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/briandberman.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/briandberman.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/briandberman.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/briandberman.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briandberman.wordpress.com&amp;blog=7478844&amp;post=21&amp;subd=briandberman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://briandberman.wordpress.com/2009/05/07/super-simple-repository-pattern-example/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/989981e8c41a8df14685a57217a98a46?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brian Berman</media:title>
		</media:content>

		<media:content url="http://briandberman.files.wordpress.com/2009/05/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://briandberman.files.wordpress.com/2009/05/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://briandberman.files.wordpress.com/2009/05/image_thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Fun with ASP.NET MVC leads to nice oO Design discovery (Updated)</title>
		<link>http://briandberman.wordpress.com/2009/04/24/fun-with-aspnet-mvc-leads-to-nice-oo-design-discovery/</link>
		<comments>http://briandberman.wordpress.com/2009/04/24/fun-with-aspnet-mvc-leads-to-nice-oo-design-discovery/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 03:47:42 +0000</pubDate>
		<dc:creator>briandberman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://briandberman.wordpress.com/2009/04/24/fun-with-aspnet-mvc-leads-to-nice-oo-design-discovery/</guid>
		<description><![CDATA[I was working through the first chapter of Professional ASP.NET MVC 1.0 and came across a really slick way to handle business rule violations.&#160; Below is some sample code written by Scott Guthrie for the NerdDinner project. 1: // 2: // POST: /Dinners/Edit/2 3: [AcceptVerbs(HttpVerbs.Post)] 4: public ActionResult Edit(int id, FormCollection formValues) 5: { 6: [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briandberman.wordpress.com&amp;blog=7478844&amp;post=7&amp;subd=briandberman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was working through the first chapter of <a href="http://www.amazon.com/gp/product/0470384611?ie=UTF8&amp;tag=diabeticbooks&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0470384611" target="_blank">Professional ASP.NET MVC 1.0</a> and came across a really slick way to handle business rule violations.&#160; Below is some sample code written by <a href="http://weblogs.asp.net/scottgu/" target="_blank">Scott Guthrie</a> for the <a href="http://www.nerddinner.com" target="_blank">NerdDinner</a> project.</p>
<div id="codeSnippetWrapper" style="border-right:silver 1px solid;border-top:silver 1px solid;font-size:8pt;overflow:auto;border-left:silver 1px solid;width:97.5%;cursor:text;direction:ltr;line-height:12pt;border-bottom:silver 1px solid;font-family:&#39;background-color:#f4f4f4;text-align:left;margin:20px 0 10px;padding:4px;">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&#39;background-color:#f4f4f4;text-align:left;border-style:none;padding:0;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&#39;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#008000;">//</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&#39;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span> <span style="color:#008000;">// POST: /Dinners/Edit/2</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&#39;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span> [AcceptVerbs(HttpVerbs.Post)]</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&#39;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span> <span style="color:#0000ff;">public</span> ActionResult Edit(<span style="color:#0000ff;">int</span> id, FormCollection formValues)</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&#39;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span> {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&#39;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>     Dinner dinner = dinnerRepository.GetDinner(id);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&#39;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span>&#160; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&#39;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span>     <span style="color:#0000ff;">try</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&#39;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span>     {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&#39;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span>         UpdateModel(dinner);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&#39;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span>&#160; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&#39;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span>         dinnerRepository.Save();</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&#39;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  13:</span>&#160; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&#39;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  14:</span>         <span style="color:#0000ff;">return</span> RedirectToAction(<span style="color:#006080;">&quot;Details&quot;</span>, <span style="color:#0000ff;">new</span> { id = dinner.DinnerId });</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&#39;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  15:</span>&#160; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&#39;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  16:</span>     }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&#39;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  17:</span>&#160; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&#39;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  18:</span>     <span style="color:#0000ff;">catch</span></pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&#39;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  19:</span>     {</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&#39;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  20:</span>         ModelState.AddRuleViolations(dinner.GetRuleViolations());</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&#39;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  21:</span>&#160; </pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&#39;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  22:</span>         <span style="color:#0000ff;">return</span> View(dinner);</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&#39;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  23:</span>     }</pre>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&#39;background-color:#f4f4f4;text-align:left;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  24:</span> }</pre>
</p></div>
</div>
<p>What’s going on here is that we are editing a Dinner object.&#160; We pass in the ID of the Dinner we are editing as well as the form values from the form post.&#160; At line 6, we instantiate a new dinner object based on the ID passed in.&#160; We then “try” (lines 8-13) to update the model and save it back to the database.&#160; If all goes well and the posted data is valid, the Dinner is saved and we are redirected (line 12).&#160; If, on the other hand, something goes wrong (incorrect or incomplete data is passed in), it safe to say that a business rule has been violated.&#160; Enter our “catch” (lines 14-19).&#160; Since something went wrong, we update our model state with the violations from the GetRuleViolations method on the Dinner object.&#160; We then return the dinner, showing the user the violations to fix.&#160; I think this is, not only a great ASP.NET MVC example, but also a good OO design example. </p>
<p>(Update – Styles for code have been fixed. <strike>I am aware that I have some formatting issues.&#160; I just opened this blog and haven’t looked at the CSS yet.&#160; Thanks.</strike>)</p>
<br />Posted in Uncategorized  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/briandberman.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/briandberman.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/briandberman.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/briandberman.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/briandberman.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/briandberman.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/briandberman.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/briandberman.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/briandberman.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/briandberman.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/briandberman.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/briandberman.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/briandberman.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/briandberman.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briandberman.wordpress.com&amp;blog=7478844&amp;post=7&amp;subd=briandberman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://briandberman.wordpress.com/2009/04/24/fun-with-aspnet-mvc-leads-to-nice-oo-design-discovery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/989981e8c41a8df14685a57217a98a46?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brian Berman</media:title>
		</media:content>
	</item>
		<item>
		<title>My First Tech Blog Post</title>
		<link>http://briandberman.wordpress.com/2009/04/23/my-first-tech-blog-post/</link>
		<comments>http://briandberman.wordpress.com/2009/04/23/my-first-tech-blog-post/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 20:12:18 +0000</pubDate>
		<dc:creator>briandberman</dc:creator>
				<category><![CDATA[Thoughts]]></category>

		<guid isPermaLink="false">http://briandberman.wordpress.com/2009/04/23/my-first-tech-blog-post/</guid>
		<description><![CDATA[After watching Scott Hanselman’s video on Social Networking for Developers, I’ve decided to take the plunge into technical blogging.&#160; I’ll be posting thoughts, code samples, and anything I think is interesting and cool, when it comes to software development.&#160; Thanks. Posted in Thoughts<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briandberman.wordpress.com&amp;blog=7478844&amp;post=4&amp;subd=briandberman&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After watching Scott Hanselman’s <a href="http://www.hanselman.com/blog/SocialNetworkingForDevelopersConferenceTalkVideo.aspx">video</a> on Social Networking for Developers, I’ve decided to take the plunge into technical blogging.&#160; I’ll be posting thoughts, code samples, and anything I think is interesting and cool, when it comes to software development.&#160; Thanks.  </p>
<br />Posted in Thoughts  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/briandberman.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/briandberman.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/briandberman.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/briandberman.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/briandberman.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/briandberman.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/briandberman.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/briandberman.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/briandberman.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/briandberman.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/briandberman.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/briandberman.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/briandberman.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/briandberman.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=briandberman.wordpress.com&amp;blog=7478844&amp;post=4&amp;subd=briandberman&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://briandberman.wordpress.com/2009/04/23/my-first-tech-blog-post/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/989981e8c41a8df14685a57217a98a46?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brian Berman</media:title>
		</media:content>
	</item>
	</channel>
</rss>
