{ + protected override FuncHandleInteger(int value) { + return quote => quote.Game.Id == value; + } + } + #endregion } public class QuoteDto { diff --git a/Src/VideoGameQuotes.Web/Controllers/ApiController.cs b/Src/VideoGameQuotes.Web/Controllers/ApiController.cs index 3ac35d4..cc5a1ac 100644 --- a/Src/VideoGameQuotes.Web/Controllers/ApiController.cs +++ b/Src/VideoGameQuotes.Web/Controllers/ApiController.cs @@ -30,7 +30,9 @@ namespace VideoGameQuotes.Web.Controllers { private readonly IDictionary> categoryHandlers = new Dictionary >(); private readonly IDictionary > systemHandlers = new Dictionary >(); private readonly IDictionary > publisherHandlers = new Dictionary >(); - private readonly IDictionary > quoteHandlers = new Dictionary >(); + private readonly IDictionary > quoteHandlers = new Dictionary > { + { "game", new Quote.GameCriterionHandler() } + }; private readonly IDictionary > gameHandlers = new Dictionary > { { "system", new Game.SystemCriterionHandler() }, { "publisher", new Game.PublisherCriterionHandler() } diff --git a/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs b/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs index b5b2f15..0afc67b 100644 --- a/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs +++ b/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs @@ -23,26 +23,11 @@ namespace VideoGameQuotes.Web.Controllers { } public ActionResult Browse(BrowseModel model) { - var viewModel = new BrowseViewModel(); - - if (model.GameIds.Any()) { - viewModel.Games = model.GameIds.Select(id => quoteService.GetGame(id)); - } - if (model.SystemIds.Any()) { - viewModel.Systems = model.SystemIds.Select(id => quoteService.GetSystem(id)); - } - if (model.PublisherIds.Any()) { - viewModel.Publishers = model.PublisherIds.Select(id => quoteService.GetPublisher(id)); - } - if (model.CategoryIds.Any()) { - viewModel.Categories = model.CategoryIds.Select(id => quoteService.GetCategory(id)); - } - - if (!viewModel.Games.Any() && !viewModel.Systems.Any() && !viewModel.Categories.Any() && !viewModel.Publishers.Any()) { + if (model.IsEmpty) { return View("DefaultBrowse"); } - return View("QualifiedBrowse", viewModel); + return View("QualifiedBrowse", new QualifiedBrowseModel(model) { Quotes = quoteService.GetBrowsableQuotes(model) }); } [HttpPost, IsValidUser] diff --git a/Src/VideoGameQuotes.Web/Global.asax.cs b/Src/VideoGameQuotes.Web/Global.asax.cs index dfff90b..4a9362b 100644 --- a/Src/VideoGameQuotes.Web/Global.asax.cs +++ b/Src/VideoGameQuotes.Web/Global.asax.cs @@ -44,7 +44,7 @@ namespace VideoGameQuotes.Web { routes.IgnoreRoute("media/{*anything}"); - routes.MapRoute("api", "api/{action}/{id}/{*criteria}", new { controller = "Api" }, new { action = "game", id = @"\d+|all" }); + 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" }); @@ -53,8 +53,6 @@ namespace VideoGameQuotes.Web { routes.MapRoute("quote", "{action}", new { controller = "Quote" }, new { action = "submit|search|recent|random|best|vote|report" }); routes.MapRoute("individual-quote", "quote/{id}/{*text}", new { controller = "Quote", action = "Quote" }, new { id = @"\d+" }); routes.MapRoute("create-category", "category/create", new { controller = "Quote", action = "CreateCategory" }); - - routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional }); } } } \ No newline at end of file diff --git a/Src/VideoGameQuotes.Web/Models/ApiModel.cs b/Src/VideoGameQuotes.Web/Models/ApiModel.cs index 0dc7bd6..6850af9 100644 --- a/Src/VideoGameQuotes.Web/Models/ApiModel.cs +++ b/Src/VideoGameQuotes.Web/Models/ApiModel.cs @@ -35,17 +35,14 @@ namespace VideoGameQuotes.Web.Models { for (var i = 0; i < criteria.Length; i++) { switch (criteria[i]) { - case "system": + default: if (i < criteria.Length - 1) { - model.Criteria["system"] = ParseCommaSeparatedCriterion(criteria[i + 1]); + model.Criteria[criteria[i]] = ParseCommaSeparatedCriterion(criteria[i + 1]); i++; } else { controllerContext.AddModelError("criteria", "Unable to parse criteria for key \"system\""); } - break; - default: - controllerContext.AddModelError("criteria", string.Format("Unable to parse criteria for key \"{0}\"", criteria[i])); break; } } @@ -54,14 +51,17 @@ namespace VideoGameQuotes.Web.Models { private static IEnumerable