diff --git a/Src/VideoGameQuotes.Web/Controllers/AdminController.cs b/Src/VideoGameQuotes.Web/Controllers/AdminController.cs index fda544c..b4e35e3 100644 --- a/Src/VideoGameQuotes.Web/Controllers/AdminController.cs +++ b/Src/VideoGameQuotes.Web/Controllers/AdminController.cs @@ -132,7 +132,5 @@ namespace VideoGameQuotes.Web.Controllers { var flaggedQuotes = adminService.GetFlaggedQuotes(); return View(flaggedQuotes); } - - } } \ No newline at end of file diff --git a/Src/VideoGameQuotes.Web/Controllers/ApiController.cs b/Src/VideoGameQuotes.Web/Controllers/ApiController.cs index 0eff449..990e505 100644 --- a/Src/VideoGameQuotes.Web/Controllers/ApiController.cs +++ b/Src/VideoGameQuotes.Web/Controllers/ApiController.cs @@ -127,12 +127,8 @@ namespace VideoGameQuotes.Web.Controllers { this.apiService = apiService; } - protected new JsonResult Json(object data) { - return Json(data, JsonRequestBehavior.AllowGet); - } - private ActionResult Error(HttpStatusCode statusCode, string message = null) { - return new StatusOverrideResult(Json(this.CreateJsonErrorResponse(message ?? "Invalid request"))) { StatusCode = statusCode }; + return new StatusOverrideResult(this.SerializeToJson(this.CreateJsonErrorResponse(message ?? "Invalid request"))) { StatusCode = statusCode }; } private ActionResult GetRecords(Func> recordGetter) { @@ -141,7 +137,7 @@ namespace VideoGameQuotes.Web.Controllers { } try { - return Json(this.CreateJsonResponse(data: new { records = recordGetter(apiService) })); + return this.SerializeToJson(this.CreateJsonResponse(data: new { records = recordGetter(apiService) })); } catch (ApiException e) { return Error(HttpStatusCode.BadRequest, e.Message); } catch { diff --git a/Src/VideoGameQuotes.Web/Controllers/CategoryController.cs b/Src/VideoGameQuotes.Web/Controllers/CategoryController.cs index a1ffefd..0f936c6 100644 --- a/Src/VideoGameQuotes.Web/Controllers/CategoryController.cs +++ b/Src/VideoGameQuotes.Web/Controllers/CategoryController.cs @@ -14,8 +14,12 @@ namespace VideoGameQuotes.Web.Controllers { this.categoryService = categoryService; } + protected new ActionResult Json(object data) { + return this.SerializeToJson(data); + } + [HttpPost, VerifyUser(Group = UserGroup.Admin)] - public JsonResult Delete(int id) { + public ActionResult Delete(int id) { if (id < 1) { return Json(this.CreateJsonResponse("Invalid ID")); } @@ -37,7 +41,7 @@ namespace VideoGameQuotes.Web.Controllers { } [HttpPost, VerifyUser(Group = UserGroup.Admin)] - public JsonResult Edit(EditCategoryModel model) { + public ActionResult Edit(EditCategoryModel model) { if (model.CategoryId < 1) { ModelState.AddModelError("CategoryId", "Invalid category ID"); } @@ -62,7 +66,7 @@ namespace VideoGameQuotes.Web.Controllers { } [HttpPost, VerifyUser] - public JsonResult Create(EditCategoryModel model) { + public ActionResult Create(EditCategoryModel model) { if (!ModelState.IsValid) { return Json(this.CreateJsonErrorResponse("Some errors occurred.")); } diff --git a/Src/VideoGameQuotes.Web/Controllers/GameController.cs b/Src/VideoGameQuotes.Web/Controllers/GameController.cs index 919d6bb..8af9c45 100644 --- a/Src/VideoGameQuotes.Web/Controllers/GameController.cs +++ b/Src/VideoGameQuotes.Web/Controllers/GameController.cs @@ -20,8 +20,12 @@ namespace VideoGameQuotes.Web.Controllers { this.userProvider = userProvider; } + protected new ActionResult Json(object data) { + return this.SerializeToJson(data); + } + [HttpPost, VerifyUser(Group = UserGroup.Admin)] - public JsonResult Delete(int id) { + public ActionResult Delete(int id) { if (id < 1) { return Json(this.CreateJsonResponse("Invalid ID")); } @@ -43,7 +47,7 @@ namespace VideoGameQuotes.Web.Controllers { } [HttpPost, VerifyUser(Group = UserGroup.Admin)] - public JsonResult Edit(EditGameModel model) { + public ActionResult Edit(EditGameModel model) { if (model.GameId < 1) { ModelState.AddModelError("GameId", "Invalid game ID"); } @@ -76,7 +80,7 @@ namespace VideoGameQuotes.Web.Controllers { } [HttpPost, VerifyUser] - public JsonResult Create(EditGameModel model) { + public ActionResult Create(EditGameModel model) { byte[] icon = null; if (model.GameIcon != null) { icon = Convert.FromBase64String(model.GameIcon); diff --git a/Src/VideoGameQuotes.Web/Controllers/HomeController.cs b/Src/VideoGameQuotes.Web/Controllers/HomeController.cs index 96a2a85..a9f22f1 100644 --- a/Src/VideoGameQuotes.Web/Controllers/HomeController.cs +++ b/Src/VideoGameQuotes.Web/Controllers/HomeController.cs @@ -44,6 +44,10 @@ namespace VideoGameQuotes.Web.Controllers { this.userProvider = userProvider; } + protected new ActionResult Json(object data) { + return this.SerializeToJson(data); + } + public ActionResult Index() { return View(); } diff --git a/Src/VideoGameQuotes.Web/Controllers/PublisherController.cs b/Src/VideoGameQuotes.Web/Controllers/PublisherController.cs index db8ae24..d4c25b4 100644 --- a/Src/VideoGameQuotes.Web/Controllers/PublisherController.cs +++ b/Src/VideoGameQuotes.Web/Controllers/PublisherController.cs @@ -16,8 +16,12 @@ namespace VideoGameQuotes.Web.Controllers { this.publisherService = publisherService; } + protected new ActionResult Json(object data) { + return this.SerializeToJson(data); + } + [HttpPost, VerifyUser(Group = UserGroup.Admin)] - public JsonResult Delete(int id) { + public ActionResult Delete(int id) { if (id < 1) { return Json(this.CreateJsonResponse("Invalid ID")); } @@ -39,7 +43,7 @@ namespace VideoGameQuotes.Web.Controllers { } [HttpPost, VerifyUser(Group = UserGroup.Admin)] - public JsonResult Edit(EditPublisherModel model) { + public ActionResult Edit(EditPublisherModel model) { if (model.PublisherId < 1) { ModelState.AddModelError("PublisherId", "Invalid publisher ID"); } diff --git a/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs b/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs index 1516c69..0a85d39 100644 --- a/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs +++ b/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs @@ -1,8 +1,6 @@ using System; using System.Linq; using System.Net; -using System.Security.Cryptography; -using System.Text; using System.Web.Mvc; using Portoa.Persistence; using Portoa.Search; @@ -29,6 +27,10 @@ namespace VideoGameQuotes.Web.Controllers { this.quoteSearcher = quoteSearcher; } + protected new ActionResult Json(object data) { + return this.SerializeToJson(data); + } + public ActionResult Browse(BrowseModel model, int page = 1) { if (page < 1) { return new StatusOverrideResult(View("BadPaging")) { StatusCode = HttpStatusCode.BadRequest }; @@ -53,7 +55,7 @@ namespace VideoGameQuotes.Web.Controllers { } [HttpPost, VerifyUser] - public JsonResult Flag(ReportModel model) { + public ActionResult Flag(ReportModel model) { if (!ModelState.IsValid) { return Json(this.CreateJsonErrorResponse("Invalid request")); } @@ -69,7 +71,7 @@ namespace VideoGameQuotes.Web.Controllers { } [HttpPost, VerifyUser] - public JsonResult Vote(VoteModel model) { + public ActionResult Vote(VoteModel model) { if (!ModelState.IsValid) { return Json(this.CreateJsonErrorResponse("Invalid request")); } @@ -252,7 +254,7 @@ namespace VideoGameQuotes.Web.Controllers { return model; } - public ActionResult Quote(int id) { + public ActionResult Quote(int id, string text = null) { try { var model = new QuoteModel { Quote = quoteService.GetQuote(id), diff --git a/Src/VideoGameQuotes.Web/Controllers/SystemController.cs b/Src/VideoGameQuotes.Web/Controllers/SystemController.cs index a9b810e..e145cf2 100644 --- a/Src/VideoGameQuotes.Web/Controllers/SystemController.cs +++ b/Src/VideoGameQuotes.Web/Controllers/SystemController.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using Portoa.Persistence; @@ -18,8 +17,12 @@ namespace VideoGameQuotes.Web.Controllers { this.systemService = systemService; } + protected new ActionResult Json(object data) { + return this.SerializeToJson(data); + } + [HttpPost, VerifyUser(Group = UserGroup.Admin)] - public JsonResult Delete(int id) { + public ActionResult Delete(int id) { if (id < 1) { return Json(this.CreateJsonResponse("Invalid ID")); } @@ -41,7 +44,7 @@ namespace VideoGameQuotes.Web.Controllers { } [HttpPost, VerifyUser(Group = UserGroup.Admin)] - public JsonResult Edit(EditSystemModel model) { + public ActionResult Edit(EditSystemModel model) { if (model.SystemId < 1) { ModelState.AddModelError("SystemId", "Invalid system ID"); } diff --git a/Src/VideoGameQuotes.Web/Controllers/UserController.cs b/Src/VideoGameQuotes.Web/Controllers/UserController.cs index fa3f874..88e8814 100644 --- a/Src/VideoGameQuotes.Web/Controllers/UserController.cs +++ b/Src/VideoGameQuotes.Web/Controllers/UserController.cs @@ -1,9 +1,7 @@ -using System; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; using System.Net; using System.Web.Mvc; using Portoa.Persistence; -using Portoa.Validation.DataAnnotations; using Portoa.Web.Controllers; using Portoa.Web.Results; using VideoGameQuotes.Api; @@ -20,33 +18,8 @@ namespace VideoGameQuotes.Web.Controllers { this.userService = userService; } - [HttpPost, VerifyUser(Group = UserGroup.Admin)] - public ActionResult Delete([GreaterThanZero]int id) { - if (!ModelState.IsValid) { - return Json(this.CreateJsonErrorResponse("Invalid user id")); - } - - try { - userService.Delete(id); - return Json(this.CreateJsonResponse()); - } catch (Exception e) { - return Json(this.CreateJsonErrorResponse(e)); - } - } - - [VerifyUser(Group = UserGroup.Admin)] - public ActionResult Ban([GreaterThanZero]int id) { - return View(); - //if (!ModelState.IsValid) { - // return Json(this.CreateJsonErrorResponse("Invalid user id")); - //} - - //try { - // userService.Delete(id); - // return Json(this.CreateJsonResponse()); - //} catch (Exception e) { - // return Json(this.CreateJsonErrorResponse(e)); - //} + protected new ActionResult Json(object data) { + return this.SerializeToJson(data); } [HttpGet, VerifyUser(Group = UserGroup.Admin)] diff --git a/Src/VideoGameQuotes.Web/Global.asax.cs b/Src/VideoGameQuotes.Web/Global.asax.cs index 3c26a8a..51909ee 100644 --- a/Src/VideoGameQuotes.Web/Global.asax.cs +++ b/Src/VideoGameQuotes.Web/Global.asax.cs @@ -1,6 +1,8 @@ using System.Web.Mvc; using System.Web.Routing; +using JetBrains.Annotations; using Microsoft.Practices.Unity; +using Portoa.Logging; using Portoa.Search; using Portoa.Web; using Portoa.Web.Models; @@ -41,7 +43,7 @@ namespace VideoGameQuotes.Web { } protected override void AfterStartUp() { - EnableSmartCasing(); + ViewEngines.Engines.Add(new SmartCaseViewEngine(Container.Resolve())); Container.Resolve>().BuildIndex(); } @@ -54,21 +56,29 @@ namespace VideoGameQuotes.Web { //bullshit route so that RenderAction works routes.MapSmartRoute("mainmenu", "home/mainmenu", new { controller = "Home", action = "MainMenu" }); routes.MapSmartRoute("quote-of-the-day", "quote/quoteoftheday", new { controller = "Quote", action = "QuoteOfTheDay" }); + routes.MapSmartRoute("quote", "{action}", new { controller = "Quote" }, new { action = "submit|random|vote|flag|browse" }); + routes.MapSmartRoute("crud-default", "{controller}/{action}", null, new { controller = "system|publisher|game|category", action = "create|edit|delete" }); + routes.MapSmartRoute("admin-default", "admin", new { controller = "Admin", action = "Index" }); + 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("api-no-criteria", "api/{action}/{id}", new { controller = "Api" }, new { action = "game|system|category|publisher|quote", id = @"\d+|all" }); + 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-default", "{action}", new { controller = "Quote", page = 1 }, new { action = "best|recent" }); + 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" }); + + //these routes don't work with constraints in mono...? + routes.MapSmartRoute("quote-edit", "quote/edit/{id}", new { controller = "Quote", action = "Edit" }); + routes.MapSmartRoute("individual-quote-with-text", "quote/{id}/{*text}", new { controller = "Quote", action = "Quote" }); - routes.MapSmartRoute("crud-default", "{controller}/{action}", null, new { controller = "System|Publisher|Game|Category", action = "Create|Edit|Delete" }); - 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" }); + routes.MapSmartRoute("default", "", new { controller = "Home", action = "Index" }); } } } \ No newline at end of file diff --git a/Src/VideoGameQuotes.Web/VideoGameQuotes.Web.csproj b/Src/VideoGameQuotes.Web/VideoGameQuotes.Web.csproj index 17e6b51..95cab28 100644 --- a/Src/VideoGameQuotes.Web/VideoGameQuotes.Web.csproj +++ b/Src/VideoGameQuotes.Web/VideoGameQuotes.Web.csproj @@ -57,6 +57,9 @@ False ..\..\Lib\MySql.Data.dll + + ..\..\Lib\Newtonsoft.Json.dll + False ..\..\Lib\NHibernate.ByteCode.LinFu.dll diff --git a/Src/VideoGameQuotes.Web/Views/Home/Index.aspx b/Src/VideoGameQuotes.Web/Views/Home/Index.aspx index 11df3c7..8522958 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/Shared/MainMenu.ascx b/Src/VideoGameQuotes.Web/Views/Shared/MainMenu.ascx index fb770c2..c1df3e3 100644 --- a/Src/VideoGameQuotes.Web/Views/Shared/MainMenu.ascx +++ b/Src/VideoGameQuotes.Web/Views/Shared/MainMenu.ascx @@ -1,15 +1,15 @@ <%@ 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" }) %>
  • <% } %> \ No newline at end of file diff --git a/Src/VideoGameQuotes.Web/Views/Shared/Site.Master b/Src/VideoGameQuotes.Web/Views/Shared/Site.Master index 39679de..0004935 100644 --- a/Src/VideoGameQuotes.Web/Views/Shared/Site.Master +++ b/Src/VideoGameQuotes.Web/Views/Shared/Site.Master @@ -35,12 +35,12 @@ diff --git a/Src/VideoGameQuotes.Web/Web.config b/Src/VideoGameQuotes.Web/Web.config index e70ce63..50e4f1d 100644 --- a/Src/VideoGameQuotes.Web/Web.config +++ b/Src/VideoGameQuotes.Web/Web.config @@ -39,13 +39,13 @@ - + - + diff --git a/Src/VideoGameQuotes.Web/hibernate.cfg.xml b/Src/VideoGameQuotes.Web/hibernate.cfg.xml index a5d62f9..94822f4 100644 --- a/Src/VideoGameQuotes.Web/hibernate.cfg.xml +++ b/Src/VideoGameQuotes.Web/hibernate.cfg.xml @@ -6,7 +6,7 @@ Database=vgquotes;Data Source=localhost;User Id=vgquotes;Password=vgquotes NHibernate.Dialect.MySQLDialect NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu - true + false