<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>ProgramGood.Net - Project Run</title>
    <link>http://www.programgood.net/</link>
    <description>The journey to becoming a great programmer</description>
    <language>en-us</language>
    <copyright>Dave Mateer</copyright>
    <lastBuildDate>Mon, 15 Feb 2010 03:59:31 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.2.8279.16125</generator>
    <managingEditor>davemateer@gmail.com</managingEditor>
    <webMaster>davemateer@gmail.com</webMaster>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=6da2752b-b696-49cf-9541-127e55d50123</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,6da2752b-b696-49cf-9541-127e55d50123.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <wfw:comment>http://www.programgood.net/CommentView,guid,6da2752b-b696-49cf-9541-127e55d50123.aspx</wfw:comment>
      <wfw:commentRss>http://www.programgood.net/SyndicationService.asmx/GetEntryCommentsRss?guid=6da2752b-b696-49cf-9541-127e55d50123</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Both my asp.net web hosters advertised they are hosting on Server 2008, which meant
IIS7.  This makes things much easier when publishing an MVC site (to do with
routing apparently).  As I’d hosted my sites for years with these providers,
they were still on Win2003 (IIS6) boxes.  I just had to ask for an upgrade and
it was done.
</p>
        <p>
Upload to IIS7 and it just works!
</p>
        <p>
The first step was to see if routing worked on the default website.. it did!
</p>
        <p>
The next step – to publish up the NerdDinner app I’ve been going through on Rob Conery,
and get the database connected live.
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_2.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_thumb.png" width="644" height="355" />
          </a>
        </p>
        <p>
The crowd goes wild  - this is live and connecting to a database :-)
</p>
        <h3>Changing Namespace / Solution Name / Project Names
</h3>
        <p>
I had lots of namespace errors.. forgot to change default assembly namespace, which
meant linq to sql was in the wrong space.  However it is possible to change everything
very quickly – solution, project names, directly.  One gotcha was remembering
to delete everything on the live server so there weren’t 2 dll’s with the same object
names inside..
</p>
        <h3>Changing Default Page to Activity / upload live trick
</h3>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">routes.MapRoute(<br /><span style="color: #006080">"Default"</span>, <span style="color: #008000">//
Route name</span><br /><span style="color: #006080">"{controller}/{action}/{id}"</span>, <span style="color: #008000">//
URL with parameters</span><br /><span style="color: #0000ff">new</span> { controller = <span style="color: #006080">"Activity"</span>,
action = <span style="color: #006080">"Index"</span>, id = <span style="color: #006080">""</span> } <span style="color: #008000">//
Parameter defaults</span><br />
);</pre>
          <br />
        </div>
        <p>
        </p>
        <p>
Change controller = “Home” to controller = “Acitivity”
</p>
        <p>
I also implemented the copyifnewer.bat trick for easily going from dev to live which
is here: <a title="http://www.programgood.net/2010/01/28/WebConfigAutomatingDevAndLive.aspx" href="http://www.programgood.net/2010/01/28/WebConfigAutomatingDevAndLive.aspx">http://www.programgood.net/2010/01/28/WebConfigAutomatingDevAndLive.aspx</a></p>
        <p>
Run application working live with Create, Read, Update and Delete working.  Also
validation, which comes for free in the standard templates.
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_4.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_thumb_1.png" width="644" height="399" />
          </a>
        </p>
        <p>
DropDownList and Postbacks – covered in another post on this site.
</p>
        <p>
          <a title="http://www.mikesdotnetting.com/Article/128/Get-The-Drop-On-ASP.NET-MVC-DropDownLists" href="http://www.mikesdotnetting.com/Article/128/Get-The-Drop-On-ASP.NET-MVC-DropDownLists">http://www.mikesdotnetting.com/Article/128/Get-The-Drop-On-ASP.NET-MVC-DropDownLists</a>
        </p>
        <h4>Summary Page
</h4>
        <p>
I created another link in the master page for menu item:
</p>
        <p>
          <a href="http://www.mateerit.co.nz/run">www.mateerit.co.nz/run</a>
        </p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_8.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_thumb_3.png" width="332" height="105" />
          </a>
        </p>
        <p>
For the summary page I’m considering a ViewModel approach.
</p>
        <p>
Lets see if a simple new Summary controller will suffice
</p>
        <p>
Got to a stage.. was going to upload to github, but had db connection strings in there
which didn’t want in the history.. so looked at rebase in git.. want to make sure
before I play too much :-)
</p>
        <p>
 
</p>
        <h5>Creating a SQL View then Displaying it
</h5>
        <p>
Michael came up with an elegant solution which I’m trying.. so creating a SQL View:
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">SELECT</span> personid, 
<br />
DATEPART(week, <span style="color: #0000ff">date</span>) <span style="color: #0000ff">AS</span> Week, 
<br />
DATEPART(<span style="color: #0000ff">year</span>, <span style="color: #0000ff">date</span>) <span style="color: #0000ff">AS</span><span style="color: #0000ff">Year</span>,<br /><span style="color: #0000ff">SUM</span>(kilometres) <span style="color: #0000ff">AS</span> kilometres, 
<br /><span style="color: #0000ff">SUM</span>(hours) <span style="color: #0000ff">AS</span> hours<br /><span style="color: #0000ff">FROM</span> dbo.Activity<br /><span style="color: #0000ff">GROUP</span><span style="color: #0000ff">BY</span> personid,
DATEPART(week, <span style="color: #0000ff">date</span>), DATEPART(<span style="color: #0000ff">year</span>, <span style="color: #0000ff">date</span>)</pre>
          <br />
        </div>
        <p>
which gives a good summary output:
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_6.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_thumb_2.png" width="244" height="123" />
          </a>
        </p>
        <p>
The aim is to be able to see the summary of each week like this (this is the old webforms
version)
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_10.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_thumb_4.png" width="644" height="237" />
          </a>
        </p>
        <p>
linq to sql generated classes off the view.
</p>
        <p>
Michael did it like this:
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_12.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_thumb_5.png" width="588" height="168" />
          </a>
        </p>
        <p>
I’m on this:
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_14.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_thumb_6.png" width="321" height="210" />
          </a>
        </p>
        <h5>Passing Complex Data – Lists within Lists
</h5>
        <p>
As each person has data associated to them, a list within a list is good.
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_16.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_thumb_7.png" width="610" height="252" />
          </a>
        </p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">public</span>
            <span style="color: #0000ff">class</span> WeekSummary<br />
{<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">int</span> Personid;<br /><span style="color: #0000ff">public</span> string Personname;<br /><span style="color: #0000ff">public</span> List&lt;WeekSummaryData&gt; Persondata;<br />
}<br /><br /><span style="color: #0000ff">public</span><span style="color: #0000ff">class</span> WeekSummaryData<br />
{<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">double</span>?
Hours;<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">double</span>?
Kilometers;<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">int</span>?
Week;<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">int</span>? <span style="color: #0000ff">Year</span>;<br />
}</pre>
          <br />
        </div>
        <p>
Then in the repository:
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">public</span> IQueryable&lt;WeekSummary&gt;
GetWeeklySummary()<br />
{<br />
var weekSummaries = <span style="color: #0000ff">from</span> p <span style="color: #0000ff">in</span> db.Persons<br />
orderby p.personname<br />
let <span style="color: #0000ff">data</span> = GetWeeklySummaryData(p.personid)<br /><span style="color: #0000ff">select</span><span style="color: #0000ff">new</span> WeekSummary
{Personid = p.personid, 
<br />
Personname = p.personname, 
<br />
Persondata = <span style="color: #0000ff">new</span> List&lt;WeekSummaryData&gt;(<span style="color: #0000ff">data</span>)};<br /><span style="color: #0000ff">return</span> weekSummaries;<br />
}<br /><br />
IQueryable&lt;WeekSummaryData&gt; GetWeeklySummaryData(<span style="color: #0000ff">int</span> personid)<br />
{<br />
var summary = <span style="color: #0000ff">from</span> w <span style="color: #0000ff">in</span> db.weekly_summaries<br /><span style="color: #0000ff">where</span> w.personid == personid<br />
orderby w.<span style="color: #0000ff">Year</span> , w.Week<br /><span style="color: #0000ff">select</span><span style="color: #0000ff">new</span> WeekSummaryData
{Hours = w.hours, 
<br />
Kilometers = w.kilometres, 
<br />
Week = w.Week, 
<br /><span style="color: #0000ff">Year</span> = w.<span style="color: #0000ff">Year</span>};<br /><span style="color: #0000ff">return</span> summary;<br />
}</pre>
          <br />
        </div>
        <p>
** understand this linq
</p>
        <p>
Then in the controller:
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">public</span> ActionResult <span style="color: #0000ff">Index</span>()<br />
{<br />
var summaries = _repository.GetWeeklySummary();<br /><span style="color: #0000ff">return</span><span style="color: #0000ff">View</span>(summaries);<br />
}</pre>
          <br />
        </div>
        <p>
and the view:
</p>
        <p>
** understand this rendering
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">&lt;% <span style="color: #0000ff">foreach</span> (WeekSummary
weekSummary <span style="color: #0000ff">in</span> Model) {<br />
%&gt;<br />
&lt;table&gt;<br />
&lt;tr&gt;<br />
&lt;th&gt;&lt;/th&gt;<br />
&lt;% <span style="color: #0000ff">foreach</span> (WeekSummaryData weekSummaryData <span style="color: #0000ff">in</span> weekSummary.Persondata)
{ %&gt;<br />
&lt;th&gt;&lt;%=Html.Encode(weekSummaryData.Week) + <span style="color: #006080">"/"</span> +
Html.Encode(weekSummaryData.Year) %&gt;&lt;/th&gt;<br />
&lt;%}%&gt;<br />
&lt;/tr&gt;<br />
&lt;tr&gt;<br />
&lt;td&gt;<br />
&lt;%=Html.Encode(weekSummary.Personname) %&gt;<br />
&lt;/td&gt;<br />
&lt;% <span style="color: #0000ff">foreach</span> (WeekSummaryData week <span style="color: #0000ff">in</span> weekSummary.Persondata)
{ %&gt;<br />
&lt;td&gt;&lt;%=Html.Encode(week.Hours) + <span style="color: #006080">"hrs"</span> %&gt;&lt;br
/&gt;&lt;%=Html.Encode(week.Kilometers) + <span style="color: #006080">"kms"</span> %&gt;&lt;/td&gt;<br />
&lt;%}%&gt;<br />
&lt;/tr&gt;<br />
&lt;/table&gt;<br />
&lt;% } %&gt;</pre>
          <br />
        </div>
        <p>
 
</p>
        <p>
refactor code with an interface for testing
</p>
        <p>
unit test do
</p>
        <p>
automock
</p>
        <p>
jquery
</p>
        <p>
tooling to help make form crud websites faster… 
</p>
        <p>
reproting tooling
</p>
        <p>
mvc2
</p>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=6da2752b-b696-49cf-9541-127e55d50123" />
      </body>
      <title>Going Live with ASP.NET MVC</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,6da2752b-b696-49cf-9541-127e55d50123.aspx</guid>
      <link>http://www.programgood.net/2010/02/15/GoingLiveWithASPNETMVC.aspx</link>
      <pubDate>Mon, 15 Feb 2010 03:59:31 GMT</pubDate>
      <description>&lt;p&gt;
