diff --git a/Src/VideoGameQuotes.Api/Mappings/Quote.hbm.xml b/Src/VideoGameQuotes.Api/Mappings/Quote.hbm.xml index 4e8f8f8..d11f525 100644 --- a/Src/VideoGameQuotes.Api/Mappings/Quote.hbm.xml +++ b/Src/VideoGameQuotes.Api/Mappings/Quote.hbm.xml @@ -11,7 +11,7 @@ - + diff --git a/Src/VideoGameQuotes.Api/Region.cs b/Src/VideoGameQuotes.Api/Region.cs index a4657b6..19adb0b 100644 --- a/Src/VideoGameQuotes.Api/Region.cs +++ b/Src/VideoGameQuotes.Api/Region.cs @@ -11,8 +11,6 @@ namespace VideoGameQuotes.Api { Japan = 2, Europe = 4, PAL = 8, - Australia = 16, - - All = NorthAmerica | Japan | Europe | PAL | Australia + Australia = 16 } } \ No newline at end of file diff --git a/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs b/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs index 4111ce3..5ca4a22 100644 --- a/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs +++ b/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs @@ -72,7 +72,7 @@ namespace VideoGameQuotes.Web.Controllers { //construct game from model data var game = new Game { Name = model.GameName, - Region = model.GameRegions.Aggregate(Region.Unknown, (current, next) => current | (Region)Enum.Parse(typeof(Region), next)), + Region = model.GameRegions, Website = model.GameWebsite, Creator = currentUserProvider.CurrentUser }; @@ -123,6 +123,7 @@ namespace VideoGameQuotes.Web.Controllers { model.AllGames = quoteService.GetAllGames().OrderBy(game => game.Name); model.AllSystems = quoteService.GetAllSystems().OrderBy(system => system.ReleaseDate); model.AllPublishers = quoteService.GetAllPublishers(); + model.AllCategories = quoteService.GetAllCategories(); } public ActionResult Quote(int id) { diff --git a/Src/VideoGameQuotes.Web/Global.asax.cs b/Src/VideoGameQuotes.Web/Global.asax.cs index f25bb55..290d963 100644 --- a/Src/VideoGameQuotes.Web/Global.asax.cs +++ b/Src/VideoGameQuotes.Web/Global.asax.cs @@ -2,16 +2,21 @@ using System.Web.Routing; using Microsoft.Practices.Unity; using Portoa.Web; +using Portoa.Web.Models; using Portoa.Web.Unity; using UnityGenerics; using VideoGameQuotes.Api; using VideoGameQuotes.Api.Persistence; -using VideoGameQuotes.Web.Controllers; using VideoGameQuotes.Web.Security; using VideoGameQuotes.Web.Services; namespace VideoGameQuotes.Web { - public class MvcApplication : ApplicationBase { + public class MvcApplication : MvcApplicationBase { + + protected override void ConfigureModelBinders(ModelBinderDictionary binders) { + binders.Add(); + } + protected override void ConfigureUnity() { Container .AddNewExtension() diff --git a/Src/VideoGameQuotes.Web/Models/QuoteSubmitModel.cs b/Src/VideoGameQuotes.Web/Models/QuoteSubmitModel.cs index 3ef1c31..8cd673c 100644 --- a/Src/VideoGameQuotes.Web/Models/QuoteSubmitModel.cs +++ b/Src/VideoGameQuotes.Web/Models/QuoteSubmitModel.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; @@ -12,6 +13,8 @@ namespace VideoGameQuotes.Web.Models { public class QuoteSubmitModel { [Required, DisplayName("Quote")] public string QuoteText { get; set; } + [DisplayName("Categories")] + public IList CategoryIds { get; set; } public int GameId { get; set; } @@ -21,7 +24,7 @@ namespace VideoGameQuotes.Web.Models { [DisplayName("Website")] public string GameWebsite { get; set; } [DisplayName("Region")] - public IList GameRegions { get; set; } + public Region GameRegions { get; set; } [DisplayName("Publishers")] public IList PublisherIds { get; set; } [DisplayName("Systems")] @@ -44,6 +47,7 @@ namespace VideoGameQuotes.Web.Models { public IEnumerable AllGames { get; set; } public IEnumerable AllSystems { get; set; } public IEnumerable AllPublishers { get; set; } + public IEnumerable AllCategories { get; set; } public IEnumerable GetGameList() { return new[] { new SelectListItem { Value = "0", Text = "--none--" } } @@ -78,18 +82,41 @@ namespace VideoGameQuotes.Web.Models { return table.ToString(TagRenderMode.Normal); } - public string MakePublisherTable(HtmlHelper html, int cellsPerRow = 4) { - return MakeTable(cellsPerRow, AllPublishers, publisher => { - var id = "publisher_" + publisher.Id; - return html.CheckBox("PublisherIds", new { id }) + html.Label(publisher.Name, id); - }); + public string MakePublisherTable(HtmlHelper html, int cellsPerRow = 8) { + return MakeTable( + cellsPerRow, + AllPublishers, + publisher => CreateCheckbox(html, "PublisherIds", publisher.Id, "publisher_" + publisher.Id, publisher.Name) + ); } public string MakeSystemTable(HtmlHelper html, int cellsPerRow = 8) { - return MakeTable(cellsPerRow, AllSystems, system => { - var id = "system_" + system.Id; - return html.CheckBox("SystemIds", new { id }) + html.Label(system.Abbreviation, id, new { title = system.Name }); - }); + return MakeTable( + cellsPerRow, + AllSystems, + system => CreateCheckbox(html, "SystemIds", system.Id, "system_" + system.Id, system.Abbreviation) + ); + } + + public string MakeCategoryTable(HtmlHelper html, int cellsPerRow = 8) { + return MakeTable( + cellsPerRow, + AllCategories, + category => CreateCheckbox(html, "CategoryIds", category.Id, "category_" + category.Id, category.Name) + ); + } + + public string MakeRegionTable(HtmlHelper html, int cellsPerRow = 8) { + return MakeTable( + cellsPerRow, + (IEnumerable)Enum.GetValues(typeof(Region)), + region => CreateCheckbox(html, "GameRegions", region, "region_" + (int)region, region.ToString()) + ); + } + + private static string CreateCheckbox(HtmlHelper html, string name, object value, string id, string labelText) { + return string.Format("", name, value, id) + + html.Label(labelText, id); } } } \ No newline at end of file diff --git a/Src/VideoGameQuotes.Web/Services/QuoteService.cs b/Src/VideoGameQuotes.Web/Services/QuoteService.cs index d356e4d..d681699 100644 --- a/Src/VideoGameQuotes.Web/Services/QuoteService.cs +++ b/Src/VideoGameQuotes.Web/Services/QuoteService.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Portoa.Persistence; using VideoGameQuotes.Api; @@ -8,10 +9,12 @@ namespace VideoGameQuotes.Web.Services { IEnumerable GetAllGames(); IEnumerable GetAllSystems(); IEnumerable GetAllPublishers(); + IEnumerable GetAllCategories(); Quote SaveQuote(Quote quote); Quote GetQuote(int id); Publisher GetPublisher(int id); GamingSystem GetSystem(int systemId); + Category GetCategory(int categoryId); } public class QuoteService : IQuoteService { @@ -19,14 +22,16 @@ namespace VideoGameQuotes.Web.Services { private readonly IRepository gameRepository; private readonly IRepository systemRepository; private readonly IRepository publisherRepository; + private readonly IRepository categoryRepository; public QuoteService( IRepository quoteRepository, IRepository gameRepository, IRepository systemRepository, - IRepository publisherRepository - ) { + IRepository publisherRepository, IRepository categoryRepository + ) { this.quoteRepository = quoteRepository; + this.categoryRepository = categoryRepository; this.gameRepository = gameRepository; this.systemRepository = systemRepository; this.publisherRepository = publisherRepository; @@ -43,7 +48,7 @@ namespace VideoGameQuotes.Web.Services { } [UnitOfWork] - public IEnumerable GetAllSystems() { + public IEnumerable GetAllSystems() { return systemRepository.Records; } @@ -52,6 +57,11 @@ namespace VideoGameQuotes.Web.Services { return publisherRepository.Records; } + [UnitOfWork] + public IEnumerable GetAllCategories() { + return categoryRepository.Records; + } + [UnitOfWork] public Quote SaveQuote(Quote quote) { return quoteRepository.Save(quote); @@ -71,5 +81,10 @@ namespace VideoGameQuotes.Web.Services { public GamingSystem GetSystem(int systemId) { return systemRepository.FindById(systemId); } + + [UnitOfWork] + public Category GetCategory(int categoryId) { + return categoryRepository.FindById(categoryId); + } } } \ No newline at end of file diff --git a/Src/VideoGameQuotes.Web/Views/Quote/Submit.aspx b/Src/VideoGameQuotes.Web/Views/Quote/Submit.aspx index 6b8b178..f12d5a3 100644 --- a/Src/VideoGameQuotes.Web/Views/Quote/Submit.aspx +++ b/Src/VideoGameQuotes.Web/Views/Quote/Submit.aspx @@ -6,103 +6,119 @@ <%= Html.ValidationSummary() %> - <% using (Html.BeginForm()) { %> -

- - <%= Html.Label("Game", "GameId") %> +

+ <% using (Html.BeginForm()) { %> +

+ + <%= Html.Label("Game", "GameId") %> +
+ <%= Html.DropDownListFor(model => model.GameId, Model.GetGameList()) %> +
+ + Create new game +

+ +
+
+ Create new game + +

+ <%= Html.LabelFor(model => model.GameName) %> +
+ <%= Html.TextBoxFor(model => model.GameName) %> +

+ +

+ <%= Html.LabelFor(model => model.GameWebsite) %> (link to Wikipedia page or something) +
+ <%= Html.TextBoxFor(model => model.GameWebsite) %> +

+ +

+ <%= Html.LabelFor(model => model.GameRegions) %> +
+ <%= Model.MakeRegionTable(Html) %> +

+ +

+ + <%= Html.LabelFor(model => model.SystemIds) %> +
+ <%= Model.MakeSystemTable(Html) %> +
+ Create new system +

+ +
+
+ Create new system + +

+ <%= Html.LabelFor(model => model.SystemName) %> +
+ <%= Html.TextBoxFor(model => model.SystemName) %> +

+ +

+ <%= Html.LabelFor(model => model.SystemAbbreviation) %> +
+ <%= Html.TextBoxFor(model => model.SystemAbbreviation) %> +

+ +

+ <%= Html.LabelFor(model => model.SystemReleaseDate) %> +
+ <%= Html.TextBox("SystemReleaseDate", DateTime.UtcNow.ToString("yyyy-MM-dd")) %> +

+
+
+ +

+ + <%= Html.LabelFor(model => model.PublisherIds) %> +
+ <%= Model.MakePublisherTable(Html) %> +
+ Create new publisher +

+ +
+
+ Create new publisher + +

+ <%= Html.LabelFor(model => model.PublisherName) %> +
+ <%= Html.TextBoxFor(model => model.PublisherName) %> +

+ +

+ <%= Html.LabelFor(model => model.PublisherWebsite) %> +
+ <%= Html.TextBoxFor(model => model.PublisherWebsite) %> +

+
+
+
+
+ +

+ <%= Html.LabelFor(model => model.QuoteText) %>
- <%= Html.DropDownListFor(model => model.GameId, Model.GetGameList()) %> - + <%= Html.TextAreaFor(model => model.QuoteText) %> +

- Create new game -

+

+ <%= Html.LabelFor(model => model.CategoryIds) %> +
+ <%= Model.MakeCategoryTable(Html) %> -

-
- Create new game + Create new category +

-

- <%= Html.LabelFor(model => model.GameName) %> -
- <%= Html.TextBoxFor(model => model.GameName) %> -

- -

- <%= Html.LabelFor(model => model.GameWebsite) %> (link to Wikipedia page or something) -
- <%= Html.TextBoxFor(model => model.GameWebsite) %> -

- -

- - <%= Html.LabelFor(model => model.SystemIds) %> -
- <%= Model.MakeSystemTable(Html) %> -
- Create new system -

- -
-
- Create new system - -

- <%= Html.LabelFor(model => model.SystemName) %> -
- <%= Html.TextBoxFor(model => model.SystemName) %> -

- -

- <%= Html.LabelFor(model => model.SystemAbbreviation) %> -
- <%= Html.TextBoxFor(model => model.SystemAbbreviation) %> -

- -

- <%= Html.LabelFor(model => model.SystemReleaseDate) %> -
- <%= Html.TextBox("SystemReleaseDate", DateTime.UtcNow.ToString("yyyy-MM-dd")) %> -

-
-
- -

- - <%= Html.LabelFor(model => model.PublisherIds) %> -
- <%= Model.MakePublisherTable(Html) %> -
- Create new publisher -

- -
-
- Create new publisher - -

- <%= Html.LabelFor(model => model.PublisherName) %> -
- <%= Html.TextBoxFor(model => model.PublisherName) %> -

- -

- <%= Html.LabelFor(model => model.PublisherWebsite) %> -
- <%= Html.TextBoxFor(model => model.PublisherWebsite) %> -

-
-
-
-
- -

- <%= Html.LabelFor(model => model.QuoteText) %> -
- <%= Html.TextAreaFor(model => model.QuoteText) %> -

- - <%= Html.Submit("Submit") %> - <% } %> + <%= Html.Submit("Submit") %> + <% } %> +