From 602a7222777ef126904f011c9a7aa4fd06909a9f Mon Sep 17 00:00:00 2001 From: tmont Date: Mon, 28 Feb 2011 00:38:47 +0000 Subject: [PATCH] quote of the day, added external image --- .../Controllers/QuoteController.cs | 7 ++ Src/VideoGameQuotes.Web/Global.asax.cs | 1 + .../Services/QuoteService.cs | 24 +++++- .../VideoGameQuotes.Web.csproj | 2 + Src/VideoGameQuotes.Web/Views/Home/About.aspx | 74 ++++++++-------- Src/VideoGameQuotes.Web/Views/Home/Index.aspx | 2 + .../Views/Quote/QuoteOfTheDay.ascx | 20 +++++ .../Views/Shared/Site.Master | 3 +- Src/VideoGameQuotes.Web/media/css/global.css | 11 ++- .../media/images/external.png | Bin 0 -> 195 bytes .../media/images/search.png | Bin 582 -> 615 bytes Src/VideoGameQuotes.Web/media/js/quoteform.js | 9 +- Src/VideoGameQuotes.Web/media/js/vgquotes.js | 81 ++++++++++++------ 13 files changed, 164 insertions(+), 70 deletions(-) create mode 100644 Src/VideoGameQuotes.Web/Views/Quote/QuoteOfTheDay.ascx create mode 100644 Src/VideoGameQuotes.Web/media/images/external.png diff --git a/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs b/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs index 48e1153..ed12483 100644 --- a/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs +++ b/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs @@ -135,6 +135,13 @@ namespace VideoGameQuotes.Web.Controllers { return RedirectToAction("Quote", new { id = quote.Id, text = quote.GetUrlFriendlyText() }); } + [ChildActionOnly] + public ActionResult QuoteOfTheDay() { + var today = DateTime.UtcNow.DayOfYear; + var quote = quoteService.GetQuoteForDayOfYear(today); + return PartialView("QuoteOfTheDay", quote); + } + [HttpPost, VerifyUser(Group = UserGroup.Admin)] public ActionResult DismissFlag([GreaterThanZero]int quoteId, [GreaterThanZero]int flagId) { if (!ModelState.IsValid) { diff --git a/Src/VideoGameQuotes.Web/Global.asax.cs b/Src/VideoGameQuotes.Web/Global.asax.cs index c12095e..441ab68 100644 --- a/Src/VideoGameQuotes.Web/Global.asax.cs +++ b/Src/VideoGameQuotes.Web/Global.asax.cs @@ -63,6 +63,7 @@ namespace VideoGameQuotes.Web { //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.MapRoute("crud-default", "{controller}/{action}", null, new { controller = "system|publisher|game|category", action = "create|edit|delete" }); diff --git a/Src/VideoGameQuotes.Web/Services/QuoteService.cs b/Src/VideoGameQuotes.Web/Services/QuoteService.cs index f1ed697..414b228 100644 --- a/Src/VideoGameQuotes.Web/Services/QuoteService.cs +++ b/Src/VideoGameQuotes.Web/Services/QuoteService.cs @@ -24,6 +24,7 @@ namespace VideoGameQuotes.Web.Services { IEnumerable GetBestQuotes(int start, int end, out int totalCount); Vote GetVoteOrCreateNew(Quote quote, User voter); IEnumerable GetBrowsableQuotes(BrowseModel model, int start, int end, out int totalCount); + Quote GetQuoteForDayOfYear(int day); } public class QuoteService : IQuoteService { @@ -34,6 +35,7 @@ namespace VideoGameQuotes.Web.Services { private readonly IRepository categoryRepository; private readonly IRepository voteRepository; private static readonly Random random = new Random(); + private static readonly IDictionary quoteOfTheDayMap = new Dictionary(); public QuoteService( IRepository quoteRepository, @@ -118,8 +120,16 @@ namespace VideoGameQuotes.Web.Services { return null; } - return quoteRepository - .Records + return GetRandomQuote(quoteRepository.Records); + } + + private static Quote GetRandomQuote(IEnumerable quotes) { + var length = quotes.Count(); + if (length == 0) { + return null; + } + + return quotes .Skip(random.Next(length)) .Take(1) .Single(); @@ -164,5 +174,15 @@ namespace VideoGameQuotes.Web.Services { totalCount = quotes.Count(); return quotes.Skip(start - 1).Take(end - start + 1); } + + + [UnitOfWork, CanBeNull] + public Quote GetQuoteForDayOfYear(int day) { + if (!quoteOfTheDayMap.ContainsKey(day)) { + quoteOfTheDayMap[day] = GetRandomQuote(quoteRepository.Records.Where(quote => quote.Score > 0)); + } + + return quoteOfTheDayMap[day]; + } } } \ No newline at end of file diff --git a/Src/VideoGameQuotes.Web/VideoGameQuotes.Web.csproj b/Src/VideoGameQuotes.Web/VideoGameQuotes.Web.csproj index 3c52671..e81cacb 100644 --- a/Src/VideoGameQuotes.Web/VideoGameQuotes.Web.csproj +++ b/Src/VideoGameQuotes.Web/VideoGameQuotes.Web.csproj @@ -149,6 +149,7 @@ + @@ -172,6 +173,7 @@ + diff --git a/Src/VideoGameQuotes.Web/Views/Home/About.aspx b/Src/VideoGameQuotes.Web/Views/Home/About.aspx index 8eb1339..c58f3e1 100644 --- a/Src/VideoGameQuotes.Web/Views/Home/About.aspx +++ b/Src/VideoGameQuotes.Web/Views/Home/About.aspx @@ -3,45 +3,45 @@

About

-
-

Genesis

-
-

- Video Game Quotes is a little project that I decided to tackle one day. I gave - myself a week to implement everything and throw it up on the internet. -

+

+ Video Game Quotes is a little project that I decided to tackle one day. I gave + myself a week to implement everything and throw it up on the internet. It actually took three + weeks as I struggled with Lucene and my + obviously poor graphic design skills. +

-

- The inspiration for the site was that there were a lot of awesome video game quotes, but sadly, - no central place to go to find/search/read them. That made me sad. -

+

+ The inspiration for the site was that there were a lot of awesome video game quotes, but sadly, + no central place to go to find/search/read them. That made me sad. +

-

- The infrastructure is modeled after bash.org, which is a database - of IRC quotes. One thing I wanted to make sure of was that it shouldn't require you to login or - register. No email addresses, or usernames, or passwords. The site keeps track of who has voted - for what based on IP address, which admittedly is a quite fragile. But it's the only way to - unique-ish-ly identify someone without requiring a login. So, you could totally game the system - by voting, resetting your router, closing your browser, and voting again. I won't stop you. -

-
+

+ The infrastructure is modeled after bash.org, which is a database + of IRC quotes. One thing I wanted to make sure of was that it shouldn’t require you to login or + register. No email addresses, or usernames, or passwords. The site keeps track of who has voted + for what based on IP address, which admittedly is a quite fragile. But it’s the only way to + unique-ish-ly identify someone without requiring a login. So, you could totally game the system + by voting, resetting your router, closing your browser, and voting again. I won’t stop you. +

-

Technical Details

-
-

- The site was written in C♯ using ASP.NET MVC 2, - Unity and NHibernate. - It runs on nginx using Mono - via FastCGI on Ubuntu. It uses MySQL for the backend. -

-
+

+ The site was written in C♯ using ASP.NET MVC 2, + Unity and NHibernate. + It runs on nginx using Mono + via FastCGI on Ubuntu. It uses MySQL for the backend and + Lucene.NET for search indexing. +

-

Get in Touch

-
-

- If you have any questions, concerns, comments, insults or death threats, don't hesitate to - <%= Html.ActionLink("contact me", "Contact", "Home") %>. -

-
-
+

+ If you have any questions, concerns, comments, insults or death threats, don’t hesitate to + <%= Html.ActionLink("contact me", "Contact", "Home") %> and you will be ignored immediately. +

+ +

Credits

+

+ Some of the icons and images used on this site were taken from the + silk icon set and + deleket’s + gaming icon set. +

diff --git a/Src/VideoGameQuotes.Web/Views/Home/Index.aspx b/Src/VideoGameQuotes.Web/Views/Home/Index.aspx index 5cf4ba0..39428fa 100644 --- a/Src/VideoGameQuotes.Web/Views/Home/Index.aspx +++ b/Src/VideoGameQuotes.Web/Views/Home/Index.aspx @@ -27,4 +27,6 @@

Here is the quote of the day:

+ + <% Html.RenderAction("QuoteOfTheDay", "Quote"); %> \ No newline at end of file diff --git a/Src/VideoGameQuotes.Web/Views/Quote/QuoteOfTheDay.ascx b/Src/VideoGameQuotes.Web/Views/Quote/QuoteOfTheDay.ascx new file mode 100644 index 0000000..fe8d24d --- /dev/null +++ b/Src/VideoGameQuotes.Web/Views/Quote/QuoteOfTheDay.ascx @@ -0,0 +1,20 @@ +<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> +<%@ Import Namespace="VideoGameQuotes.Api" %> + +
+
+
+
+
+
<%= Model.Score %>
+
+
+
+ + +
+
\ 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 ba10e94..5e5a853 100644 --- a/Src/VideoGameQuotes.Web/Views/Shared/Site.Master +++ b/Src/VideoGameQuotes.Web/Views/Shared/Site.Master @@ -37,7 +37,8 @@