Both my asp.net web hosters advertised they are hosting on Server 2008, which meant
IIS7.&amp;#160; This makes things much easier when publishing an MVC site (to do with
routing apparently).&amp;#160; As I’d hosted my sites for years with these providers,
they were still on Win2003 (IIS6) boxes.&amp;#160; I just had to ask for an upgrade and
it was done.
&lt;/p&gt;
&lt;p&gt;
Upload to IIS7 and it just works!
&lt;/p&gt;
&lt;p&gt;
The first step was to see if routing worked on the default website.. it did!
&lt;/p&gt;
&lt;p&gt;
The next step – to publish up the NerdDinner app I’ve been going through on Rob Conery,
and get the database connected live.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_thumb.png" width="644" height="355" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
The crowd goes wild&amp;#160; - this is live and connecting to a database :-)
&lt;/p&gt;
&lt;h3&gt;Changing Namespace / Solution Name / Project Names
&lt;/h3&gt;
&lt;p&gt;
I had lots of namespace errors.. forgot to change default assembly namespace, which
meant linq to sql was in the wrong space.&amp;#160; However it is possible to change everything
very quickly – solution, project names, directly.&amp;#160; One gotcha was remembering
to delete everything on the live server so there weren’t 2 dll’s with the same object
names inside..
&lt;/p&gt;
&lt;h3&gt;Changing Default Page to Activity / upload live trick
&lt;/h3&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;routes.MapRoute(&lt;br /&gt;
&lt;span style="color: #006080"&gt;&amp;quot;Default&amp;quot;&lt;/span&gt;, &lt;span style="color: #008000"&gt;//
Route name&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #006080"&gt;&amp;quot;{controller}/{action}/{id}&amp;quot;&lt;/span&gt;, &lt;span style="color: #008000"&gt;//
URL with parameters&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; { controller = &lt;span style="color: #006080"&gt;&amp;quot;Activity&amp;quot;&lt;/span&gt;,
action = &lt;span style="color: #006080"&gt;&amp;quot;Index&amp;quot;&lt;/span&gt;, id = &lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt; } &lt;span style="color: #008000"&gt;//
Parameter defaults&lt;/span&gt;
&lt;br /&gt;
);&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
Change controller = “Home” to controller = “Acitivity”
&lt;/p&gt;
&lt;p&gt;
I also implemented the copyifnewer.bat trick for easily going from dev to live which
is here: &lt;a title="http://www.programgood.net/2010/01/28/WebConfigAutomatingDevAndLive.aspx" href="http://www.programgood.net/2010/01/28/WebConfigAutomatingDevAndLive.aspx"&gt;http://www.programgood.net/2010/01/28/WebConfigAutomatingDevAndLive.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Run application working live with Create, Read, Update and Delete working.&amp;#160; Also
validation, which comes for free in the standard templates.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_thumb_1.png" width="644" height="399" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
DropDownList and Postbacks – covered in another post on this site.
&lt;/p&gt;
&lt;p&gt;
&lt;a title="http://www.mikesdotnetting.com/Article/128/Get-The-Drop-On-ASP.NET-MVC-DropDownLists" href="http://www.mikesdotnetting.com/Article/128/Get-The-Drop-On-ASP.NET-MVC-DropDownLists"&gt;http://www.mikesdotnetting.com/Article/128/Get-The-Drop-On-ASP.NET-MVC-DropDownLists&lt;/a&gt;
&lt;/p&gt;
&lt;h4&gt;Summary Page
&lt;/h4&gt;
&lt;p&gt;
I created another link in the master page for menu item:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.mateerit.co.nz/run"&gt;www.mateerit.co.nz/run&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_8.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_thumb_3.png" width="332" height="105" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
For the summary page I’m considering a ViewModel approach.
&lt;/p&gt;
&lt;p&gt;
Lets see if a simple new Summary controller will suffice
&lt;/p&gt;
&lt;p&gt;
Got to a stage.. was going to upload to github, but had db connection strings in there
which didn’t want in the history.. so looked at rebase in git.. want to make sure
before I play too much :-)
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;h5&gt;Creating a SQL View then Displaying it
&lt;/h5&gt;
&lt;p&gt;
Michael came up with an elegant solution which I’m trying.. so creating a SQL View:
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;SELECT&lt;/span&gt; personid, 
&lt;br /&gt;
DATEPART(week, &lt;span style="color: #0000ff"&gt;date&lt;/span&gt;) &lt;span style="color: #0000ff"&gt;AS&lt;/span&gt; Week, 
&lt;br /&gt;
DATEPART(&lt;span style="color: #0000ff"&gt;year&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;date&lt;/span&gt;) &lt;span style="color: #0000ff"&gt;AS&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Year&lt;/span&gt;,&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;SUM&lt;/span&gt;(kilometres) &lt;span style="color: #0000ff"&gt;AS&lt;/span&gt; kilometres, 
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;SUM&lt;/span&gt;(hours) &lt;span style="color: #0000ff"&gt;AS&lt;/span&gt; hours&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;FROM&lt;/span&gt; dbo.Activity&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;GROUP&lt;/span&gt; &lt;span style="color: #0000ff"&gt;BY&lt;/span&gt; personid,
DATEPART(week, &lt;span style="color: #0000ff"&gt;date&lt;/span&gt;), DATEPART(&lt;span style="color: #0000ff"&gt;year&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;date&lt;/span&gt;)&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
which gives a good summary output:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_thumb_2.png" width="244" height="123" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
The aim is to be able to see the summary of each week like this (this is the old webforms
version)
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_10.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_thumb_4.png" width="644" height="237" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
linq to sql generated classes off the view.
&lt;/p&gt;
&lt;p&gt;
Michael did it like this:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_12.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_thumb_5.png" width="588" height="168" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
I’m on this:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_14.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_thumb_6.png" width="321" height="210" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;h5&gt;Passing Complex Data – Lists within Lists
&lt;/h5&gt;
&lt;p&gt;
As each person has data associated to them, a list within a list is good.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_16.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/GoingLivewithASP.NETMVC_9316/image_thumb_7.png" width="610" height="252" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; WeekSummary&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; Personid;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; string Personname;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; List&amp;lt;WeekSummaryData&amp;gt; Persondata;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; WeekSummaryData&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;double&lt;/span&gt;?
Hours;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;double&lt;/span&gt;?
Kilometers;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;?
Week;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt;? &lt;span style="color: #0000ff"&gt;Year&lt;/span&gt;;&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
Then in the repository:
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; IQueryable&amp;lt;WeekSummary&amp;gt;
GetWeeklySummary()&lt;br /&gt;
{&lt;br /&gt;
var weekSummaries = &lt;span style="color: #0000ff"&gt;from&lt;/span&gt; p &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; db.Persons&lt;br /&gt;
orderby p.personname&lt;br /&gt;
let &lt;span style="color: #0000ff"&gt;data&lt;/span&gt; = GetWeeklySummaryData(p.personid)&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;select&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; WeekSummary
{Personid = p.personid, 
&lt;br /&gt;
Personname = p.personname, 
&lt;br /&gt;
Persondata = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;WeekSummaryData&amp;gt;(&lt;span style="color: #0000ff"&gt;data&lt;/span&gt;)};&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; weekSummaries;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
IQueryable&amp;lt;WeekSummaryData&amp;gt; GetWeeklySummaryData(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; personid)&lt;br /&gt;
{&lt;br /&gt;
var summary = &lt;span style="color: #0000ff"&gt;from&lt;/span&gt; w &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; db.weekly_summaries&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;where&lt;/span&gt; w.personid == personid&lt;br /&gt;
orderby w.&lt;span style="color: #0000ff"&gt;Year&lt;/span&gt; , w.Week&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;select&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; WeekSummaryData
{Hours = w.hours, 
&lt;br /&gt;
Kilometers = w.kilometres, 
&lt;br /&gt;
Week = w.Week, 
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;Year&lt;/span&gt; = w.&lt;span style="color: #0000ff"&gt;Year&lt;/span&gt;};&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; summary;&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
** understand this linq
&lt;/p&gt;
&lt;p&gt;
Then in the controller:
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ActionResult &lt;span style="color: #0000ff"&gt;Index&lt;/span&gt;()&lt;br /&gt;
{&lt;br /&gt;
var summaries = _repository.GetWeeklySummary();&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;View&lt;/span&gt;(summaries);&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
and the view:
&lt;/p&gt;
&lt;p&gt;
** understand this rendering
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&amp;lt;% &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (WeekSummary
weekSummary &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; Model) {&lt;br /&gt;
%&amp;gt;&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;% &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (WeekSummaryData weekSummaryData &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; weekSummary.Persondata)
{ %&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;&amp;lt;%=Html.Encode(weekSummaryData.Week) + &lt;span style="color: #006080"&gt;&amp;quot;/&amp;quot;&lt;/span&gt; +
Html.Encode(weekSummaryData.Year) %&amp;gt;&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;%}%&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;%=Html.Encode(weekSummary.Personname) %&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;% &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (WeekSummaryData week &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; weekSummary.Persondata)
{ %&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;lt;%=Html.Encode(week.Hours) + &lt;span style="color: #006080"&gt;&amp;quot;hrs&amp;quot;&lt;/span&gt; %&amp;gt;&amp;lt;br
/&amp;gt;&amp;lt;%=Html.Encode(week.Kilometers) + &lt;span style="color: #006080"&gt;&amp;quot;kms&amp;quot;&lt;/span&gt; %&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;%}%&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;% } %&amp;gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
refactor code with an interface for testing
&lt;/p&gt;
&lt;p&gt;
unit test do
&lt;/p&gt;
&lt;p&gt;
automock
&lt;/p&gt;
&lt;p&gt;
jquery
&lt;/p&gt;
&lt;p&gt;
tooling to help make form crud websites faster… 
&lt;/p&gt;
&lt;p&gt;
reproting tooling
&lt;/p&gt;
&lt;p&gt;
mvc2
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=6da2752b-b696-49cf-9541-127e55d50123" /&gt;</description>
      <comments>http://www.programgood.net/CommentView,guid,6da2752b-b696-49cf-9541-127e55d50123.aspx</comments>
      <category>ASP.NET MVC</category>
      <category>Project Run</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=d8273ebf-05f7-4019-9653-972975947ca4</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,d8273ebf-05f7-4019-9653-972975947ca4.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <wfw:comment>http://www.programgood.net/CommentView,guid,d8273ebf-05f7-4019-9653-972975947ca4.aspx</wfw:comment>
      <wfw:commentRss>http://www.programgood.net/SyndicationService.asmx/GetEntryCommentsRss?guid=d8273ebf-05f7-4019-9653-972975947ca4</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
While pair programming with some great developers I asked the question:  How
would you refactor this project (the running project website).
</p>
        <p>
When both of the guys I paired with suggested that it would be smart to move to MVC
and to use an ORM, I listened.
</p>
        <p>
After downloading ASP.NET MVC version 1.  I’ve been working through the tutorial
from Rob Conery:
</p>
        <p>
          <a title="http://www.asp.net/learn/mvc-videos/video-8143.aspx" href="http://www.asp.net/learn/mvc-videos/video-8143.aspx">http://www.asp.net/learn/mvc-videos/video-8143.aspx</a> (about
80mins)
</p>
        <h3>Creating a New MVC Project
</h3>
        <p>
Ctrl Shift N
</p>
        <h3>Linq to SQL
</h3>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/image_2.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/image_thumb.png" width="109" height="244" />
          </a>
        </p>
        <p>
going to use Membership for login / users.
</p>
        <p>
In models, add new item: LINQ to SQL
</p>
        <p>
drag on the two tables
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/image_4.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/image_thumb_1.png" width="244" height="142" />
          </a>
        </p>
        <p>
Original table name was dinners.  The class is called dinner
</p>
        <p>
Renamed NerddinnerDataContect to DB, and context namespace to Nerddinner
</p>
        <p>
however Entity Namespace to Nerddinner.Model – which didn’t work!  I left it
blank.
</p>
        <h3>Adding a Controller
</h3>
        <p>
The default Index controller
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">var db = <span style="color: #0000ff">new</span> DB();<br />
var dinners = db.Dinners;<br /><span style="color: #0000ff">return</span> View(dinners);</pre>
        </div>
        <p>
        </p>
        <p>
        </p>
        <h3>Adding a View
</h3>
        <p>
right click inside method in controller
</p>
        <p>
Create strongly-typed view
</p>
        <p>
View content – code gen nice.
</p>
        <p>
Tooling figured out which is the primary key (as linq to sql)
</p>
        <p>
 
</p>
        <h3>ModelBinders - Add
</h3>
        <p>
When creating a new Dinner, we use ModelBinders.. mvc looks at the Object and sees
if it can bind to the linqtosql.
</p>
        <p>
Could have used the existing FormCollection, but this is easier!
</p>
        <p>
If ModelState.IsValid   .. nice.
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/image_6.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/image_thumb_2.png" width="325" height="484" />
          </a>
        </p>
        <p>
And by changing the Html.ValidationMessage
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/image_8.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/image_thumb_3.png" width="333" height="484" />
          </a>
        </p>
        <h3>Editing Data
</h3>
        <p>
        </p>
        <p>
In the controller:
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">public</span> ActionResult
Edit(<span style="color: #0000ff">int</span> id)<br />
{<br />
var db = <span style="color: #0000ff">new</span> DB();<br />
var dinner = db.Dinners.SingleOrDefault(x =&gt; x.DinnerID == id); 
<br /><span style="color: #0000ff">return</span> View(dinner);<br />
}</pre>
          <br />
        </div>
        <p>
This is another way of expressing the above:
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">public</span> ActionResult
Edit(<span style="color: #0000ff">int</span> id)<br />
{<br />
var db = <span style="color: #0000ff">new</span> DB();<br /><span style="color: #008000">//var dinner = db.Dinners.SingleOrDefault(x =&gt; x.DinnerID
== id);</span><br />
var dinner = (from a <span style="color: #0000ff">in</span> db.Dinners<br /><span style="color: #0000ff">where</span> a.DinnerID == id<br />
select a).SingleOrDefault();<br /><br /><span style="color: #0000ff">return</span> View(dinner);<br />
}<br /></pre>
          <br />
        </div>
        <p>
&lt;% gator tags
</p>
        <p>
Other view engines – Spark or nHaml
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/image_10.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/image_thumb_4.png" width="218" height="484" />
          </a>
        </p>
        <p>
So we’ve built scaffolding.
</p>
        <h3>Routing
</h3>
        <p>
        </p>
        <p>
We want /dinners to the be root of the site.
</p>
        <p>
Routing is the thing that listens for URL’s and passes them to a controller. 
</p>
        <p>
eg Dinner / Edit /5 
</p>
        <p>
eg { controller} / {action} / {id}
</p>
        <p>
To change to be /dinners as the route in global.asax
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">static</span>
            <span style="color: #0000ff">public</span>
            <span style="color: #0000ff">void</span> RegisterRoutes(RouteCollection
routes)<br />
{<br />
routes.IgnoreRoute(<span style="color: #006080">"{resource}.axd/{*pathInfo}"</span>);<br /><br />
routes.MapRoute(<br /><span style="color: #006080">"Default"</span>, <span style="color: #008000">//
Route name</span><br /><span style="color: #006080">"{controller}/{action}/{id}"</span>, <span style="color: #008000">//
URL with parameters</span><br /><span style="color: #0000ff">new</span> {controller = <span style="color: #006080">"Dinner"</span>,
action = <span style="color: #006080">"Index"</span>, id = <span style="color: #006080">""</span>} <span style="color: #008000">//
Parameter defaults</span><br />
);<br />
}</pre>
          <br />
        </div>
        <p>
We changed from Home to Dinner above.
</p>
        <h3>Deleting
</h3>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/image_12.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/image_thumb_5.png" width="201" height="484" />
          </a>
        </p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">[AcceptVerbs(HttpVerbs.Post)]<br /><span style="color: #0000ff">public</span> ActionResult Delete(<span style="color: #0000ff">int</span> id)<br />
{<br />
var db = <span style="color: #0000ff">new</span> DB();<br />
var dinner = (from a <span style="color: #0000ff">in</span> db.Dinners<br /><span style="color: #0000ff">where</span> a.DinnerID == id<br />
select a).SingleOrDefault();<br />
db.Dinners.DeleteOnSubmit(dinner);<br />
db.SubmitChanges();<br /><br /><span style="color: #0000ff">return</span> RedirectToAction(<span style="color: #006080">"Index"</span>);<br />
}</pre>
          <br />
        </div>
        <p>
        </p>
        <p>
are wired up on the view:
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">&lt;% <span style="color: #0000ff">using</span> (Html.BeginForm(<span style="color: #006080">"delete"</span>, <span style="color: #006080">"dinner"</span>))
{%&gt;<br />
&lt;%=Html.Hidden(<span style="color: #006080">"id"</span>,Model.DinnerID)
%&gt;<br />
&lt;input id=<span style="color: #006080">"Submit1"</span> type=<span style="color: #006080">"submit"</span><span style="color: #0000ff">value</span>=<span style="color: #006080">"delete"</span> /&gt;<br />
&lt;% } %&gt;</pre>
          <br />
        </div>
        <p>
We are not using any authentication to stop people doing this at the moment. For that
we need:
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">[AcceptVerbs(HttpVerbs.Post)]<br />
[Authorize(Roles=<span style="color: #006080">"Administrator"</span>)]<br /><span style="color: #0000ff">public</span> ActionResult Delete(<span style="color: #0000ff">int</span> id)<br />
{<br />
var db = <span style="color: #0000ff">new</span> DB();</pre>
          <br />
        </div>
        <h3>Testing / Repository Pattern
</h3>
        <p>
Because the controller has database connection inside of it, this isn’t good from
a testing point of view, so we’re going to refactor this out.
</p>
        <p>
Speed would be a problem with lots of tests, as would not knowing what is in the database.
</p>
        <p>
Created an IDinnerRepository interface:
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">public</span>
            <span style="color: #0000ff">interface</span> IDinnerRepository<br />
{<br />
IQueryable&lt;Dinner&gt; FindAllDinners();<br />
Dinner GetDinner(<span style="color: #0000ff">int</span> id);<br /><span style="color: #0000ff">void</span> Add(Dinner dinner);<br /><span style="color: #0000ff">void</span> Update(Dinner dinner);<br /><span style="color: #0000ff">void</span> Delete(Dinner dinner);<br /><span style="color: #0000ff">void</span> Save();<br />
}</pre>
          <br />
        </div>
        <p>
        </p>
        <p>
Then a SqlDinnerRepository that implements this, where the constructors calls the
DB:
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">public</span>
            <span style="color: #0000ff">class</span> SqlDinnerRepository
: IDinnerRepository<br />
{<br />
DB db;<br /><br /><span style="color: #0000ff">public</span> SqlDinnerRepository()<br />
{<br />
db = <span style="color: #0000ff">new</span> DB();<br />
}<br /><br /><span style="color: #0000ff">public</span> IQueryable&lt;Dinner&gt; FindAllDinners()<br />
{<br /><span style="color: #0000ff">return</span> db.Dinners;<br />
}<br /><br /><span style="color: #0000ff">public</span> Dinner GetDinner(<span style="color: #0000ff">int</span> id)<br />
{<br />
var dinner = (from a <span style="color: #0000ff">in</span> db.Dinners<br /><span style="color: #0000ff">where</span> a.DinnerID == id<br />
select a).SingleOrDefault();<br /><br /><span style="color: #0000ff">return</span> dinner;<br />
}</pre>
          <br />
        </div>
        <p>
Then in the Dinner Controller:
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">public</span>
            <span style="color: #0000ff">class</span> DinnerController
: Controller<br />
{<br />
IDinnerRepository _repository;<br /><br /><span style="color: #0000ff">public</span> DinnerController()<br />
{<br />
_repository = <span style="color: #0000ff">new</span> SqlDinnerRepository();<br />
}<br /><br /><span style="color: #008000">// this will be the one that the test uses</span><br /><span style="color: #0000ff">public</span> DinnerController(IDinnerRepository repository)<br />
{<br />
_repository = repository;<br />
}<br /><br /><span style="color: #008000">//</span><br /><span style="color: #008000">// GET: /Dinner/</span><br /><span style="color: #0000ff">public</span> ActionResult Index()<br />
{<br /><span style="color: #008000">//var db = new DB();</span><br /><span style="color: #008000">//var dinners = db.Dinners;</span><br />
var dinners = _repository.FindAllDinners();<br /><span style="color: #0000ff">return</span> View(dinners);<br />
}</pre>
          <br />
        </div>
        <p>
        </p>
        <p>
The plan is that we will make up something that implements IDinnerRepository when
testing to make our life easier.
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/DSCN1379_dave_2.jpg">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="DSCN1379_dave" border="0" alt="DSCN1379_dave" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/DSCN1379_dave_thumb.jpg" width="644" height="484" />
          </a>
        </p>
        <p>
Made: FadinnerkeDinnerRepository
</p>
        <p>
Made: DinnerControllerTests
</p>
        <p>
Ctrl R T – Run tests
</p>
        <p>
Found error in test code:
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #008000">//var
data = result.ViewData.Model as IList&lt;Dinner&gt;; // this didn't work.. hmmmmmmm.</span>
            <br />
var data = result.ViewData.Model <span style="color: #0000ff">as</span> IEnumerable&lt;Dinner&gt;;</pre>
          <br />
        </div>
        <h3>TDD
</h3>
        <p>
Made a test that dinners should only return dates that are today or later:
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">[TestMethod]<br /><span style="color: #0000ff">public</span><span style="color: #0000ff">void</span> Index_Should_Return_Dinners_For_Today_Or_Later()
{<br /><span style="color: #008000">// Arrange</span><br />
var controller = <span style="color: #0000ff">new</span> DinnerController(<span style="color: #0000ff">new</span> Fakes.FakeDinnerRepository());<br /><br /><span style="color: #008000">// Act</span><br /><span style="color: #008000">//ViewResult result = (ViewResult) controller.Index();</span><br />
var result = controller.Index() <span style="color: #0000ff">as</span> ViewResult;<br /><br /><span style="color: #008000">// Assert</span><br />
var data = result.ViewData.Model <span style="color: #0000ff">as</span> IEnumerable&lt;Dinner&gt;;<br />
Assert.IsFalse(data.Where(x=&gt;x.EventDate&lt;DateTime.Now).Count()&gt;0);<br />
}</pre>
          <br />
        </div>
        <p>
Failed the test, then wrote the code which was in the DinnerController:
</p>
        <div id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">var dinners = _repository.FindAllDinners().Where(x=&gt;x.EventDate &gt;= DateTime.Now);</pre>
          <br />
        </div>
        <p>
 
</p>
        <h3>Lambda expressions
</h3>
        <p>
var dinners = _repository.FindAllDinners().Where(x=&gt;x.EventDate &gt;= DateTime.Now);
</p>
        <p>
 
</p>
        <h3>Presentation Model Pattern or View Model
</h3>
        <p>
45min into Rob’s video.
</p>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=d8273ebf-05f7-4019-9653-972975947ca4" />
      </body>
      <title>ASP.NET MVC</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,d8273ebf-05f7-4019-9653-972975947ca4.aspx</guid>
      <link>http://www.programgood.net/2010/02/11/ASPNETMVC.aspx</link>
      <pubDate>Thu, 11 Feb 2010 23:43:33 GMT</pubDate>
      <description>&lt;p&gt;
While pair programming with some great developers I asked the question:&amp;#160; How
would you refactor this project (the running project website).
&lt;/p&gt;
&lt;p&gt;
When both of the guys I paired with suggested that it would be smart to move to MVC
and to use an ORM, I listened.
&lt;/p&gt;
&lt;p&gt;
After downloading ASP.NET MVC version 1.&amp;#160; I’ve been working through the tutorial
from Rob Conery:
&lt;/p&gt;
&lt;p&gt;
&lt;a title="http://www.asp.net/learn/mvc-videos/video-8143.aspx" href="http://www.asp.net/learn/mvc-videos/video-8143.aspx"&gt;http://www.asp.net/learn/mvc-videos/video-8143.aspx&lt;/a&gt; (about
80mins)
&lt;/p&gt;
&lt;h3&gt;Creating a New MVC Project
&lt;/h3&gt;
&lt;p&gt;
Ctrl Shift N
&lt;/p&gt;
&lt;h3&gt;Linq to SQL
&lt;/h3&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/image_thumb.png" width="109" height="244" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
going to use Membership for login / users.
&lt;/p&gt;
&lt;p&gt;
In models, add new item: LINQ to SQL
&lt;/p&gt;
&lt;p&gt;
drag on the two tables
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/image_thumb_1.png" width="244" height="142" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Original table name was dinners.&amp;#160; The class is called dinner
&lt;/p&gt;
&lt;p&gt;
Renamed NerddinnerDataContect to DB, and context namespace to Nerddinner
&lt;/p&gt;
&lt;p&gt;
however Entity Namespace to Nerddinner.Model – which didn’t work!&amp;#160; I left it
blank.
&lt;/p&gt;
&lt;h3&gt;Adding a Controller
&lt;/h3&gt;
&lt;p&gt;
The default Index controller
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;var db = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DB();&lt;br /&gt;
var dinners = db.Dinners;&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; View(dinners);&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;h3&gt;Adding a View
&lt;/h3&gt;
&lt;p&gt;
right click inside method in controller
&lt;/p&gt;
&lt;p&gt;
Create strongly-typed view
&lt;/p&gt;
&lt;p&gt;
View content – code gen nice.
&lt;/p&gt;
&lt;p&gt;
Tooling figured out which is the primary key (as linq to sql)
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;h3&gt;ModelBinders - Add
&lt;/h3&gt;
&lt;p&gt;
When creating a new Dinner, we use ModelBinders.. mvc looks at the Object and sees
if it can bind to the linqtosql.
&lt;/p&gt;
&lt;p&gt;
Could have used the existing FormCollection, but this is easier!
&lt;/p&gt;
&lt;p&gt;
If ModelState.IsValid&amp;#160;&amp;#160; .. nice.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/image_thumb_2.png" width="325" height="484" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
And by changing the Html.ValidationMessage
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/image_8.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/image_thumb_3.png" width="333" height="484" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;h3&gt;Editing Data
&lt;/h3&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
In the controller:
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ActionResult
Edit(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; id)&lt;br /&gt;
{&lt;br /&gt;
var db = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DB();&lt;br /&gt;
var dinner = db.Dinners.SingleOrDefault(x =&amp;gt; x.DinnerID == id); 
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; View(dinner);&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
This is another way of expressing the above:
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ActionResult
Edit(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; id)&lt;br /&gt;
{&lt;br /&gt;
var db = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DB();&lt;br /&gt;
&lt;span style="color: #008000"&gt;//var dinner = db.Dinners.SingleOrDefault(x =&amp;gt; x.DinnerID
== id);&lt;/span&gt;
&lt;br /&gt;
var dinner = (from a &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; db.Dinners&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;where&lt;/span&gt; a.DinnerID == id&lt;br /&gt;
select a).SingleOrDefault();&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; View(dinner);&lt;br /&gt;
}&lt;br /&gt;
&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;lt;% gator tags
&lt;/p&gt;
&lt;p&gt;
Other view engines – Spark or nHaml
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/image_10.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/image_thumb_4.png" width="218" height="484" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
So we’ve built scaffolding.
&lt;/p&gt;
&lt;h3&gt;Routing
&lt;/h3&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
We want /dinners to the be root of the site.
&lt;/p&gt;
&lt;p&gt;
Routing is the thing that listens for URL’s and passes them to a controller. 
&lt;/p&gt;
&lt;p&gt;
eg Dinner / Edit /5 
&lt;/p&gt;
&lt;p&gt;
eg { controller} / {action} / {id}
&lt;/p&gt;
&lt;p&gt;
To change to be /dinners as the route in global.asax
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; RegisterRoutes(RouteCollection
routes)&lt;br /&gt;
{&lt;br /&gt;
routes.IgnoreRoute(&lt;span style="color: #006080"&gt;&amp;quot;{resource}.axd/{*pathInfo}&amp;quot;&lt;/span&gt;);&lt;br /&gt;
&lt;br /&gt;
routes.MapRoute(&lt;br /&gt;
&lt;span style="color: #006080"&gt;&amp;quot;Default&amp;quot;&lt;/span&gt;, &lt;span style="color: #008000"&gt;//
Route name&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #006080"&gt;&amp;quot;{controller}/{action}/{id}&amp;quot;&lt;/span&gt;, &lt;span style="color: #008000"&gt;//
URL with parameters&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; {controller = &lt;span style="color: #006080"&gt;&amp;quot;Dinner&amp;quot;&lt;/span&gt;,
action = &lt;span style="color: #006080"&gt;&amp;quot;Index&amp;quot;&lt;/span&gt;, id = &lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;} &lt;span style="color: #008000"&gt;//
Parameter defaults&lt;/span&gt;
&lt;br /&gt;
);&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
We changed from Home to Dinner above.
&lt;/p&gt;
&lt;h3&gt;Deleting
&lt;/h3&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/image_12.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/image_thumb_5.png" width="201" height="484" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;[AcceptVerbs(HttpVerbs.Post)]&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ActionResult Delete(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; id)&lt;br /&gt;
{&lt;br /&gt;
var db = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DB();&lt;br /&gt;
var dinner = (from a &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; db.Dinners&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;where&lt;/span&gt; a.DinnerID == id&lt;br /&gt;
select a).SingleOrDefault();&lt;br /&gt;
db.Dinners.DeleteOnSubmit(dinner);&lt;br /&gt;
db.SubmitChanges();&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; RedirectToAction(&lt;span style="color: #006080"&gt;&amp;quot;Index&amp;quot;&lt;/span&gt;);&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
are wired up on the view:
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&amp;lt;% &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (Html.BeginForm(&lt;span style="color: #006080"&gt;&amp;quot;delete&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;dinner&amp;quot;&lt;/span&gt;))
{%&amp;gt;&lt;br /&gt;
&amp;lt;%=Html.Hidden(&lt;span style="color: #006080"&gt;&amp;quot;id&amp;quot;&lt;/span&gt;,Model.DinnerID)
%&amp;gt;&lt;br /&gt;
&amp;lt;input id=&lt;span style="color: #006080"&gt;&amp;quot;Submit1&amp;quot;&lt;/span&gt; type=&lt;span style="color: #006080"&gt;&amp;quot;submit&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;=&lt;span style="color: #006080"&gt;&amp;quot;delete&amp;quot;&lt;/span&gt; /&amp;gt;&lt;br /&gt;
&amp;lt;% } %&amp;gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
We are not using any authentication to stop people doing this at the moment. For that
we need:
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;[AcceptVerbs(HttpVerbs.Post)]&lt;br /&gt;
[Authorize(Roles=&lt;span style="color: #006080"&gt;&amp;quot;Administrator&amp;quot;&lt;/span&gt;)]&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ActionResult Delete(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; id)&lt;br /&gt;
{&lt;br /&gt;
var db = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DB();&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;h3&gt;Testing / Repository Pattern
&lt;/h3&gt;
&lt;p&gt;
Because the controller has database connection inside of it, this isn’t good from
a testing point of view, so we’re going to refactor this out.
&lt;/p&gt;
&lt;p&gt;
Speed would be a problem with lots of tests, as would not knowing what is in the database.
&lt;/p&gt;
&lt;p&gt;
Created an IDinnerRepository interface:
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; IDinnerRepository&lt;br /&gt;
{&lt;br /&gt;
IQueryable&amp;lt;Dinner&amp;gt; FindAllDinners();&lt;br /&gt;
Dinner GetDinner(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; id);&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Add(Dinner dinner);&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Update(Dinner dinner);&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Delete(Dinner dinner);&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Save();&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
Then a SqlDinnerRepository that implements this, where the constructors calls the
DB:
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; SqlDinnerRepository
: IDinnerRepository&lt;br /&gt;
{&lt;br /&gt;
DB db;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; SqlDinnerRepository()&lt;br /&gt;
{&lt;br /&gt;
db = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DB();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; IQueryable&amp;lt;Dinner&amp;gt; FindAllDinners()&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; db.Dinners;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; Dinner GetDinner(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; id)&lt;br /&gt;
{&lt;br /&gt;
var dinner = (from a &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; db.Dinners&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;where&lt;/span&gt; a.DinnerID == id&lt;br /&gt;
select a).SingleOrDefault();&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; dinner;&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
Then in the Dinner Controller:
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; DinnerController
: Controller&lt;br /&gt;
{&lt;br /&gt;
IDinnerRepository _repository;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; DinnerController()&lt;br /&gt;
{&lt;br /&gt;
_repository = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SqlDinnerRepository();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// this will be the one that the test uses&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; DinnerController(IDinnerRepository repository)&lt;br /&gt;
{&lt;br /&gt;
_repository = repository;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;//&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// GET: /Dinner/&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ActionResult Index()&lt;br /&gt;
{&lt;br /&gt;
&lt;span style="color: #008000"&gt;//var db = new DB();&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;//var dinners = db.Dinners;&lt;/span&gt;
&lt;br /&gt;
var dinners = _repository.FindAllDinners();&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; View(dinners);&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
The plan is that we will make up something that implements IDinnerRepository when
testing to make our life easier.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/DSCN1379_dave_2.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="DSCN1379_dave" border="0" alt="DSCN1379_dave" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETMVC_A3E3/DSCN1379_dave_thumb.jpg" width="644" height="484" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Made: FadinnerkeDinnerRepository
&lt;/p&gt;
&lt;p&gt;
Made: DinnerControllerTests
&lt;/p&gt;
&lt;p&gt;
Ctrl R T – Run tests
&lt;/p&gt;
&lt;p&gt;
Found error in test code:
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt; &lt;span style="color: #008000"&gt;//var
data = result.ViewData.Model as IList&amp;lt;Dinner&amp;gt;; // this didn't work.. hmmmmmmm.&lt;/span&gt;
&lt;br /&gt;
var data = result.ViewData.Model &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; IEnumerable&amp;lt;Dinner&amp;gt;;&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;h3&gt;TDD
&lt;/h3&gt;
&lt;p&gt;
Made a test that dinners should only return dates that are today or later:
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;[TestMethod]&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Index_Should_Return_Dinners_For_Today_Or_Later()
{&lt;br /&gt;
&lt;span style="color: #008000"&gt;// Arrange&lt;/span&gt;
&lt;br /&gt;
var controller = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DinnerController(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Fakes.FakeDinnerRepository());&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// Act&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;//ViewResult result = (ViewResult) controller.Index();&lt;/span&gt;
&lt;br /&gt;
var result = controller.Index() &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; ViewResult;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// Assert&lt;/span&gt;
&lt;br /&gt;
var data = result.ViewData.Model &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; IEnumerable&amp;lt;Dinner&amp;gt;;&lt;br /&gt;
Assert.IsFalse(data.Where(x=&amp;gt;x.EventDate&amp;lt;DateTime.Now).Count()&amp;gt;0);&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
Failed the test, then wrote the code which was in the DinnerController:
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;var dinners = _repository.FindAllDinners().Where(x=&amp;gt;x.EventDate &amp;gt;= DateTime.Now);&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;h3&gt;Lambda expressions
&lt;/h3&gt;
&lt;p&gt;
var dinners = _repository.FindAllDinners().Where(x=&amp;gt;x.EventDate &amp;gt;= DateTime.Now);
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;h3&gt;Presentation Model Pattern or View Model
&lt;/h3&gt;
&lt;p&gt;
45min into Rob’s video.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=d8273ebf-05f7-4019-9653-972975947ca4" /&gt;</description>
      <comments>http://www.programgood.net/CommentView,guid,d8273ebf-05f7-4019-9653-972975947ca4.aspx</comments>
      <category>Project Run</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=7027d99f-7fcb-4f79-adf0-6e8cebe23b6f</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,7027d99f-7fcb-4f79-adf0-6e8cebe23b6f.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <wfw:comment>http://www.programgood.net/CommentView,guid,7027d99f-7fcb-4f79-adf0-6e8cebe23b6f.aspx</wfw:comment>
      <wfw:commentRss>http://www.programgood.net/SyndicationService.asmx/GetEntryCommentsRss?guid=7027d99f-7fcb-4f79-adf0-6e8cebe23b6f</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
No error.  Just closes when using ASP.NET MVC
</p>
        <p>
          <a title="http://stackoverflow.com/questions/1361291/resharper-r-4-5-and-mvc-1-0-solutions-cause-visual-studio-2008-sp1-to-crash" href="http://stackoverflow.com/questions/1361291/resharper-r-4-5-and-mvc-1-0-solutions-cause-visual-studio-2008-sp1-to-crash">http://stackoverflow.com/questions/1361291/resharper-r-4-5-and-mvc-1-0-solutions-cause-visual-studio-2008-sp1-to-crash</a>
        </p>
        <p>
then onto:
</p>
        <p>
          <a title="http://stackoverflow.com/questions/500696/why-does-visual-studio-crash-opening-aspx-with-mvc-rc1" href="http://stackoverflow.com/questions/500696/why-does-visual-studio-crash-opening-aspx-with-mvc-rc1">http://stackoverflow.com/questions/500696/why-does-visual-studio-crash-opening-aspx-with-mvc-rc1</a>
        </p>
        <p>
Have tried the one above, which seems to work so far.
</p>
        <p>
[Edit] it didn’t.. so now I’m trying this:
</p>
        <p>
          <a href="https://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=16827&amp;wa=wsignin1.0">https://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=16827&amp;wa=wsignin1.0</a>
        </p>
        <p>
Something still weird as locking up when loading assemblies (looks like resharper) 
am trying resharper5 beta2 to see if that helps (haven’t got correct license). 
I can get around lockup by deleting dlls from bin and obj.
</p>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=7027d99f-7fcb-4f79-adf0-6e8cebe23b6f" />
      </body>
      <title>Visual Studio 2008 SP1 with Resharper 4.5 Crashing</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,7027d99f-7fcb-4f79-adf0-6e8cebe23b6f.aspx</guid>
      <link>http://www.programgood.net/2010/02/11/VisualStudio2008SP1WithResharper45Crashing.aspx</link>
      <pubDate>Thu, 11 Feb 2010 23:22:14 GMT</pubDate>
      <description>&lt;p&gt;
No error.&amp;#160; Just closes when using ASP.NET MVC
&lt;/p&gt;
&lt;p&gt;
&lt;a title="http://stackoverflow.com/questions/1361291/resharper-r-4-5-and-mvc-1-0-solutions-cause-visual-studio-2008-sp1-to-crash" href="http://stackoverflow.com/questions/1361291/resharper-r-4-5-and-mvc-1-0-solutions-cause-visual-studio-2008-sp1-to-crash"&gt;http://stackoverflow.com/questions/1361291/resharper-r-4-5-and-mvc-1-0-solutions-cause-visual-studio-2008-sp1-to-crash&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
then onto:
&lt;/p&gt;
&lt;p&gt;
&lt;a title="http://stackoverflow.com/questions/500696/why-does-visual-studio-crash-opening-aspx-with-mvc-rc1" href="http://stackoverflow.com/questions/500696/why-does-visual-studio-crash-opening-aspx-with-mvc-rc1"&gt;http://stackoverflow.com/questions/500696/why-does-visual-studio-crash-opening-aspx-with-mvc-rc1&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Have tried the one above, which seems to work so far.
&lt;/p&gt;
&lt;p&gt;
[Edit] it didn’t.. so now I’m trying this:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="https://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=16827&amp;amp;wa=wsignin1.0"&gt;https://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=16827&amp;amp;wa=wsignin1.0&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Something still weird as locking up when loading assemblies (looks like resharper)&amp;#160;
am trying resharper5 beta2 to see if that helps (haven’t got correct license).&amp;#160;
I can get around lockup by deleting dlls from bin and obj.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=7027d99f-7fcb-4f79-adf0-6e8cebe23b6f" /&gt;</description>
      <comments>http://www.programgood.net/CommentView,guid,7027d99f-7fcb-4f79-adf0-6e8cebe23b6f.aspx</comments>
      <category>ASP.NET MVC</category>
      <category>Project Run</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=d746049f-288a-4286-a32c-9dd366ed4e85</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,d746049f-288a-4286-a32c-9dd366ed4e85.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <wfw:comment>http://www.programgood.net/CommentView,guid,d746049f-288a-4286-a32c-9dd366ed4e85.aspx</wfw:comment>
      <wfw:commentRss>http://www.programgood.net/SyndicationService.asmx/GetEntryCommentsRss?guid=d746049f-288a-4286-a32c-9dd366ed4e85</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
When using a shared hosting provider, and only have access to 1 MSSQL database, it
is possible to have 2 different web applications hanging off the same database.
</p>
        <p>
The users seem to be different, however the roles are across all applications.
</p>
        <p>
In VS2008, press the hammer and world icon:  as long as the web.config is pointing
to the live database, you can change the live data.
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETWebSiteAdministrationTool_A154/image_2.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETWebSiteAdministrationTool_A154/image_thumb.png" width="265" height="513" />
          </a>
        </p>
        <p>
And if you’ve a different project eg 
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETWebSiteAdministrationTool_A154/image_4.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETWebSiteAdministrationTool_A154/image_thumb_1.png" width="263" height="364" />
          </a>
        </p>
        <p>
You can do the same thing and connect to the same live database.
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETWebSiteAdministrationTool_A154/image_6.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETWebSiteAdministrationTool_A154/image_thumb_2.png" width="532" height="484" />
          </a>
        </p>
        <p>
Here are roles from 2 different webapps.  Coach and runner;  then administrators,
power users, and users.
</p>
        <p>
        </p>
        <p>
        </p>
        <h3>App_Data Database
</h3>
        <p>
This was useful when sending the code to others, so they don’t have to manually make
a new database.
</p>
        <p>
&lt;add name="LocalSqlServer" connectionString="Data Source=.\SQLEXPRESS;Integrated
Security=True;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;User Instance=True" 
providerName="System.Data.SqlClient" /&gt;
</p>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=d746049f-288a-4286-a32c-9dd366ed4e85" />
      </body>
      <title>ASP.NET Web Site Administration Tool</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,d746049f-288a-4286-a32c-9dd366ed4e85.aspx</guid>
      <link>http://www.programgood.net/2010/02/03/ASPNETWebSiteAdministrationTool.aspx</link>
      <pubDate>Wed, 03 Feb 2010 23:20:31 GMT</pubDate>
      <description>&lt;p&gt;
When using a shared hosting provider, and only have access to 1 MSSQL database, it
is possible to have 2 different web applications hanging off the same database.
&lt;/p&gt;
&lt;p&gt;
The users seem to be different, however the roles are across all applications.
&lt;/p&gt;
&lt;p&gt;
In VS2008, press the hammer and world icon:&amp;#160; as long as the web.config is pointing
to the live database, you can change the live data.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETWebSiteAdministrationTool_A154/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETWebSiteAdministrationTool_A154/image_thumb.png" width="265" height="513" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
And if you’ve a different project eg 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETWebSiteAdministrationTool_A154/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETWebSiteAdministrationTool_A154/image_thumb_1.png" width="263" height="364" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
You can do the same thing and connect to the same live database.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETWebSiteAdministrationTool_A154/image_6.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ASP.NETWebSiteAdministrationTool_A154/image_thumb_2.png" width="532" height="484" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Here are roles from 2 different webapps.&amp;#160; Coach and runner;&amp;#160; then administrators,
power users, and users.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;h3&gt;App_Data Database
&lt;/h3&gt;
&lt;p&gt;
This was useful when sending the code to others, so they don’t have to manually make
a new database.
&lt;/p&gt;
&lt;p&gt;
&amp;lt;add name=&amp;quot;LocalSqlServer&amp;quot; connectionString=&amp;quot;Data Source=.\SQLEXPRESS;Integrated
Security=True;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;User Instance=True&amp;quot;&amp;#160;
providerName=&amp;quot;System.Data.SqlClient&amp;quot; /&amp;gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=d746049f-288a-4286-a32c-9dd366ed4e85" /&gt;</description>
      <comments>http://www.programgood.net/CommentView,guid,d746049f-288a-4286-a32c-9dd366ed4e85.aspx</comments>
      <category>Project Run</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=7e3bae70-4ddb-4e47-b8f9-509e62d9a37c</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,7e3bae70-4ddb-4e47-b8f9-509e62d9a37c.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <wfw:comment>http://www.programgood.net/CommentView,guid,7e3bae70-4ddb-4e47-b8f9-509e62d9a37c.aspx</wfw:comment>
      <wfw:commentRss>http://www.programgood.net/SyndicationService.asmx/GetEntryCommentsRss?guid=7e3bae70-4ddb-4e47-b8f9-509e62d9a37c</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
This helped me a lot understanding how various components worked in my application:
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/54019d7891b5_AE09/DSCN1364_small_2.jpg">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="DSCN1364_small" border="0" alt="DSCN1364_small" src="http://www.programgood.net/content/binary/WindowsLiveWriter/54019d7891b5_AE09/DSCN1364_small_thumb.jpg" width="580" height="772" />
          </a>
        </p>
        <p>
Some obvious omissions included no regex validation on time edit/add.
</p>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=7e3bae70-4ddb-4e47-b8f9-509e62d9a37c" />
      </body>
      <title>Refactoring of Architecture</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,7e3bae70-4ddb-4e47-b8f9-509e62d9a37c.aspx</guid>
      <link>http://www.programgood.net/2010/02/02/RefactoringOfArchitecture.aspx</link>
      <pubDate>Tue, 02 Feb 2010 04:18:07 GMT</pubDate>
      <description>&lt;p&gt;
This helped me a lot understanding how various components worked in my application:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/54019d7891b5_AE09/DSCN1364_small_2.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="DSCN1364_small" border="0" alt="DSCN1364_small" src="http://www.programgood.net/content/binary/WindowsLiveWriter/54019d7891b5_AE09/DSCN1364_small_thumb.jpg" width="580" height="772" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Some obvious omissions included no regex validation on time edit/add.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=7e3bae70-4ddb-4e47-b8f9-509e62d9a37c" /&gt;</description>
      <comments>http://www.programgood.net/CommentView,guid,7e3bae70-4ddb-4e47-b8f9-509e62d9a37c.aspx</comments>
      <category>Project Run</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=012001d8-680b-47d9-9861-c1d4b1160e4e</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,012001d8-680b-47d9-9861-c1d4b1160e4e.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <wfw:comment>http://www.programgood.net/CommentView,guid,012001d8-680b-47d9-9861-c1d4b1160e4e.aspx</wfw:comment>
      <wfw:commentRss>http://www.programgood.net/SyndicationService.asmx/GetEntryCommentsRss?guid=012001d8-680b-47d9-9861-c1d4b1160e4e</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Great video tutorial on: <a title="http://download.microsoft.com/download/3/6/0/3604c3d2-0db9-4726-910d-b3b8f93a86e4/hilo_membership-roles_final.wmv" href="http://download.microsoft.com/download/3/6/0/3604c3d2-0db9-4726-910d-b3b8f93a86e4/hilo_membership-roles_final.wmv">http://download.microsoft.com/download/3/6/0/3604c3d2-0db9-4726-910d-b3b8f93a86e4/hilo_membership-roles_final.wmv</a></p>
        <p>
Nice look and feel, however can’t find the source for the graphics.
</p>
        <p>
Click the little hammer and world to bring up the Web Site Administration Tool.
</p>
        <p>
Click <strong>show all</strong> to view the ASPNETDB.MDF
</p>
        <p>
By Default it puts it in an MDF file in App_Data which is a SQL Express powered db.
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_8.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_thumb_3.png" width="185" height="210" />
          </a>
        </p>
        <p>
Use Forms Authentication:
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_2.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_thumb.png" width="644" height="299" />
          </a>
        </p>
        <p>
Enable Roles (groups of users):
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_4.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_thumb_1.png" width="603" height="484" />
          </a>
        </p>
        <p>
Add some roles:
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_6.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_thumb_2.png" width="557" height="484" />
          </a>
        </p>
        <p>
On Default.aspx, Anonymous Template:
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_10.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_thumb_4.png" width="644" height="265" />
          </a>
        </p>
        <p>
Forgot password:
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_14.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_thumb_6.png" width="644" height="281" />
          </a>
        </p>
        <p>
Mail:
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_12.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_thumb_5.png" width="557" height="484" />
          </a>
        </p>
        <p>
Protecting a directory:
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_16.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_thumb_7.png" width="644" height="290" />
          </a>
        </p>
        <p>
My spike showed exactly how all this works.
</p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_18.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_thumb_8.png" width="188" height="192" />
          </a>
        </p>
        <p>
To get this to work live however (my hosting company doesn’t like me uploading MDF
files!).. I need to put the tables into my database.  So, can use Database Publishing
Wizard, or now it is included in VS2008.
</p>
        <p>
From <a title="http://weblogs.asp.net/scottgu/archive/2005/08/25/423703.aspx" href="http://weblogs.asp.net/scottgu/archive/2005/08/25/423703.aspx">http://weblogs.asp.net/scottgu/archive/2005/08/25/423703.aspx</a></p>
        <p>
          <strong>aspnet_regsql.exe</strong>
        </p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_20.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_thumb_9.png" width="622" height="484" />
          </a>
        </p>
        <p>
So this just created tables/views/SP’s in a new db – I used Membership1 as a test
db.
</p>
        <p>
Upload the tables after dumping out the SQL to a text file and got the following errors: 
<br /></p>
        <p>
Msg 468, Level 16, State 9, Procedure aspnet_UsersInRoles_AddUsersToRoles, Line 45 
<br />
Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS"
and "Latin1_General_CI_AS" in the equal to operation.
</p>
        <p>
Easiest way was to look at the script and search for all occurrences of:
</p>
        <p>
COLLATE SQL_Latin1_General_CP1_CI_AS
</p>
        <p>
and replace with nothing. 
</p>
        <h3>Web.Config
</h3>
        <p>
Need to tell the current membership provider where the data store is.
</p>
        <p>
&lt;connectionStrings&gt; 
</p>
        <p>
       &lt;remove name=”LocalSqlServer”/&gt; 
</p>
        <p>
        &lt;add name="LocalSqlServer"
connectionString="Data Source=DAVEXPLAPTOP;Initial Catalog=membership1;Persist
Security Info=True;User ID=runuser1;Password=runuser1" providerName="System.Data.SqlClient"
/&gt;
</p>
        <p>
   &lt;/connectionStrings&gt; 
</p>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=012001d8-680b-47d9-9861-c1d4b1160e4e" />
      </body>
      <title>Membership and Roles</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,012001d8-680b-47d9-9861-c1d4b1160e4e.aspx</guid>
      <link>http://www.programgood.net/2010/02/02/MembershipAndRoles.aspx</link>
      <pubDate>Tue, 02 Feb 2010 04:13:09 GMT</pubDate>
      <description>&lt;p&gt;
Great video tutorial on: &lt;a title="http://download.microsoft.com/download/3/6/0/3604c3d2-0db9-4726-910d-b3b8f93a86e4/hilo_membership-roles_final.wmv" href="http://download.microsoft.com/download/3/6/0/3604c3d2-0db9-4726-910d-b3b8f93a86e4/hilo_membership-roles_final.wmv"&gt;http://download.microsoft.com/download/3/6/0/3604c3d2-0db9-4726-910d-b3b8f93a86e4/hilo_membership-roles_final.wmv&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Nice look and feel, however can’t find the source for the graphics.
&lt;/p&gt;
&lt;p&gt;
Click the little hammer and world to bring up the Web Site Administration Tool.
&lt;/p&gt;
&lt;p&gt;
Click &lt;strong&gt;show all&lt;/strong&gt; to view the ASPNETDB.MDF
&lt;/p&gt;
&lt;p&gt;
By Default it puts it in an MDF file in App_Data which is a SQL Express powered db.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_8.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_thumb_3.png" width="185" height="210" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Use Forms Authentication:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_thumb.png" width="644" height="299" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Enable Roles (groups of users):
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_thumb_1.png" width="603" height="484" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Add some roles:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_thumb_2.png" width="557" height="484" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
On Default.aspx, Anonymous Template:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_10.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_thumb_4.png" width="644" height="265" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Forgot password:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_14.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_thumb_6.png" width="644" height="281" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Mail:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_12.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_thumb_5.png" width="557" height="484" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Protecting a directory:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_16.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_thumb_7.png" width="644" height="290" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
My spike showed exactly how all this works.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_18.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_thumb_8.png" width="188" height="192" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
To get this to work live however (my hosting company doesn’t like me uploading MDF
files!).. I need to put the tables into my database.&amp;#160; So, can use Database Publishing
Wizard, or now it is included in VS2008.
&lt;/p&gt;
&lt;p&gt;
From &lt;a title="http://weblogs.asp.net/scottgu/archive/2005/08/25/423703.aspx" href="http://weblogs.asp.net/scottgu/archive/2005/08/25/423703.aspx"&gt;http://weblogs.asp.net/scottgu/archive/2005/08/25/423703.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;aspnet_regsql.exe&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_20.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/MembershipRoles_91B2/image_thumb_9.png" width="622" height="484" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
So this just created tables/views/SP’s in a new db – I used Membership1 as a test
db.
&lt;/p&gt;
&lt;p&gt;
Upload the tables after dumping out the SQL to a text file and got the following errors: 
&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
Msg 468, Level 16, State 9, Procedure aspnet_UsersInRoles_AddUsersToRoles, Line 45 
&lt;br /&gt;
Cannot resolve the collation conflict between &amp;quot;SQL_Latin1_General_CP1_CI_AS&amp;quot;
and &amp;quot;Latin1_General_CI_AS&amp;quot; in the equal to operation.
&lt;/p&gt;
&lt;p&gt;
Easiest way was to look at the script and search for all occurrences of:
&lt;/p&gt;
&lt;p&gt;
COLLATE SQL_Latin1_General_CP1_CI_AS
&lt;/p&gt;
&lt;p&gt;
and replace with nothing. 
&lt;/p&gt;
&lt;h3&gt;Web.Config
&lt;/h3&gt;
&lt;p&gt;
Need to tell the current membership provider where the data store is.
&lt;/p&gt;
&lt;p&gt;
&amp;lt;connectionStrings&amp;gt; 
&lt;/p&gt;
&lt;p&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;remove name=”LocalSqlServer”/&amp;gt; 
&lt;/p&gt;
&lt;p&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;add name=&amp;quot;LocalSqlServer&amp;quot;
connectionString=&amp;quot;Data Source=DAVEXPLAPTOP;Initial Catalog=membership1;Persist
Security Info=True;User ID=runuser1;Password=runuser1&amp;quot; providerName=&amp;quot;System.Data.SqlClient&amp;quot;
/&amp;gt;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;&amp;#160; &amp;lt;/connectionStrings&amp;gt; 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=012001d8-680b-47d9-9861-c1d4b1160e4e" /&gt;</description>
      <comments>http://www.programgood.net/CommentView,guid,012001d8-680b-47d9-9861-c1d4b1160e4e.aspx</comments>
      <category>Project Run</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=701850df-7467-4b63-b3af-7596a861ca61</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,701850df-7467-4b63-b3af-7596a861ca61.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <wfw:comment>http://www.programgood.net/CommentView,guid,701850df-7467-4b63-b3af-7596a861ca61.aspx</wfw:comment>
      <wfw:commentRss>http://www.programgood.net/SyndicationService.asmx/GetEntryCommentsRss?guid=701850df-7467-4b63-b3af-7596a861ca61</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Am using publish web.. and automated build script so web.config is correct for dev
and live.  Needs to be a Web Application, and not a Web Site.
</p>
        <p>
          <a title="http://www.hanselman.com/blog/ManagingMultipleConfigurationFileEnvironmentsWithPreBuildEvents.aspx" href="http://www.hanselman.com/blog/ManagingMultipleConfigurationFileEnvironmentsWithPreBuildEvents.aspx">http://www.hanselman.com/blog/ManagingMultipleConfigurationFileEnvironmentsWithPreBuildEvents.aspx</a>
        </p>
        <p>
Differences between Web Sites and Web Applications <a title="http://www.codersbarn.com/post/2008/06/ASPNET-Web-Site-versus-Web-Application-Project.aspx" href="http://www.codersbarn.com/post/2008/06/ASPNET-Web-Site-versus-Web-Application-Project.aspx">http://www.codersbarn.com/post/2008/06/ASPNET-Web-Site-versus-Web-Application-Project.aspx</a></p>
        <p>
Also if doing more than one pre-build call need to do this:
</p>
        <p>
call "$(ProjectDir)copyifnewer.bat" "$(ProjectDir)web.config.$(ConfigurationName)"
"$(ProjectDir)web.config" 
<br />
call "$(ProjectDir)copyifnewer.bat" "$(ProjectDir)LoggedIn\web.config.$(ConfigurationName)"
"$(ProjectDir)LoggedIn\web.config"
</p>
        <p>
Also I got an error in dev, where my debugging wasn’t working properly.  Had
to tick debug info to full here.
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/Web.Configautomatingdevandlive_A67B/image_2.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/Web.Configautomatingdevandlive_A67B/image_thumb.png" width="644" height="455" />
          </a>
        </p>
        <p>
to do – possibly abstract out the connection string settings (and anything else dev/live
specific) into another file, so the actual Web.config can be changed by VS easily.
</p>
        <p>
In Visual Basic the interface is slightly different however it is in there!
</p>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=701850df-7467-4b63-b3af-7596a861ca61" />
      </body>
      <title>Web.Config automating dev and live</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,701850df-7467-4b63-b3af-7596a861ca61.aspx</guid>
      <link>http://www.programgood.net/2010/01/28/WebConfigAutomatingDevAndLive.aspx</link>
      <pubDate>Thu, 28 Jan 2010 22:52:17 GMT</pubDate>
      <description>&lt;p&gt;
Am using publish web.. and automated build script so web.config is correct for dev
and live.&amp;#160; Needs to be a Web Application, and not a Web Site.
&lt;/p&gt;
&lt;p&gt;
&lt;a title="http://www.hanselman.com/blog/ManagingMultipleConfigurationFileEnvironmentsWithPreBuildEvents.aspx" href="http://www.hanselman.com/blog/ManagingMultipleConfigurationFileEnvironmentsWithPreBuildEvents.aspx"&gt;http://www.hanselman.com/blog/ManagingMultipleConfigurationFileEnvironmentsWithPreBuildEvents.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Differences between Web Sites and Web Applications &lt;a title="http://www.codersbarn.com/post/2008/06/ASPNET-Web-Site-versus-Web-Application-Project.aspx" href="http://www.codersbarn.com/post/2008/06/ASPNET-Web-Site-versus-Web-Application-Project.aspx"&gt;http://www.codersbarn.com/post/2008/06/ASPNET-Web-Site-versus-Web-Application-Project.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Also if doing more than one pre-build call need to do this:
&lt;/p&gt;
&lt;p&gt;
call &amp;quot;$(ProjectDir)copyifnewer.bat&amp;quot; &amp;quot;$(ProjectDir)web.config.$(ConfigurationName)&amp;quot;
&amp;quot;$(ProjectDir)web.config&amp;quot; 
&lt;br /&gt;
call &amp;quot;$(ProjectDir)copyifnewer.bat&amp;quot; &amp;quot;$(ProjectDir)LoggedIn\web.config.$(ConfigurationName)&amp;quot;
&amp;quot;$(ProjectDir)LoggedIn\web.config&amp;quot;
&lt;/p&gt;
&lt;p&gt;
Also I got an error in dev, where my debugging wasn’t working properly.&amp;#160; Had
to tick debug info to full here.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/Web.Configautomatingdevandlive_A67B/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/Web.Configautomatingdevandlive_A67B/image_thumb.png" width="644" height="455" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
to do – possibly abstract out the connection string settings (and anything else dev/live
specific) into another file, so the actual Web.config can be changed by VS easily.
&lt;/p&gt;
&lt;p&gt;
In Visual Basic the interface is slightly different however it is in there!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=701850df-7467-4b63-b3af-7596a861ca61" /&gt;</description>
      <comments>http://www.programgood.net/CommentView,guid,701850df-7467-4b63-b3af-7596a861ca61.aspx</comments>
      <category>Project Run</category>
      <category>Tools</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=24581d10-189a-4b99-82db-a9fd6f3fd857</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,24581d10-189a-4b99-82db-a9fd6f3fd857.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <wfw:comment>http://www.programgood.net/CommentView,guid,24581d10-189a-4b99-82db-a9fd6f3fd857.aspx</wfw:comment>
      <wfw:commentRss>http://www.programgood.net/SyndicationService.asmx/GetEntryCommentsRss?guid=24581d10-189a-4b99-82db-a9fd6f3fd857</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Spikes are great.. aim to try things very fast to prove things work. KISS!  These
are all on <a href="http://www.mateerit.co.nz/HelloWorld/">http://www.mateerit.co.nz/HelloWorld/</a></p>
        <h3>Hello World 
</h3>
        <p>
Web Application, view it locally, view it on live server.
</p>
        <p>
Locally is fine.  For live I’m on a shared server, and have to remember to create
a new virtual directory (clicking Web Directory below)
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_2.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_thumb.png" width="567" height="484" />
          </a>
        </p>
        <p>
Setup VS to publish the site (in Build menu).. use this syntax:  <a href="ftp://myuser%3Amypass@myftpsite.com:21/my/path/to/web/root/">ftp://myuser%3Amypass@myftpsite.com:21/my/path/to/web/root/</a></p>
        <p>
to avoid having to type in password each time!
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_4.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_thumb_1.png" width="644" height="471" />
          </a>
        </p>
        <p>
Alt B H enter, to publish to live site quickly.
</p>
        <h3>Connect to the Database
</h3>
        <p>
print something on the screen from the SQL Server..locally:
</p>
        <p>
Aim is to print off a list of Persons:
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_8.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_thumb_3.png" width="621" height="484" />
          </a>
        </p>
        <p>
Simplest way to do this is:
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_10.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_thumb_4.png" width="545" height="484" />
          </a>
        </p>
        <p>
Put on a grid and wire it up:
</p>
        <p>
Publish live, and it wont be able to find the correct connection string:
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_12.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_thumb_5.png" width="768" height="327" />
          </a>
        </p>
        <p>
Went into web.config and commented out the local one, and put in another for the live
server.
</p>
        <p>
&lt;!--&lt;add name="RunConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial
Catalog=Run;Persist Security Info=True;User ID=runuser1;Password=runuser1" 
providerName="System.Data.SqlClient" /&gt;—&gt;
</p>
        <p>
          <br />
    &lt;add name="RunConnectionString" connectionString="Data
Source=mssql1.openhost.net.nz;Initial Catalog=mateer;Persist Security Info=True;User
ID=mateeruser;Password=secret"  providerName="System.Data.SqlClient"
/&gt;
</p>
        <p>
Its also useful to be able to connect to the remote database directly:  My host
makes you open its firewall rules a week at a time from here: <a title="https://winplesk6.openhost.net.nz/sql.php" href="https://winplesk6.openhost.net.nz/sql.php">https://winplesk6.openhost.net.nz/sql.php</a> or
mateerit.co.nz:85/sql.php
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_6.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_thumb_2.png" width="445" height="354" />
          </a>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <h3>SqlDataSource
</h3>
        <p>
The SqlDataSource data source control represents data in an SQL relational database
to data-bound controls. You can use the SqlDataSource control in conjunction with
a data-bound control to retrieve data from a relational database and to display, edit,
and sort data on a Web page with little or no code.
</p>
        <p>
However this bypassing the tiered approach, and is essentially putting all logic in
the webpage!
</p>
        <p>
In Project Run I ended up using ObjectDataSource (to connect to the underlying architecture
allowing me to use data Web controls such as GridView, DetailsView or DataList). 
Picture from: <a title="http://www.asp.net/learn/data-access/tutorial-47-cs.aspx" href="http://www.asp.net/learn/data-access/tutorial-47-cs.aspx">http://www.asp.net/learn/data-access/tutorial-47-cs.aspx</a></p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_14.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_thumb_6.png" width="529" height="490" />
          </a>
        </p>
        <div id="codeSnippetWrapper">
          <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">&lt;asp:SqlDataSource ID=<span style="color: #006080">"PersonsDataSource"</span> runat=<span style="color: #006080">"server"</span></pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        ConnectionString=<span style="color: #006080">"&lt;%$
ConnectionStrings:RunConnectionString %&gt;"</span></pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        SelectCommand=<span style="color: #006080">"SELECT
[personid], [personname] FROM [Person]"</span>&gt;</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    &lt;/asp:SqlDataSource&gt;</pre>
            <!--CRLF-->
          </div>
        </div>
        <h3>GridView
</h3>
        <p>
Changing the header titles, colours
</p>
        <p>
Sorting and paging work as data is into a loosely-typed DataSet.
</p>
        <p>
Could use a DataReader (instead of a DataSet on the SqlDataSource) which is simpler,
but no sorting, paging.
</p>
        <p>
Add / Edit / Delete – Need to add those into the SqlDataSource.  Very easy to
make Edit and Delete.
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_16.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_thumb_7.png" width="315" height="424" />
          </a>
        </p>
        <p>
Harder to make an insert.. see here for ‘workaround’ and discussion: <a title="http://www.codeproject.com/KB/aspnet/InsertSqlDataSource.aspx" href="http://www.codeproject.com/KB/aspnet/InsertSqlDataSource.aspx">http://www.codeproject.com/KB/aspnet/InsertSqlDataSource.aspx</a></p>
        <h3>DataList
</h3>
        <p>
Provides greater flexibility – render using templates.  This will emit a &lt;table&gt;&lt;tr&gt;&lt;td&gt;
syntax.
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_18.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_thumb_8.png" width="265" height="492" />
          </a>
        </p>
        <h3>Repeater
</h3>
        <p>
Renders nothing other than what you tell it.
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_20.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_thumb_9.png" width="670" height="278" />
          </a>
        </p>
        <p>
        </p>
        <p>
        </p>
        <h3>DetailsView
</h3>
        <p>
View one record at a time, and very easy to get a new record.  Built in paging.
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_22.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_thumb_10.png" width="176" height="160" />
          </a>
        </p>
        <h3>FormView
</h3>
        <p>
Same as details but less rigid layout.
</p>
        <h3>ListView
</h3>
        <p>
3.5.. provides more control over markup.  Easy insert
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_24.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_thumb_11.png" width="392" height="258" />
          </a>
        </p>
        <p>
 
</p>
        <h3>DataPager
</h3>
        <p>
new in 3.5 too.  The First, Previous, Next, Last control.
</p>
        <p>
        </p>
        <p>
 
</p>
        <p>
Enabling split view vertically.. very cool.
</p>
        <p>
          <a title="http://weblogs.asp.net/scottgu/archive/2007/07/30/enabling-vertical-split-view-in-vs-2008.aspx" href="http://weblogs.asp.net/scottgu/archive/2007/07/30/enabling-vertical-split-view-in-vs-2008.aspx">http://weblogs.asp.net/scottgu/archive/2007/07/30/enabling-vertical-split-view-in-vs-2008.aspx</a>
        </p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_26.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_thumb_12.png" width="644" height="223" />
          </a>
        </p>
        <p>
 
</p>
        <h3>
          <p>
            <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_28.png">
            </a>
          </p>
        </h3>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=24581d10-189a-4b99-82db-a9fd6f3fd857" />
      </body>
      <title>Spikes for Project Run</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,24581d10-189a-4b99-82db-a9fd6f3fd857.aspx</guid>
      <link>http://www.programgood.net/2010/01/28/SpikesForProjectRun.aspx</link>
      <pubDate>Thu, 28 Jan 2010 02:42:59 GMT</pubDate>
      <description>&lt;p&gt;
Spikes are great.. aim to try things very fast to prove things work. KISS!&amp;#160; These
are all on &lt;a href="http://www.mateerit.co.nz/HelloWorld/"&gt;http://www.mateerit.co.nz/HelloWorld/&lt;/a&gt;
&lt;/p&gt;
&lt;h3&gt;Hello World 
&lt;/h3&gt;
&lt;p&gt;
Web Application, view it locally, view it on live server.
&lt;/p&gt;
&lt;p&gt;
Locally is fine.&amp;#160; For live I’m on a shared server, and have to remember to create
a new virtual directory (clicking Web Directory below)
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_thumb.png" width="567" height="484" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Setup VS to publish the site (in Build menu).. use this syntax:&amp;#160; &lt;a href="ftp://myuser%3Amypass@myftpsite.com:21/my/path/to/web/root/"&gt;ftp://myuser%3Amypass@myftpsite.com:21/my/path/to/web/root/&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
to avoid having to type in password each time!
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_thumb_1.png" width="644" height="471" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Alt B H enter, to publish to live site quickly.
&lt;/p&gt;
&lt;h3&gt;Connect to the Database
&lt;/h3&gt;
&lt;p&gt;
print something on the screen from the SQL Server..locally:
&lt;/p&gt;
&lt;p&gt;
Aim is to print off a list of Persons:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_8.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_thumb_3.png" width="621" height="484" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Simplest way to do this is:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_10.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_thumb_4.png" width="545" height="484" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Put on a grid and wire it up:
&lt;/p&gt;
&lt;p&gt;
Publish live, and it wont be able to find the correct connection string:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_12.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_thumb_5.png" width="768" height="327" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Went into web.config and commented out the local one, and put in another for the live
server.
&lt;/p&gt;
&lt;p&gt;
&amp;lt;!--&amp;lt;add name=&amp;quot;RunConnectionString&amp;quot; connectionString=&amp;quot;Data Source=.\SQLEXPRESS;Initial
Catalog=Run;Persist Security Info=True;User ID=runuser1;Password=runuser1&amp;quot;&amp;#160;
providerName=&amp;quot;System.Data.SqlClient&amp;quot; /&amp;gt;—&amp;gt;
&lt;/p&gt;
&lt;p&gt;
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; &amp;lt;add name=&amp;quot;RunConnectionString&amp;quot; connectionString=&amp;quot;Data
Source=mssql1.openhost.net.nz;Initial Catalog=mateer;Persist Security Info=True;User
ID=mateeruser;Password=secret&amp;quot;&amp;#160; providerName=&amp;quot;System.Data.SqlClient&amp;quot;
/&amp;gt;
&lt;/p&gt;
&lt;p&gt;
Its also useful to be able to connect to the remote database directly:&amp;#160; My host
makes you open its firewall rules a week at a time from here: &lt;a title="https://winplesk6.openhost.net.nz/sql.php" href="https://winplesk6.openhost.net.nz/sql.php"&gt;https://winplesk6.openhost.net.nz/sql.php&lt;/a&gt; or
mateerit.co.nz:85/sql.php
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_thumb_2.png" width="445" height="354" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;h3&gt;SqlDataSource
&lt;/h3&gt;
&lt;p&gt;
The SqlDataSource data source control represents data in an SQL relational database
to data-bound controls. You can use the SqlDataSource control in conjunction with
a data-bound control to retrieve data from a relational database and to display, edit,
and sort data on a Web page with little or no code.
&lt;/p&gt;
&lt;p&gt;
However this bypassing the tiered approach, and is essentially putting all logic in
the webpage!
&lt;/p&gt;
&lt;p&gt;
In Project Run I ended up using ObjectDataSource (to connect to the underlying architecture
allowing me to use data Web controls such as GridView, DetailsView or DataList).&amp;#160;
Picture from: &lt;a title="http://www.asp.net/learn/data-access/tutorial-47-cs.aspx" href="http://www.asp.net/learn/data-access/tutorial-47-cs.aspx"&gt;http://www.asp.net/learn/data-access/tutorial-47-cs.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_14.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_thumb_6.png" width="529" height="490" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;lt;asp:SqlDataSource ID=&lt;span style="color: #006080"&gt;&amp;quot;PersonsDataSource&amp;quot;&lt;/span&gt; runat=&lt;span style="color: #006080"&gt;&amp;quot;server&amp;quot;&lt;/span&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        ConnectionString=&lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;%$
ConnectionStrings:RunConnectionString %&amp;gt;&amp;quot;&lt;/span&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        SelectCommand=&lt;span style="color: #006080"&gt;&amp;quot;SELECT
[personid], [personname] FROM [Person]&amp;quot;&lt;/span&gt;&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &amp;lt;/asp:SqlDataSource&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h3&gt;GridView
&lt;/h3&gt;
&lt;p&gt;
Changing the header titles, colours
&lt;/p&gt;
&lt;p&gt;
Sorting and paging work as data is into a loosely-typed DataSet.
&lt;/p&gt;
&lt;p&gt;
Could use a DataReader (instead of a DataSet on the SqlDataSource) which is simpler,
but no sorting, paging.
&lt;/p&gt;
&lt;p&gt;
Add / Edit / Delete – Need to add those into the SqlDataSource.&amp;#160; Very easy to
make Edit and Delete.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_16.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_thumb_7.png" width="315" height="424" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Harder to make an insert.. see here for ‘workaround’ and discussion: &lt;a title="http://www.codeproject.com/KB/aspnet/InsertSqlDataSource.aspx" href="http://www.codeproject.com/KB/aspnet/InsertSqlDataSource.aspx"&gt;http://www.codeproject.com/KB/aspnet/InsertSqlDataSource.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;h3&gt;DataList
&lt;/h3&gt;
&lt;p&gt;
Provides greater flexibility – render using templates.&amp;#160; This will emit a &amp;lt;table&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;
syntax.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_18.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_thumb_8.png" width="265" height="492" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;h3&gt;Repeater
&lt;/h3&gt;
&lt;p&gt;
Renders nothing other than what you tell it.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_20.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_thumb_9.png" width="670" height="278" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;h3&gt;DetailsView
&lt;/h3&gt;
&lt;p&gt;
View one record at a time, and very easy to get a new record.&amp;#160; Built in paging.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_22.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_thumb_10.png" width="176" height="160" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;h3&gt;FormView
&lt;/h3&gt;
&lt;p&gt;
Same as details but less rigid layout.
&lt;/p&gt;
&lt;h3&gt;ListView
&lt;/h3&gt;
&lt;p&gt;
3.5.. provides more control over markup.&amp;#160; Easy insert
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_24.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_thumb_11.png" width="392" height="258" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;h3&gt;DataPager
&lt;/h3&gt;
&lt;p&gt;
new in 3.5 too.&amp;#160; The First, Previous, Next, Last control.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
Enabling split view vertically.. very cool.
&lt;/p&gt;
&lt;p&gt;
&lt;a title="http://weblogs.asp.net/scottgu/archive/2007/07/30/enabling-vertical-split-view-in-vs-2008.aspx" href="http://weblogs.asp.net/scottgu/archive/2007/07/30/enabling-vertical-split-view-in-vs-2008.aspx"&gt;http://weblogs.asp.net/scottgu/archive/2007/07/30/enabling-vertical-split-view-in-vs-2008.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_26.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_thumb_12.png" width="644" height="223" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;h3&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/SpikesforProjectRun_9D26/image_28.png"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;/h3&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=24581d10-189a-4b99-82db-a9fd6f3fd857" /&gt;</description>
      <comments>http://www.programgood.net/CommentView,guid,24581d10-189a-4b99-82db-a9fd6f3fd857.aspx</comments>
      <category>Project Run</category>
    </item>
    <item>
      <trackback:ping>http://www.programgood.net/Trackback.aspx?guid=9d3f7ecc-55da-4597-aa8f-90836a9a1dd8</trackback:ping>
      <pingback:server>http://www.programgood.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.programgood.net/PermaLink,guid,9d3f7ecc-55da-4597-aa8f-90836a9a1dd8.aspx</pingback:target>
      <dc:creator>Dave Mateer</dc:creator>
      <wfw:comment>http://www.programgood.net/CommentView,guid,9d3f7ecc-55da-4597-aa8f-90836a9a1dd8.aspx</wfw:comment>
      <wfw:commentRss>http://www.programgood.net/SyndicationService.asmx/GetEntryCommentsRss?guid=9d3f7ecc-55da-4597-aa8f-90836a9a1dd8</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
This is a series of posts about an existing fun project of mine which I’ve decided
to refactor,to see how 
</p>
        <ul>
          <li>
Elegant I can make the code</li>
          <li>
Example of the ‘journey’ of refactoring</li>
          <li>
Working with other great programmers.</li>
        </ul>
        <p>
Project Run started a few years ago when myself and Pete were training for the St
James Race.  This is all real, and we completed the race!
</p>
        <h3>Elevator Pitch
</h3>
        <p>
Runners can record their training online. The coach can easily see their recorded
training, and can make notes. It will be motivational and competitive for the runners
to see what they have done. It will show how long to go before the event they are
training for.
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ProjectRunRefactoring_90A1/image_2.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ProjectRunRefactoring_90A1/image_thumb.png" width="524" height="484" />
          </a>
        </p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ProjectRunRefactoring_90A1/image_4.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ProjectRunRefactoring_90A1/image_thumb_1.png" width="572" height="484" />
          </a>
        </p>
        <h3>Stories / Requirements
</h3>
        <p>
Star * means most important stories that will be developed in version 1.
</p>
        <p>
1) *Dave is a runner. He goes to the website logs in, and enters in the run he has
just done. Twice round Hagley Park. 13kms. Took 1:20. Perceived effort - Steady
</p>
        <p>
2) *Pete is a runner. He has just done a Port Hills run. 1:30. Uphill sections were
Moderate to Mod Hard. Flat and downhill were Steady.
</p>
        <p>
3) *Chris is the coach. He goes to the website, logs in. Then looks at Dave and Petes
past weeks activity. He makes overall notes for both of them. He makes specific notes
for Dave.
</p>
        <p>
4) *Dave logs in and is proud to see he has completed this weeks training goals of
40km and 10 hours. 
</p>
        <p>
5) *Pete logs in and sees that his progress has improved because 4 weeks ago he did
40kms and was ‘Tired’ at the end of the week. Yet this week he has done 60kms and
is feeling good.
</p>
        <p>
6) *Dave logs in and puts in that he did 2 hours of mountain biking covering 30kms.
</p>
        <p>
7) *Pete logs in and puts in 1 hour of Yoga.
</p>
        <p>
8) *Dave logs in and adds in the 10mins of stretching he did to the run he just entered
</p>
        <p>
9) *Dave logs in and makes a mess of things, and wants to delete todays run, which
he puts in as 2009.
</p>
        <p>
10) *Dave adds in a note to a previous day about running with food. He likes leppin
and is going to try other stuff.
</p>
        <p>
11) *edit
</p>
        <p>
12) *Chris goes to website and has forgotten his password. The system sends a new
one to his email account.
</p>
        <p>
13) Chris logs in and easily alters the training plan for Pete and Dave.
</p>
        <p>
14) Dave logs in and puts his max heart rate in, average, max speed, average and time
in each training zone.
</p>
        <p>
15) Dave uploads data using his watch to the website.
</p>
        <h3>Timeline 
