* fixed some type constraint issues, and fixed all action links to use capitalization

* incorporated SmartCaseRoute into the route table
This commit is contained in:
tmont 2011-03-02 20:18:33 +00:00
parent c37b948735
commit 62f0fadbae
22 changed files with 77 additions and 71 deletions

View File

@ -33,10 +33,10 @@ namespace VideoGameQuotes.Web.Configuration {
.RegisterInstance(Version.LUCENE_29)
.RegisterType<Analyzer, StandardAnalyzer>(new InjectionConstructor(typeof(Version)))
.RegisterType<QueryParser>(new InjectionFactory(CreateQueryParser))
.RegisterAndIntercept(typeof(ISearcher<>), typeof(LuceneEntitySearcher<>))
.RegisterAndIntercept(typeof(ISearchService<>), typeof(SearchService<>))
.RegisterAndIntercept(typeof(ISearcher<,>), typeof(LuceneEntitySearcher<,>))
.RegisterAndIntercept(typeof(ISearchService<,>), typeof(SearchService<,>))
.RegisterAndIntercept<ILuceneDocumentHandler<Quote>, QuoteDocumentHandler>()
.RegisterAndIntercept(typeof(ISearchIndexBuilder<>), typeof(LuceneEntityIndexBuilder<>));
.RegisterAndIntercept(typeof(ISearchIndexBuilder<,>), typeof(LuceneEntityIndexBuilder<,>));
Container
.Configure<Interception>()

View File

@ -31,7 +31,7 @@ namespace VideoGameQuotes.Web.Configuration {
return returnValue;
}
container.Resolve<ISearchIndexBuilder<Quote>>().UpdateIndex(quote);
container.Resolve<ISearchIndexBuilder<Quote, int>>().UpdateIndex(quote);
return returnValue;
}

View File

@ -91,7 +91,7 @@ namespace VideoGameQuotes.Web.Controllers {
records = new[] { repository.FindById(model.Id) };
}
return records.ToArray().Select(entity => entity.ToDto<T, int, TDto>());
return records.ToArray().Select(entity => entity.ToDto<TDto>());
}
[UnitOfWork]

View File

