From a41335c5bad61c3b34045ca34456fe8218fd8106 Mon Sep 17 00:00:00 2001
From: tmont
+ There are currently <%= Model.TotalNumberOfQuotes %> quotes. Choose wisely.
+
+ The quote and all its votes and flags were deleted.
+ ).GetMethod("Save", new[] { typeof(Quote) });
@@ -67,5 +74,14 @@ namespace VideoGameQuotes.Web.Configuration {
return member == saveMethod;
}
}
+
+ private class QuoteDeletedMatchingRule : IMatchingRule {
+ private static readonly MethodBase deleteMethod = typeof(IRepository
).GetMethod("Delete", new[] { typeof(int) });
+
+ public bool Matches(MethodBase member) {
+ return member == deleteMethod;
+ }
+ }
+ #endregion
}
}
\ No newline at end of file
diff --git a/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs b/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs
index 0a85d39..5d7de55 100644
--- a/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs
+++ b/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs
@@ -31,13 +31,23 @@ namespace VideoGameQuotes.Web.Controllers {
return this.SerializeToJson(data);
}
+ [HttpPost, VerifyUser(Group = UserGroup.Admin)]
+ public ActionResult Delete(int id) {
+ try {
+ quoteService.Delete(id);
+ return Json(this.CreateJsonResponse());
+ } catch (Exception e) {
+ return Json(this.CreateJsonErrorResponse(e));
+ }
+ }
+
public ActionResult Browse(BrowseModel model, int page = 1) {
if (page < 1) {
return new StatusOverrideResult(View("BadPaging")) { StatusCode = HttpStatusCode.BadRequest };
}
if (model.IsEmpty) {
- return View("DefaultBrowse");
+ return View("DefaultBrowse", quoteService.GetDefaultBrowseModel());
}
model.CurrentUser = currentUserProvider.CurrentUser;
diff --git a/Src/VideoGameQuotes.Web/Global.asax.cs b/Src/VideoGameQuotes.Web/Global.asax.cs
index 51909ee..f3bdd8b 100644
--- a/Src/VideoGameQuotes.Web/Global.asax.cs
+++ b/Src/VideoGameQuotes.Web/Global.asax.cs
@@ -75,7 +75,8 @@ namespace VideoGameQuotes.Web {
//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("quote-delete", "quote/delete", new { controller = "Quote", action = "Delete" });
+ routes.MapSmartRoute("single-quote", "quote/{id}/{*text}", new { controller = "Quote", action = "Quote" });
routes.MapSmartRoute("dismiss-flag", "dismiss-flag", new { controller = "Quote", action = "DismissFlag" });
routes.MapSmartRoute("default", "", new { controller = "Home", action = "Index" });
diff --git a/Src/VideoGameQuotes.Web/Models/DefaultBrowseModel.cs b/Src/VideoGameQuotes.Web/Models/DefaultBrowseModel.cs
new file mode 100644
index 0000000..0544f15
--- /dev/null
+++ b/Src/VideoGameQuotes.Web/Models/DefaultBrowseModel.cs
@@ -0,0 +1,9 @@
+namespace VideoGameQuotes.Web.Models {
+ public class DefaultBrowseModel {
+ public int TotalNumberOfQuotes { get; set; }
+ public int TotalNumberOfGames { get; set; }
+ public int TotalNumberOfSystems { get; set; }
+ public int TotalNumberOfPublishers { get; set; }
+ public int TotalNumberOfCategories { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Src/VideoGameQuotes.Web/Services/QuoteService.cs b/Src/VideoGameQuotes.Web/Services/QuoteService.cs
index fb86305..7e0b925 100644
--- a/Src/VideoGameQuotes.Web/Services/QuoteService.cs
+++ b/Src/VideoGameQuotes.Web/Services/QuoteService.cs
@@ -25,6 +25,8 @@ namespace VideoGameQuotes.Web.Services {
Vote GetVoteOrCreateNew(Quote quote, User voter);
IEnumerable
GetBrowsableQuotes(BrowseModel model, int start, int end, out int totalCount);
Quote GetQuoteForDayOfYear(int day);
+ DefaultBrowseModel GetDefaultBrowseModel();
+ void Delete(int id);
}
public class QuoteService : IQuoteService {
@@ -53,6 +55,22 @@ namespace VideoGameQuotes.Web.Services {
this.publisherRepository = publisherRepository;
}
+ [UnitOfWork]
+ public DefaultBrowseModel GetDefaultBrowseModel() {
+ return new DefaultBrowseModel {
+ TotalNumberOfCategories = categoryRepository.Records.Count(),
+ TotalNumberOfSystems = systemRepository.Records.Count(),
+ TotalNumberOfPublishers = publisherRepository.Records.Count(),
+ TotalNumberOfGames = gameRepository.Records.Count(),
+ TotalNumberOfQuotes = quoteRepository.Records.Count()
+ };
+ }
+
+ [UnitOfWork]
+ public void Delete(int id) {
+ quoteRepository.Delete(id);
+ }
+
[UnitOfWork]
public Game GetGame(int id) {
return gameRepository.FindById(id);
diff --git a/Src/VideoGameQuotes.Web/VideoGameQuotes.Web.csproj b/Src/VideoGameQuotes.Web/VideoGameQuotes.Web.csproj
index 95cab28..c1a0ef1 100644
--- a/Src/VideoGameQuotes.Web/VideoGameQuotes.Web.csproj
+++ b/Src/VideoGameQuotes.Web/VideoGameQuotes.Web.csproj
@@ -105,6 +105,7 @@
Browse
+ Wild Success!
+
+
- Anyway, try <%= Html.ActionLink("searching", "Search", "Quote") %> for the quote - you were hoping to find. Maybe that will make you less of a stain on humanity. + Anyway, try searching for the quote you were hoping to find using the little search box up + there in the top right corner. Maybe that will make you less of a stain on humanity.
diff --git a/Src/VideoGameQuotes.Web/Views/Shared/SingleQuote.ascx b/Src/VideoGameQuotes.Web/Views/Shared/SingleQuote.ascx index 89a38f4..ce6ad56 100644 --- a/Src/VideoGameQuotes.Web/Views/Shared/SingleQuote.ascx +++ b/Src/VideoGameQuotes.Web/Views/Shared/SingleQuote.ascx @@ -28,11 +28,12 @@
- + " title="permanent link to this quote"> <% if (Model.User != null && Model.User.Group >= UserGroup.Admin) { %> " title="edit this quote"> - (<%= Model.Quote.FlagCount %>) + + [<%= Model.Quote.FlagCount %>] <% } %>