</h3>
        <p>
Was 2 weeks.  This included working with a great designer (Nora).
</p>
        <h3>UI Design
</h3>
        <p>
Working from paper sketches, where the design goal was simplicity, therefore only
2 real pages to the site.  Nora does Photoshop mockups.. 
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ProjectRunRefactoring_90A1/home_2.jpg">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Web" border="0" alt="Web" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ProjectRunRefactoring_90A1/home_thumb.jpg" width="244" height="184" />
          </a>
        </p>
        <h3>Architecture / Methodology
</h3>
        <p>
.NET2 Webforms hosted on a shared cheap hosting solution.
</p>
        <p>
SQL Server2005
</p>
        <p>
TDD Test first then write code - nUnit.
</p>
        <p>
Controls used (I wanted to know how much comes out of the box in .NET, and how much
I could leverage).. used these as a  result of successful spikes (see below)
</p>
        <ul>
          <li>
Membership</li>
          <li>
Login / Password recovery</li>
          <li>
Master Pages</li>
          <li>
Data Grid</li>
          <li>
Repeater</li>
          <li>
Validation</li>
          <li>
Menu builder</li>
          <li>
Themes</li>
        </ul>
        <p>
2 Tiers:
</p>
        <p>
          <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ProjectRunRefactoring_90A1/image_6.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ProjectRunRefactoring_90A1/image_thumb_2.png" width="240" height="573" />
          </a>
        </p>
        <p>