@ -21,9 +21,9 @@ namespace VideoGameQuotes.Web.Controllers {
public class QuoteController : Controller {
private readonly IQuoteService quoteService;
private readonly ICurrentUserProvider<User> currentUserProvider;
private readonly ISearcher<Quote> quoteSearcher;
private readonly ISearcher<Quote, int> quoteSearcher;
public QuoteController(IQuoteService quoteService, ICurrentUserProvider<User> currentUserProvider, ISearcher<Quote> quoteSearcher) {
public QuoteController(IQuoteService quoteService, ICurrentUserProvider<User> currentUserProvider, ISearcher<Quote, int> quoteSearcher) {
this.quoteService = quoteService;
this.currentUserProvider = currentUserProvider;
this.quoteSearcher = quoteSearcher;

View File

@ -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<ISearchIndexBuilder<Quote>>().BuildIndex();
Container.Resolve<ISearchIndexBuilder<Quote, int>>().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" });
}
}
}

View File

@ -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<T> : ISearchService<T> where T : Entity<T, int> {
private readonly IRepository<T> repository;
public class SearchService<T, TId> : ISearchService<T, TId> where T : IIdentifiable<TId> {
private readonly IRepository<T, TId> repository;
public SearchService(IRepository<T> repository) {
public SearchService(IRepository<T, TId> repository) {
this.repository = repository;
}
[UnitOfWork]
public IEnumerable<T> FindByIds(IEnumerable<int> ids) {
public IEnumerable<T> FindByIds(IEnumerable<TId> ids) {
return repository
.Records
.Where(entity => ids.ToArray().Contains(entity.Id));
@ -22,5 +23,9 @@ namespace VideoGameQuotes.Web.Search {
public IEnumerable<T> GetAllIndexableRecords() {
return repository.Records;
}
public TId ConvertIdFromStringValue(string idValue) {
return (TId)Convert.ChangeType(idValue, typeof(TId));
}
}
}

View File

@ -53,6 +53,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Lib\Microsoft.Practices.Unity.Interception.dll</HintPath>
</Reference>
<Reference Include="MySql.Data, Version=6.3.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Lib\MySql.Data.dll</HintPath>
</Reference>
<Reference Include="NHibernate.ByteCode.LinFu, Version=3.0.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Lib\NHibernate.ByteCode.LinFu.dll</HintPath>
@ -204,7 +208,7 @@
<Content Include="Views\Home\Contact.aspx" />
<Content Include="Views\Home\ContactSuccess.aspx" />
<Content Include="Views\Shared\CaptchaJavaScript.ascx" />
<Content Include="Views\Quote\PagingMenu.ascx" />
<Content Include="Views\Shared\PagingMenu.ascx" />
<Content Include="Views\Quote\QuoteFormJavaScript.ascx" />
<Content Include="Views\Quote\QuoteOfTheDay.ascx" />
<Content Include="Views\Shared\BadPaging.aspx" />

View File

@ -3,7 +3,7 @@
<asp:Content runat="server" ID="Main" ContentPlaceHolderID="MainContent">
<h2>Success</h2>
<p>
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.
</p>
</asp:Content>

View File

@ -5,6 +5,6 @@
<span class="flag-count"><%: Model.Flags.Count() %></span>
<p>
<%= 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) %>
</p>
</div>

View File

@ -4,9 +4,9 @@
<h2>Site Administration</h2>
<ul>
<li><%= Html.ActionLink("Create admin", "create", "admin") %></li>
<li><%= Html.ActionLink("Change password", "password", "admin") %></li>
<li><%= Html.ActionLink("View quote flags", "flags", "admin") %></li>
<li><%= Html.ActionLink("Manage users", "users", "admin") %></li>
<li><%= Html.ActionLink("Create admin", "Create", "Admin") %></li>
<li><%= Html.ActionLink("Change password", "Password", "Admin") %></li>
<li><%= Html.ActionLink("View quote flags", "Flags", "Admin") %></li>
<li><%= Html.ActionLink("Manage users", "Users", "Admin") %></li>
</ul>
</asp:Content>

View File

@ -6,6 +6,6 @@
</p>
<p>
<%= Html.ActionLink("Administer more stuff", "index", "admin") %>
<%= Html.ActionLink("Administer more stuff", "Index", "Admin") %>
</p>
</asp:Content>

View File

@ -16,9 +16,9 @@
<% if (Model.CurrentUser.Group == UserGroup.Admin) { %>
<div class="user-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)%>
</div>
<% } %>

View File

@ -1,15 +1,11 @@
<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<VideoGameQuotes.Web.Models.PagedModelWithUser<VideoGameQuotes.Api.User>>" MasterPageFile="~/Views/Shared/Site.Master" %>
<%@ Import Namespace="Portoa.Web.Models" %>
<%@ Import Namespace="VideoGameQuotes.Web.Models" %>
<asp:Content runat="server" ID="Title" ContentPlaceHolderID="TitleContent">Manage Users</asp:Content>
<asp:Content runat="server" ID="Main" ContentPlaceHolderID="MainContent">
<h2>Users</h2>
<p>
<% 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 }) %>
</p>
<% Html.RenderPartial("PagingMenu", new PagingMenuModel(Model) { Action = "Users", Controller = "Admin" }); %>
<%
foreach (var user in Model.Records) {

View File

@ -5,8 +5,8 @@
<h2>Welcome</h2>
<p>
Welcome to <strong>Video Game Quotes</strong>. You can <%= Html.ActionLink("browse", "browse", "quote") %>,
<%= Html.ActionLink("rate", "best", "quote") %> and <%= Html.ActionLink("submit", "submit", "quote") %>
Welcome to <strong>Video Game Quotes</strong>. 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.
</p>
@ -21,7 +21,7 @@
<p>
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&rsquo;t hesitate to contact him (i.e. me) using the
<%= Html.ActionLink("contact", "contact", "home") %> form.
<%= Html.ActionLink("contact", "Contact", "Home") %> form.
</p>
<p>

View File

@ -4,7 +4,7 @@
<asp:Content runat="server" ID="Title" ContentPlaceHolderID="TitleContent">Best</asp:Content>
<asp:Content runat="server" ID="Main" ContentPlaceHolderID="MainContent">
<% 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) {

View File

@ -12,7 +12,7 @@
</div>
<div class="quote-text">
<a href="<%= Url.Action("quote", "quote", new { id = Model.Id, text = Model.GetUrlFriendlyText() }) %>">
<a href="<%= Url.Action("Quote", "Quote", new { id = Model.Id, text = Model.GetUrlFriendlyText() }) %>">
<%= Model.FormatTextForHtml() %>
</a>
</div>

View File

@ -3,7 +3,7 @@
<%@ Import Namespace="VideoGameQuotes.Web.Models" %>
<asp:Content runat="server" ID="Title" ContentPlaceHolderID="TitleContent">Recent: <%= Model.Start %>&ndash;<%= Model.End %></asp:Content>
<asp:Content runat="server" ID="Main" ContentPlaceHolderID="MainContent">
<% 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) {

View File

@ -1,13 +1,13 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<VideoGameQuotes.Web.Models.MainMenuModel>" %>
<%@ Import Namespace="VideoGameQuotes.Api" %>
<li><%= Html.ActionLink("Recent", "recent", "Quote", null, new { title = "View most recently submitted quotes" })%></li>
<li><%= Html.ActionLink("Best", "best", "quote", null, new { title = "View the top rated quotes" })%></li>
<li><%= Html.ActionLink("Browse", "browse", "Quote", new { qualifiers = "" }, new { title = "Browse the quote database" })%></li>
<li><%= Html.ActionLink("Random", "random", "Quote", null, new { title = "View a random quote" })%></li>
<li><%= Html.ActionLink("Submit", "submit", "Quote", null, new { title = "Submit a new quote" }) %></li>
<li><%= Html.ActionLink("Recent", "Recent", "Quote", null, new { title = "View most recently submitted quotes" })%></li>
<li><%= Html.ActionLink("Best", "Best", "Quote", null, new { title = "View the top rated quotes" })%></li>
<li><%= Html.ActionLink("Browse", "Browse", "Quote", new { qualifiers = "" }, new { title = "Browse the quote database" })%></li>
<li><%= Html.ActionLink("Random", "Random", "Quote", null, new { title = "View a random quote" })%></li>
<li><%= Html.ActionLink("Submit", "Submit", "Quote", null, new { title = "Submit a new quote" }) %></li>
<% if (Model.User != null && Model.User.Group >= UserGroup.Admin) { %>
<li><%= Html.ActionLink("Admin", "index", "admin", null, new { title = "Perform administrative tasks" }) %></li>
<li><%= Html.ActionLink("Admin", "Index", "Admin", null, new { title = "Perform administrative tasks" }) %></li>
<% } %>
<li class="searchbox">
<%= Html.TextBox("searchQuery", null, new { id = "search-query" })%>

View File

@ -23,15 +23,15 @@
<p class="quote-details-created">
<span title="<%: Model.Quote.Created %>">added <%: Model.Quote.GetHumanReadableTimeSinceCreated() %></span>
<% if (Model.User != null && Model.User.Group >= UserGroup.Admin) { %>
by <%= Html.ActionLink(Model.Quote.Creator.GetUsernameOrIp(), "edit", "user", new { usernameOrIp = Model.Quote.Creator.GetUsernameOrIp()}, null) %>
by <%= Html.ActionLink(Model.Quote.Creator.GetUsernameOrIp(), "Edit", "User", new { usernameOrIp = Model.Quote.Creator.GetUsernameOrIp()}, null) %>
<% } %>
</p>
<p class="quote-links">
<a class="quote-flag-icon" href="#" title="flag this quote as inaccurate, fake, spam, duplicate, etc."></a>
<a class="quote-permalink" href="<%= Url.Action("quote", "quote", new { id = Model.Quote.Id, text = Model.Quote.GetUrlFriendlyText() }) %>" title="permanent link to this quote"></a>
<a class="quote-permalink" href="<%= Url.Action("Quote", "Quote", new { id = Model.Quote.Id, text = Model.Quote.GetUrlFriendlyText() }) %>" title="permanent link to this quote"></a>
<% if (Model.User != null && Model.User.Group >= UserGroup.Admin) { %>
<a class="edit-icon" href="<%= Url.Action("edit", "quote", new { id = Model.Quote.Id }) %>" title="edit this quote"></a>
<a class="edit-icon" href="<%= Url.Action("Edit", "Quote", new { id = Model.Quote.Id }) %>" title="edit this quote"></a>
<small>(<%= Model.Quote.FlagCount %>)</small>
<% } %>
</p>
@ -40,9 +40,9 @@
<div class="quote-categories">
<ul class="menu clearfix">
<li>
<a class="game-link" href="<%= Url.Action("browse", "quote", new { qualifiers = "game/" + Model.Quote.Game.Id }) %>" title="browse quotes from the game &quot;<%: Model.Quote.Game.Name %>&quot;">
<a class="game-link" href="<%= Url.Action("Browse", "Quote", new { qualifiers = "game/" + Model.Quote.Game.Id }) %>" title="browse quotes from the game &quot;<%: Model.Quote.Game.Name %>&quot;">
<% if (Model.Quote.Game.Icon != null) { %>
<img src="data:image/png;base64,<%= Model.Quote.Game.GetBase64EncodedIcon() %>" alt="icon" />
<img src="data:image/png;base64,<%= Model.Quote.Game.GetBase64EncodedIcon() %>" alt="" />
<% } %>
<%: Model.Quote.Game.Name %>
</a>
@ -50,9 +50,9 @@
<% foreach (var system in Model.Quote.Game.Systems.OrderBy(system => system.ReleaseDate)) { %>
<li>
<a class="system-link" href="<%= Url.Action("browse", "quote", new { qualifiers = "system/" + system.Id }) %>" title="browse quotes from the system &quot;<%: system.Name %>&quot;">
<a class="system-link" href="<%= Url.Action("Browse", "Quote", new { qualifiers = "system/" + system.Id }) %>" title="browse quotes from the system &quot;<%: system.Name %>&quot;">
<% if (system.Icon != null) { %>
<img src="data:image/png;base64,<%= system.GetBase64EncodedIcon() %>" alt="icon" />
<img src="data:image/png;base64,<%= system.GetBase64EncodedIcon() %>" alt="" />
<% } %>
<%: system.Abbreviation %>
</a>
@ -60,7 +60,7 @@
<% } %>
<% foreach (var category in Model.Quote.Categories.OrderBy(category => category.Name)) { %>
<li><%= Html.ActionLink(category.Name, "browse", "Quote", new { qualifiers = "category/" + category.Id }, new { title = string.Format("browse quotes categorized as \"{0}\"", category.Name) })%></li>
<li><%= Html.ActionLink(category.Name, "Browse", "Quote", new { qualifiers = "category/" + category.Id }, new { title = string.Format("browse quotes categorized as \"{0}\"", category.Name) })%></li>
<% } %>
</ul>
</div>

View File

@ -35,12 +35,12 @@
<div id="footer">
<p>
&copy; <%= DateTime.UtcNow.Year %> <a href="http://tommymontgomery.com/" title="Who is this man?">Tommy Montgomery</a><br />
<%= Html.ActionLink("about", "about", "home") %> |
<%= Html.ActionLink("credits", "about", "home", null, null, "credits", null, null) %> |
<%= Html.ActionLink("about", "About", "Home") %> |
<%= Html.ActionLink("credits", "About", "Home", null, null, "credits", null, null) %> |
<% if (!Request.IsAuthenticated) { %>
<a href="#" id="login-link">login</a>
<% } else { %>
<%= Html.ActionLink("logout", "logout", "home", new { redirectUrl = Request.Path }, null)%>
<%= Html.ActionLink("logout", "Logout", "Home", new { redirectUrl = Request.Path }, null)%>
<% } %>
</p>
</div>

View File

@ -12,7 +12,7 @@
<container>
<extensions>
<add type="VideoGameQuotes.Web.Configuration.EnableLogging, VideoGameQuotes.Web"/>
<!--<add type="Portoa.Web.Unity.LogAllMethodCalls, Portoa.Web"/>-->
<add type="Portoa.Web.Unity.LogAllMethodCalls, Portoa.Web"/>
<add type="VideoGameQuotes.Web.Configuration.EnableSearchWithLucene, VideoGameQuotes.Web"/>
</extensions>
</container>