E-mail
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.
Upload to IIS7 and it just works!
The first step was to see if routing worked on the default website.. it did!
The next step – to publish up the NerdDinner app I’ve been going through on Rob Conery, and get the database connected live.
The crowd goes wild - this is live and connecting to a database
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..
routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Activity", action = "Index", id = "" } // Parameter defaults);
Change controller = “Home” to controller = “Acitivity”
I also implemented the copyifnewer.bat trick for easily going from dev to live which is here: http://www.programgood.net/2010/01/28/WebConfigAutomatingDevAndLive.aspx
Run application working live with Create, Read, Update and Delete working. Also validation, which comes for free in the standard templates.
DropDownList and Postbacks – covered in another post on this site.
http://www.mikesdotnetting.com/Article/128/Get-The-Drop-On-ASP.NET-MVC-DropDownLists
I created another link in the master page for menu item:
www.mateerit.co.nz/run
For the summary page I’m considering a ViewModel approach.
Lets see if a simple new Summary controller will suffice
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
Michael came up with an elegant solution which I’m trying.. so creating a SQL View:
SELECT personid, DATEPART(week, date) AS Week, DATEPART(year, date) AS Year, SUM(kilometres) AS kilometres, SUM(hours) AS hoursFROM dbo.ActivityGROUP BY personid, DATEPART(week, date), DATEPART(year, date)
which gives a good summary output:
The aim is to be able to see the summary of each week like this (this is the old webforms version)
linq to sql generated classes off the view.
Michael did it like this:
I’m on this:
As each person has data associated to them, a list within a list is good.
public class WeekSummary{ public int Personid; public string Personname; public List<WeekSummaryData> Persondata;}public class WeekSummaryData{ public double? Hours; public double? Kilometers; public int? Week; public int? Year;}
Then in the repository:
public IQueryable<WeekSummary> GetWeeklySummary(){ var weekSummaries = from p in db.Persons orderby p.personname let data = GetWeeklySummaryData(p.personid) select new WeekSummary {Personid = p.personid, Personname = p.personname, Persondata = new List<WeekSummaryData>(data)}; return weekSummaries;}IQueryable<WeekSummaryData> GetWeeklySummaryData(int personid){ var summary = from w in db.weekly_summaries where w.personid == personid orderby w.Year , w.Week select new WeekSummaryData {Hours = w.hours, Kilometers = w.kilometres, Week = w.Week, Year = w.Year}; return summary;}
** understand this linq
Then in the controller:
public ActionResult Index(){ var summaries = _repository.GetWeeklySummary(); return View(summaries);}
and the view:
** understand this rendering
<% foreach (WeekSummary weekSummary in Model) { %> <table> <tr> <th></th> <% foreach (WeekSummaryData weekSummaryData in weekSummary.Persondata) { %> <th><%=Html.Encode(weekSummaryData.Week) + "/" + Html.Encode(weekSummaryData.Year) %></th> <%}%> </tr> <tr> <td> <%=Html.Encode(weekSummary.Personname) %> </td> <% foreach (WeekSummaryData week in weekSummary.Persondata) { %> <td><%=Html.Encode(week.Hours) + "hrs" %><br /><%=Html.Encode(week.Kilometers) + "kms" %></td> <%}%> </tr> </table><% } %>
refactor code with an interface for testing
unit test do
automock
jquery
tooling to help make form crud websites faster…
reproting tooling
mvc2
Remember Me
a@href@title, strike