Source control was Subversion, now I’ve moved to GIT.
</p>
        <h3>Spikes (UI)
</h3>
        <p>
Here is a snapshot of the code right now before I do any more refactoring:
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:5dbd994f-de02-4b1f-9503-ed119d1fcfa5" class="wlWriterEditableSmartContent">
          <p>
            <a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ProjectRunRefactoring_90A1/ProjectRun1.zip" target="_blank">ProjectRun1</a>
          </p>
        </div>
        <p>
        </p>
        <p>
To remind myself how these front end UI controls work… going to create new blog post
for these spikes.
</p>
        <h3>Spikes (BLL/DAL)
</h3>
        <p>
Used TDD as much as possible to drive features
</p>
        <h3>Development Process
</h3>
        <p>
Project timeline – used a word document
</p>
        <p>
Bug tracking – word document.
</p>
        <p>
Got code live as soon as possible, and to ‘clients’ as soon as possible for feedback.
</p>
        <img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=9d3f7ecc-55da-4597-aa8f-90836a9a1dd8" />
      </body>
      <title>Project Run – Refactoring</title>
      <guid isPermaLink="false">http://www.programgood.net/PermaLink,guid,9d3f7ecc-55da-4597-aa8f-90836a9a1dd8.aspx</guid>
      <link>http://www.programgood.net/2010/01/27/ProjectRunRefactoring.aspx</link>
      <pubDate>Wed, 27 Jan 2010 21:57:38 GMT</pubDate>
      <description>&lt;p&gt;
