* fixed some bugs that occurred when there are no quotes in the database

* fixed some bullshit route stuff that mono failed to implement correctly
* don't use JsonResult because it's broken on Mono
This commit is contained in:
tmont 2011-03-03 23:41:42 +00:00
parent b75f46359d
commit 6d17cfa573
16 changed files with 84 additions and 83 deletions

View File

@ -132,7 +132,5 @@ namespace VideoGameQuotes.Web.Controllers {
var flaggedQuotes = adminService.GetFlaggedQuotes();
return View(flaggedQuotes);
}
}
}

View File

@ -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<TDto>(Func<IApiService, IEnumerable<TDto>> 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 {

View File

@ -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."));
}

View File

@ -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);

View File

@ -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();
}

View File

@ -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");
}

View File

@ -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),

View File

@ -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");
}

View File

@ -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)]

View File

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

View File

@ -57,6 +57,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Lib\MySql.Data.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\Lib\Newtonsoft.Json.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>

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

@ -1,15 +1,15 @@
<%@ 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 class="searchbox">
<%= Html.TextBox("searchQuery", null, new { id = "search-query" })%>
<span href="#" title="search quotes" id="search-submit"></span>
<span href="#" title="search quotes" id="search-submit"></span>
</li>

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

@ -39,13 +39,13 @@
<logger name="vgquotes">
<level value="ALL"/>
<appender-ref ref="DebugAppender" />
<!--<appender-ref ref="DebugAppender" />-->
<appender-ref ref="TelnetAppender" />
</logger>
<logger name="NHibernate.SQL">
<level value="ALL"/>
<appender-ref ref="DebugAppender" />
<!--<appender-ref ref="DebugAppender" />-->
<appender-ref ref="TelnetAppender" />
</logger>
</log4net>

View File

@ -6,7 +6,7 @@
<property name="connection.connection_string">Database=vgquotes;Data Source=localhost;User Id=vgquotes;Password=vgquotes</property>
<property name="dialect">NHibernate.Dialect.MySQLDialect</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
<property name="show_sql">true</property>
<property name="show_sql">false</property>
<mapping assembly="VideoGameQuotes.Api"/>
</session-factory>