From 62f0fadbae70589bcc28bc061959bbc6ba0ba57e Mon Sep 17 00:00:00 2001 From: tmont Date: Wed, 2 Mar 2011 20:18:33 +0000 Subject: [PATCH] * fixed some type constraint issues, and fixed all action links to use capitalization * incorporated SmartCaseRoute into the route table --- .../Configuration/EnableSearchWithLucene.cs | 6 +-- .../UpdateSearchIndexCallHandler.cs | 2 +- .../Controllers/ApiController.cs | 2 +- .../Controllers/QuoteController.cs | 4 +- Src/VideoGameQuotes.Web/Global.asax.cs | 37 ++++++++++--------- .../Search/SearchService.cs | 15 +++++--- .../VideoGameQuotes.Web.csproj | 6 ++- .../Views/Admin/CreateAdminSuccess.aspx | 2 +- .../Views/Admin/FlaggedQuote.ascx | 2 +- .../Views/Admin/Index.aspx | 8 ++-- .../Admin/PasswordSuccessfullyChanged.aspx | 2 +- .../Views/Admin/SingleUser.ascx | 6 +-- .../Views/Admin/Users.aspx | 8 +--- Src/VideoGameQuotes.Web/Views/Home/Index.aspx | 6 +-- Src/VideoGameQuotes.Web/Views/Quote/Best.aspx | 2 +- .../Views/Quote/QuoteOfTheDay.ascx | 2 +- .../Views/Quote/Recent.aspx | 2 +- .../Views/Shared/MainMenu.ascx | 12 +++--- .../Views/{Quote => Shared}/PagingMenu.ascx | 0 .../Views/Shared/SingleQuote.ascx | 16 ++++---- .../Views/Shared/Site.Master | 6 +-- Src/VideoGameQuotes.Web/Web.config | 2 +- 22 files changed, 77 insertions(+), 71 deletions(-) rename Src/VideoGameQuotes.Web/Views/{Quote => Shared}/PagingMenu.ascx (100%) diff --git a/Src/VideoGameQuotes.Web/Configuration/EnableSearchWithLucene.cs b/Src/VideoGameQuotes.Web/Configuration/EnableSearchWithLucene.cs index 7f8ac58..158d6c4 100644 --- a/Src/VideoGameQuotes.Web/Configuration/EnableSearchWithLucene.cs +++ b/Src/VideoGameQuotes.Web/Configuration/EnableSearchWithLucene.cs @@ -33,10 +33,10 @@ namespace VideoGameQuotes.Web.Configuration { .RegisterInstance(Version.LUCENE_29) .RegisterType(new InjectionConstructor(typeof(Version))) .RegisterType(new InjectionFactory(CreateQueryParser)) - .RegisterAndIntercept(typeof(ISearcher<>), typeof(LuceneEntitySearcher<>)) - .RegisterAndIntercept(typeof(ISearchService<>), typeof(SearchService<>)) + .RegisterAndIntercept(typeof(ISearcher<,>), typeof(LuceneEntitySearcher<,>)) + .RegisterAndIntercept(typeof(ISearchService<,>), typeof(SearchService<,>)) .RegisterAndIntercept, QuoteDocumentHandler>() - .RegisterAndIntercept(typeof(ISearchIndexBuilder<>), typeof(LuceneEntityIndexBuilder<>)); + .RegisterAndIntercept(typeof(ISearchIndexBuilder<,>), typeof(LuceneEntityIndexBuilder<,>)); Container .Configure() diff --git a/Src/VideoGameQuotes.Web/Configuration/UpdateSearchIndexCallHandler.cs b/Src/VideoGameQuotes.Web/Configuration/UpdateSearchIndexCallHandler.cs index af43d4b..0961b77 100644 --- a/Src/VideoGameQuotes.Web/Configuration/UpdateSearchIndexCallHandler.cs +++ b/Src/VideoGameQuotes.Web/Configuration/UpdateSearchIndexCallHandler.cs @@ -31,7 +31,7 @@ namespace VideoGameQuotes.Web.Configuration { return returnValue; } - container.Resolve>().UpdateIndex(quote); + container.Resolve>().UpdateIndex(quote); return returnValue; } diff --git a/Src/VideoGameQuotes.Web/Controllers/ApiController.cs b/Src/VideoGameQuotes.Web/Controllers/ApiController.cs index 48b9843..0eff449 100644 --- a/Src/VideoGameQuotes.Web/Controllers/ApiController.cs +++ b/Src/VideoGameQuotes.Web/Controllers/ApiController.cs @@ -91,7 +91,7 @@ namespace VideoGameQuotes.Web.Controllers { records = new[] { repository.FindById(model.Id) }; } - return records.ToArray().Select(entity => entity.ToDto()); + return records.ToArray().Select(entity => entity.ToDto()); } [UnitOfWork] diff --git a/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs b/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs index cc10a1a..1516c69 100644 --- a/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs +++ b/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs @@ -21,9 +21,9 @@ namespace VideoGameQuotes.Web.Controllers { public class QuoteController : Controller { private readonly IQuoteService quoteService; private readonly ICurrentUserProvider currentUserProvider; - private readonly ISearcher quoteSearcher; + private readonly ISearcher quoteSearcher; - public QuoteController(IQuoteService quoteService, ICurrentUserProvider currentUserProvider, ISearcher quoteSearcher) { + public QuoteController(IQuoteService quoteService, ICurrentUserProvider currentUserProvider, ISearcher quoteSearcher) { this.quoteService = quoteService; this.currentUserProvider = currentUserProvider; this.quoteSearcher = quoteSearcher; diff --git a/Src/VideoGameQuotes.Web/Global.asax.cs b/Src/VideoGameQuotes.Web/Global.asax.cs index 1a570e0..60dc2d5 100644 --- a/Src/VideoGameQuotes.Web/Global.asax.cs +++ b/Src/VideoGameQuotes.Web/Global.asax.cs @@ -5,6 +5,7 @@ using Microsoft.Practices.Unity; using Portoa.Search; using Portoa.Web; using Portoa.Web.Models; +using Portoa.Web.Routing; using Portoa.Web.Security; using Portoa.Web.Unity; using UnityGenerics; @@ -41,7 +42,7 @@ namespace VideoGameQuotes.Web { } protected override void AfterStartUp() { - Container.Resolve>().BuildIndex(); + Container.Resolve>().BuildIndex(); } protected override void OnApplicationEnd() { @@ -55,24 +56,24 @@ namespace VideoGameQuotes.Web { routes.MapRoute("favicon", "favicon.ico", new { controller = "Home", action = "Favicon" }); //bullshit route so that RenderAction works - routes.MapRoute("mainmenu", "home/mainmenu", new { controller = "Home", action = "MainMenu" }); - routes.MapRoute("quote-of-the-day", "quote/quoteoftheday", new { controller = "Quote", action = "QuoteOfTheDay" }); + routes.MapSmartRoute("mainmenu", "home/mainmenu", new { controller = "Home", action = "MainMenu" }); + routes.MapSmartRoute("quote-of-the-day", "quote/quoteoftheday", new { controller = "Quote", action = "QuoteOfTheDay" }); - routes.MapRoute("crud-default", "{controller}/{action}", null, new { controller = "system|publisher|game|category", action = "create|edit|delete" }); - routes.MapRoute("users-paged", "admin/users/{start}-{end}", new { controller = "Admin", action = "Users" }, new { start = @"\d+", end = @"\d+" }); - routes.MapRoute("admin", "admin/{action}", new { controller = "Admin", action = "Index" }, new { action = "users|create|flags|password" }); - routes.MapRoute("user-edit", "user/edit/{usernameOrIp}", new { controller = "User", action = "Edit", usernameOrIp = @"\w+" }); - routes.MapRoute("user-default", "user/{action}/{id}", new { controller = "User", action = "delete|ban", id = UrlParameter.Optional }); - routes.MapRoute("api", "api/{action}/{id}/{*criteria}", new { controller = "Api" }, new { action = "game|system|category|publisher|quote", id = @"\d+|all" }); - routes.MapRoute("home", "{action}", new { controller = "Home", action = "Index" }, new { action = "about|contact|login|logout" }); - routes.MapRoute("paged", "{action}/{page}", new { controller = "Quote", page = 1 }, new { action = "best|recent", page = @"\d+" }); - routes.MapRoute("browse", "browse/{*qualifiers}", new { controller = "Quote", action = "Browse" }); - routes.MapRoute("search", "search/{*searchQuery}", new { controller = "Quote", action = "Search" }); - routes.MapRoute("quote-task", "quote/{action}/{id}", new { controller = "Quote" }, new { action = "edit", id = @"\d+" }); - routes.MapRoute("quote", "{action}", new { controller = "Quote" }, new { action = "submit|recent|random|vote|flag" }); - routes.MapRoute("dismiss-flag", "dismiss-flag", new { controller = "Quote", action = "DismissFlag" }); - routes.MapRoute("individual-quote", "quote/{id}/{*text}", new { controller = "Quote", action = "Quote" }, new { id = @"\d+" }); - routes.MapRoute("default", "{controller}", new { controller = "home", action = "index" }); + routes.MapSmartRoute("crud-default", "{controller}/{action}", null, new { controller = "system|publisher|game|category", action = "create|edit|delete" }); + routes.MapSmartRoute("users-paged", "admin/users/{start}-{end}", new { controller = "Admin", action = "Users" }, new { start = @"\d+", end = @"\d+" }); + routes.MapSmartRoute("admin", "admin/{action}", new { controller = "Admin", action = "Index" }, new { action = "users|create|flags|password" }); + routes.MapSmartRoute("user-edit", "user/edit/{usernameOrIp}", new { controller = "User", action = "Edit", usernameOrIp = @"\w+" }); + routes.MapSmartRoute("user-default", "user/{action}/{id}", new { controller = "User", action = "delete|ban", id = UrlParameter.Optional }); + routes.MapSmartRoute("api", "api/{action}/{id}/{*criteria}", new { controller = "Api" }, new { action = "game|system|category|publisher|quote", id = @"\d+|all" }); + routes.MapSmartRoute("home", "{action}", new { controller = "Home", action = "Index" }, new { action = "about|contact|login|logout" }); + routes.MapSmartRoute("paged", "{action}/{page}", new { controller = "Quote", page = 1 }, new { action = "best|recent", page = @"\d+" }); + routes.MapSmartRoute("browse", "browse/{*qualifiers}", new { controller = "Quote", action = "Browse" }); + routes.MapSmartRoute("search", "search/{*searchQuery}", new { controller = "Quote", action = "Search" }); + routes.MapSmartRoute("quote-task", "quote/{action}/{id}", new { controller = "Quote" }, new { action = "edit", id = @"\d+" }); + routes.MapSmartRoute("quote", "{action}", new { controller = "Quote" }, new { action = "submit|recent|random|vote|flag" }); + routes.MapSmartRoute("dismiss-flag", "dismiss-flag", new { controller = "Quote", action = "DismissFlag" }); + routes.MapSmartRoute("individual-quote", "quote/{id}/{*text}", new { controller = "Quote", action = "Quote" }, new { id = @"\d+" }); + routes.MapSmartRoute("default", "{controller}", new { controller = "home", action = "index" }); } } } \ No newline at end of file diff --git a/Src/VideoGameQuotes.Web/Search/SearchService.cs b/Src/VideoGameQuotes.Web/Search/SearchService.cs index 9f90402..6841fa4 100644 --- a/Src/VideoGameQuotes.Web/Search/SearchService.cs +++ b/Src/VideoGameQuotes.Web/Search/SearchService.cs @@ -1,18 +1,19 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Portoa.Persistence; using Portoa.Search; namespace VideoGameQuotes.Web.Search { - public class SearchService : ISearchService where T : Entity { - private readonly IRepository repository; + public class SearchService : ISearchService where T : IIdentifiable { + private readonly IRepository repository; - public SearchService(IRepository repository) { + public SearchService(IRepository repository) { this.repository = repository; } [UnitOfWork] - public IEnumerable FindByIds(IEnumerable ids) { + public IEnumerable FindByIds(IEnumerable ids) { return repository .Records .Where(entity => ids.ToArray().Contains(entity.Id)); @@ -22,5 +23,9 @@ namespace VideoGameQuotes.Web.Search { public IEnumerable GetAllIndexableRecords() { return repository.Records; } + + public TId ConvertIdFromStringValue(string idValue) { + return (TId)Convert.ChangeType(idValue, typeof(TId)); + } } } \ No newline at end of file diff --git a/Src/VideoGameQuotes.Web/VideoGameQuotes.Web.csproj b/Src/VideoGameQuotes.Web/VideoGameQuotes.Web.csproj index 91e1bb2..17e6b51 100644 --- a/Src/VideoGameQuotes.Web/VideoGameQuotes.Web.csproj +++ b/Src/VideoGameQuotes.Web/VideoGameQuotes.Web.csproj @@ -53,6 +53,10 @@ False ..\..\Lib\Microsoft.Practices.Unity.Interception.dll + + False + ..\..\Lib\MySql.Data.dll + False ..\..\Lib\NHibernate.ByteCode.LinFu.dll @@ -204,7 +208,7 @@ - + diff --git a/Src/VideoGameQuotes.Web/Views/Admin/CreateAdminSuccess.aspx b/Src/VideoGameQuotes.Web/Views/Admin/CreateAdminSuccess.aspx index 26af07c..beae2fc 100644 --- a/Src/VideoGameQuotes.Web/Views/Admin/CreateAdminSuccess.aspx +++ b/Src/VideoGameQuotes.Web/Views/Admin/CreateAdminSuccess.aspx @@ -3,7 +3,7 @@

Success

- The user <%= Html.ActionLink(Model.Username, "user", "admin", new { id = Model.UserId }, null) %> is now + The user <%= Html.ActionLink(Model.Username, "User", "Admin", new { id = Model.UserId }, null) %> is now an admin.

diff --git a/Src/VideoGameQuotes.Web/Views/Admin/FlaggedQuote.ascx b/Src/VideoGameQuotes.Web/Views/Admin/FlaggedQuote.ascx index 74304fc..91c34c4 100644 --- a/Src/VideoGameQuotes.Web/Views/Admin/FlaggedQuote.ascx +++ b/Src/VideoGameQuotes.Web/Views/Admin/FlaggedQuote.ascx @@ -5,6 +5,6 @@ <%: Model.Flags.Count() %>

- <%= Html.ActionLink(Model.GetAbbreviatedText(), "quote", "quote", new { id = Model.Id, text = Model.GetUrlFriendlyText() }, null) %> + <%= Html.ActionLink(Model.GetAbbreviatedText(), "Quote", "Quote", new { id = Model.Id, text = Model.GetUrlFriendlyText() }, null) %>

diff --git a/Src/VideoGameQuotes.Web/Views/Admin/Index.aspx b/Src/VideoGameQuotes.Web/Views/Admin/Index.aspx index f3e32b5..9f17afc 100644 --- a/Src/VideoGameQuotes.Web/Views/Admin/Index.aspx +++ b/Src/VideoGameQuotes.Web/Views/Admin/Index.aspx @@ -4,9 +4,9 @@

Site Administration

    -
  • <%= Html.ActionLink("Create admin", "create", "admin") %>
  • -
  • <%= Html.ActionLink("Change password", "password", "admin") %>
  • -
  • <%= Html.ActionLink("View quote flags", "flags", "admin") %>
  • -
  • <%= Html.ActionLink("Manage users", "users", "admin") %>
  • +
  • <%= Html.ActionLink("Create admin", "Create", "Admin") %>
  • +
  • <%= Html.ActionLink("Change password", "Password", "Admin") %>
  • +
  • <%= Html.ActionLink("View quote flags", "Flags", "Admin") %>
  • +
  • <%= Html.ActionLink("Manage users", "Users", "Admin") %>
\ No newline at end of file diff --git a/Src/VideoGameQuotes.Web/Views/Admin/PasswordSuccessfullyChanged.aspx b/Src/VideoGameQuotes.Web/Views/Admin/PasswordSuccessfullyChanged.aspx index a6663b2..ae3e009 100644 --- a/Src/VideoGameQuotes.Web/Views/Admin/PasswordSuccessfullyChanged.aspx +++ b/Src/VideoGameQuotes.Web/Views/Admin/PasswordSuccessfullyChanged.aspx @@ -6,6 +6,6 @@

- <%= Html.ActionLink("Administer more stuff", "index", "admin") %> + <%= Html.ActionLink("Administer more stuff", "Index", "Admin") %>

diff --git a/Src/VideoGameQuotes.Web/Views/Admin/SingleUser.ascx b/Src/VideoGameQuotes.Web/Views/Admin/SingleUser.ascx index 736de40..0166d13 100644 --- a/Src/VideoGameQuotes.Web/Views/Admin/SingleUser.ascx +++ b/Src/VideoGameQuotes.Web/Views/Admin/SingleUser.ascx @@ -16,9 +16,9 @@ <% if (Model.CurrentUser.Group == UserGroup.Admin) { %>
- <%= Html.ActionLink("edit", "edit", "User", new { usernameOrIp = Model.User.Username ?? Model.User.IpAddress }, null) %> | - <%= Html.ActionLink("delete", "delete", "User", new { id = Model.User.Id }, null)%> | - <%= Html.ActionLink("ban", "ban", "User", new { id = Model.User.Id }, null)%> + <%= Html.ActionLink("edit", "Edit", "User", new { usernameOrIp = Model.User.Username ?? Model.User.IpAddress }, null) %> | + <%= Html.ActionLink("delete", "Delete", "User", new { id = Model.User.Id }, null)%> | + <%= Html.ActionLink("ban", "Ban", "User", new { id = Model.User.Id }, null)%>
<% } %> diff --git a/Src/VideoGameQuotes.Web/Views/Admin/Users.aspx b/Src/VideoGameQuotes.Web/Views/Admin/Users.aspx index 4f6351d..f59a167 100644 --- a/Src/VideoGameQuotes.Web/Views/Admin/Users.aspx +++ b/Src/VideoGameQuotes.Web/Views/Admin/Users.aspx @@ -1,15 +1,11 @@ <%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage>" MasterPageFile="~/Views/Shared/Site.Master" %> +<%@ Import Namespace="Portoa.Web.Models" %> <%@ Import Namespace="VideoGameQuotes.Web.Models" %> Manage Users

Users

-

- <% if (Model.HasPrevious) { %> - <%= Html.ActionLink("previous", "users", new { start = Model.PreviousStart, end = Model.PreviousEnd }) %> - <% } %> - <%= Html.ActionLink("next", "users", new { start = Model.NextStart, end = Model.NextEnd }) %> -

+ <% Html.RenderPartial("PagingMenu", new PagingMenuModel(Model) { Action = "Users", Controller = "Admin" }); %> <% foreach (var user in Model.Records) { diff --git a/Src/VideoGameQuotes.Web/Views/Home/Index.aspx b/Src/VideoGameQuotes.Web/Views/Home/Index.aspx index ad7ea2e..11df3c7 100644 --- a/Src/VideoGameQuotes.Web/Views/Home/Index.aspx +++ b/Src/VideoGameQuotes.Web/Views/Home/Index.aspx @@ -5,8 +5,8 @@

Welcome

- Welcome to Video Game Quotes. You can <%= Html.ActionLink("browse", "browse", "quote") %>, - <%= Html.ActionLink("rate", "best", "quote") %> and <%= Html.ActionLink("submit", "submit", "quote") %> + Welcome to Video Game Quotes. You can <%= Html.ActionLink("browse", "Browse", "Quote") %>, + <%= Html.ActionLink("rate", "Best", "Quote") %> and <%= Html.ActionLink("submit", "Submit", "Quote") %> quotes from video games. You do not need to register or login to perform any of these tasks. Participation is encouraged.

@@ -21,7 +21,7 @@

If you have ideas to make this place suck less, or if you just want to express your admiration for its creator (i.e. me), don’t hesitate to contact him (i.e. me) using the - <%= Html.ActionLink("contact", "contact", "home") %> form. + <%= Html.ActionLink("contact", "Contact", "Home") %> form.

diff --git a/Src/VideoGameQuotes.Web/Views/Quote/Best.aspx b/Src/VideoGameQuotes.Web/Views/Quote/Best.aspx index 4ced243..01cfd4f 100644 --- a/Src/VideoGameQuotes.Web/Views/Quote/Best.aspx +++ b/Src/VideoGameQuotes.Web/Views/Quote/Best.aspx @@ -4,7 +4,7 @@ Best - <% Html.RenderPartial("PagingMenu", new PagingMenuModel(Model) { Action = "best", Controller = "quote" }); %> + <% Html.RenderPartial("PagingMenu", new PagingMenuModel(Model) { Action = "Best", Controller = "Quote" }); %> <% foreach (var quote in Model.Records) { diff --git a/Src/VideoGameQuotes.Web/Views/Quote/QuoteOfTheDay.ascx b/Src/VideoGameQuotes.Web/Views/Quote/QuoteOfTheDay.ascx index fe8d24d..e97f54b 100644 --- a/Src/VideoGameQuotes.Web/Views/Quote/QuoteOfTheDay.ascx +++ b/Src/VideoGameQuotes.Web/Views/Quote/QuoteOfTheDay.ascx @@ -12,7 +12,7 @@

diff --git a/Src/VideoGameQuotes.Web/Views/Quote/Recent.aspx b/Src/VideoGameQuotes.Web/Views/Quote/Recent.aspx index 36782be..7f3214d 100644 --- a/Src/VideoGameQuotes.Web/Views/Quote/Recent.aspx +++ b/Src/VideoGameQuotes.Web/Views/Quote/Recent.aspx @@ -3,7 +3,7 @@ <%@ Import Namespace="VideoGameQuotes.Web.Models" %> Recent: <%= Model.Start %>–<%= Model.End %> - <% Html.RenderPartial("PagingMenu", new PagingMenuModel(Model) { Action = "recent", Controller = "quote" }); %> + <% Html.RenderPartial("PagingMenu", new PagingMenuModel(Model) { Action = "Recent", Controller = "Quote" }); %> <% foreach (var quote in Model.Records) { diff --git a/Src/VideoGameQuotes.Web/Views/Shared/MainMenu.ascx b/Src/VideoGameQuotes.Web/Views/Shared/MainMenu.ascx index 3f643bd..fb770c2 100644 --- a/Src/VideoGameQuotes.Web/Views/Shared/MainMenu.ascx +++ b/Src/VideoGameQuotes.Web/Views/Shared/MainMenu.ascx @@ -1,13 +1,13 @@ <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> <%@ Import Namespace="VideoGameQuotes.Api" %> -
  • <%= Html.ActionLink("Recent", "recent", "Quote", null, new { title = "View most recently submitted quotes" })%>
  • -
  • <%= Html.ActionLink("Best", "best", "quote", null, new { title = "View the top rated quotes" })%>
  • -
  • <%= Html.ActionLink("Browse", "browse", "Quote", new { qualifiers = "" }, new { title = "Browse the quote database" })%>
  • -
  • <%= Html.ActionLink("Random", "random", "Quote", null, new { title = "View a random quote" })%>
  • -
  • <%= Html.ActionLink("Submit", "submit", "Quote", null, new { title = "Submit a new quote" }) %>
  • +
  • <%= Html.ActionLink("Recent", "Recent", "Quote", null, new { title = "View most recently submitted quotes" })%>
  • +
  • <%= Html.ActionLink("Best", "Best", "Quote", null, new { title = "View the top rated quotes" })%>
  • +
  • <%= Html.ActionLink("Browse", "Browse", "Quote", new { qualifiers = "" }, new { title = "Browse the quote database" })%>
  • +
  • <%= Html.ActionLink("Random", "Random", "Quote", null, new { title = "View a random quote" })%>
  • +
  • <%= Html.ActionLink("Submit", "Submit", "Quote", null, new { title = "Submit a new quote" }) %>
  • <% if (Model.User != null && Model.User.Group >= UserGroup.Admin) { %> -
  • <%= Html.ActionLink("Admin", "index", "admin", null, new { title = "Perform administrative tasks" }) %>
  • +
  • <%= Html.ActionLink("Admin", "Index", "Admin", null, new { title = "Perform administrative tasks" }) %>
  • <% } %>