This is a series of posts about an existing fun project of mine which I’ve decided
to refactor,to see how 
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Elegant I can make the code&lt;/li&gt;
&lt;li&gt;
Example of the ‘journey’ of refactoring&lt;/li&gt;
&lt;li&gt;
Working with other great programmers.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Project Run started a few years ago when myself and Pete were training for the St
James Race.&amp;#160; This is all real, and we completed the race!
&lt;/p&gt;
&lt;h3&gt;Elevator Pitch
&lt;/h3&gt;
&lt;p&gt;
Runners can record their training online. The coach can easily see their recorded
training, and can make notes. It will be motivational and competitive for the runners
to see what they have done. It will show how long to go before the event they are
training for.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ProjectRunRefactoring_90A1/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ProjectRunRefactoring_90A1/image_thumb.png" width="524" height="484" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ProjectRunRefactoring_90A1/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ProjectRunRefactoring_90A1/image_thumb_1.png" width="572" height="484" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;h3&gt;Stories / Requirements
&lt;/h3&gt;
&lt;p&gt;
Star * means most important stories that will be developed in version 1.
&lt;/p&gt;
&lt;p&gt;
1) *Dave is a runner. He goes to the website logs in, and enters in the run he has
just done. Twice round Hagley Park. 13kms. Took 1:20. Perceived effort - Steady
&lt;/p&gt;
&lt;p&gt;
2) *Pete is a runner. He has just done a Port Hills run. 1:30. Uphill sections were
Moderate to Mod Hard. Flat and downhill were Steady.
&lt;/p&gt;
&lt;p&gt;
3) *Chris is the coach. He goes to the website, logs in. Then looks at Dave and Petes
past weeks activity. He makes overall notes for both of them. He makes specific notes
for Dave.
&lt;/p&gt;
&lt;p&gt;
4) *Dave logs in and is proud to see he has completed this weeks training goals of
40km and 10 hours. 
&lt;/p&gt;
&lt;p&gt;
5) *Pete logs in and sees that his progress has improved because 4 weeks ago he did
40kms and was ‘Tired’ at the end of the week. Yet this week he has done 60kms and
is feeling good.
&lt;/p&gt;
&lt;p&gt;
6) *Dave logs in and puts in that he did 2 hours of mountain biking covering 30kms.
&lt;/p&gt;
&lt;p&gt;
7) *Pete logs in and puts in 1 hour of Yoga.
&lt;/p&gt;
&lt;p&gt;
8) *Dave logs in and adds in the 10mins of stretching he did to the run he just entered
&lt;/p&gt;
&lt;p&gt;
9) *Dave logs in and makes a mess of things, and wants to delete todays run, which
he puts in as 2009.
&lt;/p&gt;
&lt;p&gt;
10) *Dave adds in a note to a previous day about running with food. He likes leppin
and is going to try other stuff.
&lt;/p&gt;
&lt;p&gt;
11) *edit
&lt;/p&gt;
&lt;p&gt;
12) *Chris goes to website and has forgotten his password. The system sends a new
one to his email account.
&lt;/p&gt;
&lt;p&gt;
13) Chris logs in and easily alters the training plan for Pete and Dave.
&lt;/p&gt;
&lt;p&gt;
14) Dave logs in and puts his max heart rate in, average, max speed, average and time
in each training zone.
&lt;/p&gt;
&lt;p&gt;
15) Dave uploads data using his watch to the website.
&lt;/p&gt;
&lt;h3&gt;Timeline 
&lt;/h3&gt;
&lt;p&gt;
Was 2 weeks.&amp;#160; This included working with a great designer (Nora).
&lt;/p&gt;
&lt;h3&gt;UI Design
&lt;/h3&gt;
&lt;p&gt;
Working from paper sketches, where the design goal was simplicity, therefore only
2 real pages to the site.&amp;#160; Nora does Photoshop mockups.. 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ProjectRunRefactoring_90A1/home_2.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Web" border="0" alt="Web" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ProjectRunRefactoring_90A1/home_thumb.jpg" width="244" height="184" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;h3&gt;Architecture / Methodology
&lt;/h3&gt;
&lt;p&gt;
.NET2 Webforms hosted on a shared cheap hosting solution.
&lt;/p&gt;
&lt;p&gt;
SQL Server2005
&lt;/p&gt;
&lt;p&gt;
TDD Test first then write code - nUnit.
&lt;/p&gt;
&lt;p&gt;
Controls used (I wanted to know how much comes out of the box in .NET, and how much
I could leverage).. used these as a&amp;#160; result of successful spikes (see below)
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Membership&lt;/li&gt;
&lt;li&gt;
Login / Password recovery&lt;/li&gt;
&lt;li&gt;
Master Pages&lt;/li&gt;
&lt;li&gt;
Data Grid&lt;/li&gt;
&lt;li&gt;
Repeater&lt;/li&gt;
&lt;li&gt;
Validation&lt;/li&gt;
&lt;li&gt;
Menu builder&lt;/li&gt;
&lt;li&gt;
Themes&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
2 Tiers:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ProjectRunRefactoring_90A1/image_6.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.programgood.net/content/binary/WindowsLiveWriter/ProjectRunRefactoring_90A1/image_thumb_2.png" width="240" height="573" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Source control was Subversion, now I’ve moved to GIT.
&lt;/p&gt;
&lt;h3&gt;Spikes (UI)
&lt;/h3&gt;
&lt;p&gt;
Here is a snapshot of the code right now before I do any more refactoring:
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:5dbd994f-de02-4b1f-9503-ed119d1fcfa5" class="wlWriterEditableSmartContent"&gt;
&lt;p&gt;
&lt;a href="http://www.programgood.net/content/binary/WindowsLiveWriter/ProjectRunRefactoring_90A1/ProjectRun1.zip" target="_blank"&gt;ProjectRun1&lt;/a&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
To remind myself how these front end UI controls work… going to create new blog post
for these spikes.
&lt;/p&gt;
&lt;h3&gt;Spikes (BLL/DAL)
&lt;/h3&gt;
&lt;p&gt;
Used TDD as much as possible to drive features
&lt;/p&gt;
&lt;h3&gt;Development Process
&lt;/h3&gt;
&lt;p&gt;
Project timeline – used a word document
&lt;/p&gt;
&lt;p&gt;
Bug tracking – word document.
&lt;/p&gt;
&lt;p&gt;
Got code live as soon as possible, and to ‘clients’ as soon as possible for feedback.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.programgood.net/aggbug.ashx?id=9d3f7ecc-55da-4597-aa8f-90836a9a1dd8" /&gt;</description>
      <comments>http://www.programgood.net/CommentView,guid,9d3f7ecc-55da-4597-aa8f-90836a9a1dd8.aspx</comments>
      <category>Project Run</category>
    </item>
  </channel>
</rss>