From 133163292de75f8aae54e4323a2bf59143631bf1 Mon Sep 17 00:00:00 2001 From: Thomas Hounsell Date: Tue, 28 Oct 2014 23:39:18 +0000 Subject: [PATCH] Move all URLs to lower-case, some refactoring --- App_Start/RouteConfig.cs | 24 +++---- BuildFeed.csproj | 5 +- .../BuildDateTimeModelBinder.cs | 3 - Code/DisplayHelpers.cs | 26 ++++++++ Controllers/buildController.cs | 40 ++++++------ Controllers/rssController.cs | 16 ++--- Controllers/supportController.cs | 16 ++--- Views/build/index.cshtml | 62 +++++++------------ .../DisplayTemplates/Enumeration.cshtml | 20 +----- .../shared/EditorTemplates/Enumeration.cshtml | 18 +----- Views/shared/_default.cshtml | 3 +- Views/shared/error.cshtml | 2 +- packages.config | 2 +- 13 files changed, 106 insertions(+), 131 deletions(-) rename {App_Code => Code}/BuildDateTimeModelBinder.cs (90%) create mode 100644 Code/DisplayHelpers.cs diff --git a/App_Start/RouteConfig.cs b/App_Start/RouteConfig.cs index 405fae6..0207c3d 100644 --- a/App_Start/RouteConfig.cs +++ b/App_Start/RouteConfig.cs @@ -19,61 +19,61 @@ public static void RegisterRoutes(RouteCollection routes) routes.MapRoute( name: "Site Root", url: "", - defaults: new { controller = "Build", action = "Index", page = 1 } + defaults: new { controller = "Build", action = "index", page = 1 } ); routes.MapRoute( name: "Pagination", url: "page/{page}/", - defaults: new { controller = "Build", action = "Index", page = 1 } + defaults: new { controller = "Build", action = "index", page = 1 } ); routes.MapRoute( name: "Lab Root", url: "lab/{lab}/", - defaults: new { controller = "Build", action = "Lab", page = 1 } + defaults: new { controller = "Build", action = "lab", page = 1 } ); routes.MapRoute( name: "Lab", url: "lab/{lab}/page/{page}/", - defaults: new { controller = "Build", action = "Lab", page = 1 } + defaults: new { controller = "Build", action = "lab", page = 1 } ); routes.MapRoute( name: "Version Root", url: "version/{major}.{minor}/", - defaults: new { controller = "Build", action = "Version", page = 1 } + defaults: new { controller = "Build", action = "version", page = 1 } ); routes.MapRoute( name: "Version", url: "version/{major}.{minor}/page/{page}/", - defaults: new { controller = "Build", action = "Version", page = 1 } + defaults: new { controller = "Build", action = "version", page = 1 } ); routes.MapRoute( name: "Year Root", url: "year/{year}/", - defaults: new { controller = "Build", action = "Year", page = 1 } + defaults: new { controller = "Build", action = "year", page = 1 } ); routes.MapRoute( name: "Year", url: "year/{year}/{page}/", - defaults: new { controller = "Build", action = "Year", page = 1 } + defaults: new { controller = "Build", action = "year", page = 1 } ); routes.MapRoute( name: "Source Root", url: "source/{source}/", - defaults: new { controller = "Build", action = "Source", page = 1 } + defaults: new { controller = "Build", action = "source", page = 1 } ); routes.MapRoute( name: "Source", url: "source/{source}/{page}/", - defaults: new { controller = "Build", action = "Source", page = 1 } + defaults: new { controller = "Build", action = "source", page = 1 } ); routes.MapRoute( @@ -91,7 +91,7 @@ public static void RegisterRoutes(RouteCollection routes) routes.MapRoute( name: "Support", url: "support/{action}/", - defaults: new { controller = "Support", action = "Index" } + defaults: new { controller = "Support", action = "index" } ); routes.MapHttpRoute( @@ -103,7 +103,7 @@ public static void RegisterRoutes(RouteCollection routes) routes.MapRoute( name: "Actions", url: "actions/{action}/{id}", - defaults: new { controller = "Build", action = "Index", id = UrlParameter.Optional } + defaults: new { controller = "Build", action = "index", id = UrlParameter.Optional } ); } } diff --git a/BuildFeed.csproj b/BuildFeed.csproj index 394b67d..9990f53 100644 --- a/BuildFeed.csproj +++ b/BuildFeed.csproj @@ -54,7 +54,7 @@ False - ..\packages\Newtonsoft.Json.6.0.5\lib\net45\Newtonsoft.Json.dll + ..\packages\Newtonsoft.Json.6.0.6\lib\net45\Newtonsoft.Json.dll False @@ -145,7 +145,8 @@ - + + diff --git a/App_Code/BuildDateTimeModelBinder.cs b/Code/BuildDateTimeModelBinder.cs similarity index 90% rename from App_Code/BuildDateTimeModelBinder.cs rename to Code/BuildDateTimeModelBinder.cs index 0a17514..0baa2cf 100644 --- a/App_Code/BuildDateTimeModelBinder.cs +++ b/Code/BuildDateTimeModelBinder.cs @@ -1,8 +1,5 @@ using System; -using System.Collections.Generic; using System.Globalization; -using System.Linq; -using System.Text; using System.Web.Mvc; namespace BuildFeed diff --git a/Code/DisplayHelpers.cs b/Code/DisplayHelpers.cs new file mode 100644 index 0000000..04c8066 --- /dev/null +++ b/Code/DisplayHelpers.cs @@ -0,0 +1,26 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.Linq; + +namespace BuildFeed +{ + public static class DisplayHelpers + { + public static string GetDisplayTextForEnum(object o) + { + var result = null as string; + var display = o.GetType() + .GetMember(o.ToString()).First() + .GetCustomAttributes(false) + .OfType() + .LastOrDefault(); + + if (display != null) + { + result = display.GetName(); + } + + return result ?? o.ToString(); + } + } +} \ No newline at end of file diff --git a/Controllers/buildController.cs b/Controllers/buildController.cs index 4e5c2ba..e248445 100644 --- a/Controllers/buildController.cs +++ b/Controllers/buildController.cs @@ -10,11 +10,11 @@ namespace BuildFeed.Controllers { public class buildController : Controller { - public int pageSize { get { return 12; } } + public int pageSize { get { return 15; } } // // GET: /build/ - public ActionResult Index(int page = 1) + public ActionResult index(int page = 1) { var builds = Build.SelectInBuildOrder(); var pageBuilds = builds.Skip((page - 1) * pageSize).Take(pageSize); @@ -25,7 +25,7 @@ public ActionResult Index(int page = 1) return View(pageBuilds); } - public ActionResult Year(int year, int page = 1) + public ActionResult year(int year, int page = 1) { var builds = Build.SelectInBuildOrder().Where(b => b.BuildTime.HasValue && b.BuildTime.Value.Year == year); var pageBuilds = builds.Skip((page - 1) * pageSize).Take(pageSize); @@ -33,10 +33,10 @@ public ActionResult Year(int year, int page = 1) ViewBag.PageNumber = page; ViewBag.PageCount = Math.Ceiling(Convert.ToDouble(builds.Count()) / Convert.ToDouble(pageSize)); - return View("Index", pageBuilds); + return View("index", pageBuilds); } - public ActionResult Lab(string lab, int page = 1) + public ActionResult lab(string lab, int page = 1) { var builds = Build.SelectInBuildOrder().Where(b => b.Lab != null && (b.Lab.ToLower() == lab.ToLower())); var pageBuilds = builds.Skip((page - 1) * pageSize).Take(pageSize); @@ -44,10 +44,10 @@ public ActionResult Lab(string lab, int page = 1) ViewBag.PageNumber = page; ViewBag.PageCount = Math.Ceiling(Convert.ToDouble(builds.Count()) / Convert.ToDouble(pageSize)); - return View("Index", pageBuilds); + return View("index", pageBuilds); } - public ActionResult Version(int major, int minor, int page = 1) + public ActionResult version(int major, int minor, int page = 1) { var builds = Build.SelectInBuildOrder().Where(b => b.MajorVersion == major && b.MinorVersion == minor); var pageBuilds = builds.Skip((page - 1) * pageSize).Take(pageSize); @@ -55,10 +55,10 @@ public ActionResult Version(int major, int minor, int page = 1) ViewBag.PageNumber = page; ViewBag.PageCount = Math.Ceiling(Convert.ToDouble(builds.Count()) / Convert.ToDouble(pageSize)); - return View("Index", pageBuilds); + return View("index", pageBuilds); } - public ActionResult Source(TypeOfSource source, int page = 1) + public ActionResult source(TypeOfSource source, int page = 1) { var builds = Build.SelectInBuildOrder().Where(b => b.SourceType == source); var pageBuilds = builds.Skip((page - 1) * pageSize).Take(pageSize); @@ -66,13 +66,13 @@ public ActionResult Source(TypeOfSource source, int page = 1) ViewBag.PageNumber = page; ViewBag.PageCount = Math.Ceiling(Convert.ToDouble(builds.Count()) / Convert.ToDouble(pageSize)); - return View("Index", pageBuilds); + return View("index", pageBuilds); } // // GET: /build/Info/5 - public ActionResult Info(int id) + public ActionResult info(int id) { Build b = Build.SelectById(id); @@ -87,7 +87,7 @@ public ActionResult Info(int id) // // GET: /build/Create [Authorize] - public ActionResult Create() + public ActionResult create() { return View(); } @@ -96,7 +96,7 @@ public ActionResult Create() // POST: /build/Create [Authorize] [HttpPost] - public ActionResult Create(Build build) + public ActionResult create(Build build) { if (ModelState.IsValid) { @@ -109,7 +109,7 @@ public ActionResult Create(Build build) { return View(build); } - return RedirectToAction("Index"); + return RedirectToAction("index"); } else { @@ -120,17 +120,17 @@ public ActionResult Create(Build build) // // GET: /build/Edit/5 [Authorize] - public ActionResult Edit(long id) + public ActionResult edit(long id) { Build b = Build.SelectById(id); - return View("Create", b); + return View("create", b); } // // POST: /build/Edit/5 [Authorize] [HttpPost] - public ActionResult Edit(long id, Build build) + public ActionResult edit(long id, Build build) { if (ModelState.IsValid) { @@ -143,16 +143,16 @@ public ActionResult Edit(long id, Build build) return View(); } - return RedirectToAction("Index"); + return RedirectToAction("index"); } else { - return View("Create", build); + return View("create", build); } } [Authorize(Users = "hounsell")] - public ActionResult Delete(long id) + public ActionResult delete(long id) { Build.DeleteById(id); return Redirect("/"); diff --git a/Controllers/rssController.cs b/Controllers/rssController.cs index f0b5a8a..b500d44 100644 --- a/Controllers/rssController.cs +++ b/Controllers/rssController.cs @@ -36,8 +36,8 @@ public async Task index() select new RssItem() { Title = build.FullBuildString, - Link = new RssUrl(string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Action("Info", new { controller = "Build", id = build.Id }))), - Guid = new RssGuid() { IsPermaLink = true, Value = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Action("Info", new { controller = "Build", id = build.Id })) }, + Link = new RssUrl(string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Action("info", new { controller = "Build", id = build.Id }))), + Guid = new RssGuid() { IsPermaLink = true, Value = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Action("info", new { controller = "Build", id = build.Id })) }, }).ToList() } }; @@ -68,8 +68,8 @@ public async Task added() select new RssItem() { Title = build.FullBuildString, - Link = new RssUrl(string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Action("Info", new { controller = "Build", id = build.Id }))), - Guid = new RssGuid() { IsPermaLink = true, Value = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Action("Info", new { controller = "Build", id = build.Id })) }, + Link = new RssUrl(string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Action("info", new { controller = "Build", id = build.Id }))), + Guid = new RssGuid() { IsPermaLink = true, Value = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Action("info", new { controller = "Build", id = build.Id })) }, PubDate = build.Added }).ToList() } @@ -109,8 +109,8 @@ public async Task version() select new RssItem() { Title = build.FullBuildString, - Link = new RssUrl(string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Action("Info", new { controller = "Build", id = build.Id }))), - Guid = new RssGuid() { IsPermaLink = true, Value = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Action("Info", new { controller = "Build", id = build.Id })) }, + Link = new RssUrl(string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Action("info", new { controller = "Build", id = build.Id }))), + Guid = new RssGuid() { IsPermaLink = true, Value = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Action("info", new { controller = "Build", id = build.Id })) }, }).ToList() } }; @@ -145,8 +145,8 @@ public async Task flight(LevelOfFlight id) select new RssItem() { Title = build.FullBuildString, - Link = new RssUrl(string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Action("Info", new { controller = "Build", id = build.Id }))), - Guid = new RssGuid() { IsPermaLink = true, Value = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Action("Info", new { controller = "Build", id = build.Id })) }, + Link = new RssUrl(string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Action("info", new { controller = "Build", id = build.Id }))), + Guid = new RssGuid() { IsPermaLink = true, Value = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Action("info", new { controller = "Build", id = build.Id })) }, }).ToList() } }; diff --git a/Controllers/supportController.cs b/Controllers/supportController.cs index 7714308..5253517 100644 --- a/Controllers/supportController.cs +++ b/Controllers/supportController.cs @@ -11,18 +11,18 @@ namespace BuildFeed.Controllers public class supportController : Controller { // GET: support - public ActionResult Index() + public ActionResult index() { return View(); } - public ActionResult Login() + public ActionResult login() { return View(); } [HttpPost] - public ActionResult Login(LoginUser ru) + public ActionResult login(LoginUser ru) { if (ModelState.IsValid) { @@ -43,13 +43,13 @@ public ActionResult Login(LoginUser ru) } [Authorize] - public ActionResult Password() + public ActionResult password() { return View(); } [HttpPost] - public ActionResult Password(ChangePassword cp) + public ActionResult password(ChangePassword cp) { if (ModelState.IsValid) { @@ -66,19 +66,19 @@ public ActionResult Password(ChangePassword cp) return View(cp); } - public ActionResult Logout() + public ActionResult logout() { FormsAuthentication.SignOut(); return Redirect("/"); } - public ActionResult Register() + public ActionResult register() { return View(); } [HttpPost] - public ActionResult Register(RegistrationUser ru) + public ActionResult register(RegistrationUser ru) { if (ModelState.IsValid) { diff --git a/Views/build/index.cshtml b/Views/build/index.cshtml index ee1e30a..956cead 100644 --- a/Views/build/index.cshtml +++ b/Views/build/index.cshtml @@ -1,23 +1,7 @@ @model IEnumerable @{ - Func GetDisplayName = o => - { - var result = null as string; - var display = o.GetType() - .GetMember(o.ToString()).First() - .GetCustomAttributes(false) - .OfType() - .LastOrDefault(); - if (display != null) - { - result = display.GetName(); - } - - return result ?? o.ToString(); - }; - - ViewBag.Action = ViewContext.Controller.ValueProvider.GetValue("action").RawValue.ToString(); + ViewBag.Action = ViewContext.Controller.ValueProvider.GetValue("action").RawValue.ToString().ToLower(); ViewBag.Title = "BuildFeed"; @@ -28,23 +12,23 @@ switch (ViewBag.Action as string) { - case "Index": + case "index": ViewBag.Title = "BuildFeed | The collaborative build list"; break; - case "Lab": + case "lab": ViewBag.ItemId = ViewContext.Controller.ValueProvider.GetValue("lab").RawValue; ViewBag.Title = string.Format("Builds from {1} | {0}", ViewBag.Title, ViewBag.ItemId); break; - case "Year": + case "year": ViewBag.ItemId = ViewContext.Controller.ValueProvider.GetValue("year").RawValue; ViewBag.Title = string.Format("Builds from {1} | {0}", ViewBag.Title, ViewBag.ItemId); break; - case "Version": + case "version": ViewBag.ItemId = string.Format("{0}.{1}", ViewContext.Controller.ValueProvider.GetValue("major").RawValue, ViewContext.Controller.ValueProvider.GetValue("minor").RawValue); ViewBag.Title = string.Format("Windows NT {1} | {0}", ViewBag.Title, ViewBag.ItemId); break; - case "Source": - ViewBag.ItemId = GetDisplayName(Enum.Parse(typeof(BuildFeed.Models.TypeOfSource), ViewContext.Controller.ValueProvider.GetValue("source").RawValue.ToString())); + case "source": + ViewBag.ItemId = DisplayHelpers.GetDisplayTextForEnum(Enum.Parse(typeof(BuildFeed.Models.TypeOfSource), ViewContext.Controller.ValueProvider.GetValue("source").RawValue.ToString())); ViewBag.Title = string.Format("{1} | {0}", ViewBag.Title, ViewBag.ItemId); break; } @@ -54,15 +38,15 @@ { @switch (ViewBag.Action as string) { - case "Index": + case "index": break; - case "Lab": + case "lab": break; - case "Year": + case "year": break; @@ -76,14 +60,14 @@ {
  • - @Html.ActionLink("Info", "Info", new { id = item.Id }, new { @class = "btn btn-info btn-xs" }) + @Html.ActionLink("Info", "info", new { id = item.Id }, new { @class = "btn btn-info btn-xs" }) @if (User.Identity.IsAuthenticated) { - @Html.ActionLink("Edit", "Edit", new { id = item.Id }, new { @class = "btn btn-default btn-xs" }) + @Html.ActionLink("Edit", "edit", new { id = item.Id }, new { @class = "btn btn-default btn-xs" }) } @if (User.Identity.Name == "hounsell") { - @Html.ActionLink("Delete", "Delete", new { id = item.Id }, new { @class = "btn btn-danger btn-xs" }) + @Html.ActionLink("Delete", "delete", new { id = item.Id }, new { @class = "btn btn-danger btn-xs" }) }

    @Html.DisplayFor(modelItem => item.FullBuildString)

    @@ -131,7 +115,7 @@
    @@ -150,7 +134,7 @@ @@ -170,7 +154,7 @@ @@ -190,7 +174,7 @@ @@ -210,7 +194,7 @@ @@ -230,15 +214,15 @@ diff --git a/Views/shared/DisplayTemplates/Enumeration.cshtml b/Views/shared/DisplayTemplates/Enumeration.cshtml index 4cd3a99..e52d573 100644 --- a/Views/shared/DisplayTemplates/Enumeration.cshtml +++ b/Views/shared/DisplayTemplates/Enumeration.cshtml @@ -2,22 +2,4 @@ @model Enum -@{ - Func GetDisplayName = o => - { - var result = null as string; - var display = o.GetType() - .GetMember(o.ToString()).First() - .GetCustomAttributes(false) - .OfType() - .LastOrDefault(); - if (display != null) - { - result = display.GetName(); - } - - return result ?? o.ToString(); - }; -} - -@GetDisplayName(ViewData.Model) +@DisplayHelpers.GetDisplayTextForEnum(ViewData.Model) diff --git a/Views/shared/EditorTemplates/Enumeration.cshtml b/Views/shared/EditorTemplates/Enumeration.cshtml index 71befea..1698aa8 100644 --- a/Views/shared/EditorTemplates/Enumeration.cshtml +++ b/Views/shared/EditorTemplates/Enumeration.cshtml @@ -3,27 +3,11 @@ @model Enum @{ - Func GetDisplayName = o => - { - var result = null as string; - var display = o.GetType() - .GetMember(o.ToString()).First() - .GetCustomAttributes(false) - .OfType() - .LastOrDefault(); - if (display != null) - { - result = display.GetName(); - } - - return result ?? o.ToString(); - }; - var values = Enum.GetValues(ViewData.ModelMetadata.ModelType).Cast() .Select(v => new SelectListItem { Selected = v.Equals(Model), - Text = GetDisplayName(v), + Text = DisplayHelpers.GetDisplayTextForEnum(v), Value = v.ToString() }); } diff --git a/Views/shared/_default.cshtml b/Views/shared/_default.cshtml index 5d46d28..8fa40db 100644 --- a/Views/shared/_default.cshtml +++ b/Views/shared/_default.cshtml @@ -8,6 +8,7 @@ + @Styles.Render("~/content/css") @@ -32,7 +33,7 @@