submit form now works, except for categories, and error handling, and handling failed transactions, and...
This commit is contained in:
parent
f0221f2a7b
commit
2409a207cf
@ -11,7 +11,7 @@
|
||||
<property name="Modified" column="modified" not-null="false" type="DateTime" />
|
||||
|
||||
<many-to-one name="Creator" column="creator" not-null="true" foreign-key="fk_quote_user"/>
|
||||
<many-to-one name="Game" column="game_id" not-null="true" foreign-key="fk_quote_game" />
|
||||
<many-to-one name="Game" column="game_id" not-null="true" foreign-key="fk_quote_game" cascade="save-update" />
|
||||
|
||||
<set access="field" name="categories" table="quote_category_map" cascade="save-update">
|
||||
<key column="quote_id" />
|
||||
|
@ -11,8 +11,6 @@ namespace VideoGameQuotes.Api {
|
||||
Japan = 2,
|
||||
Europe = 4,
|
||||
PAL = 8,
|
||||
Australia = 16,
|
||||
|
||||
All = NorthAmerica | Japan | Europe | PAL | Australia
|
||||
Australia = 16
|
||||
}
|
||||
}
|
@ -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) {
|
||||
|
@ -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<Region, FlagEnumModelBinder>();
|
||||
}
|
||||
|
||||
protected override void ConfigureUnity() {
|
||||
Container
|
||||
.AddNewExtension<ConfigureLog4Net>()
|
||||
|
@ -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<int> 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<string> GameRegions { get; set; }
|
||||
public Region GameRegions { get; set; }
|
||||
[DisplayName("Publishers")]
|
||||
public IList<int> PublisherIds { get; set; }
|
||||
[DisplayName("Systems")]
|
||||
@ -44,6 +47,7 @@ namespace VideoGameQuotes.Web.Models {
|
||||
public IEnumerable<Game> AllGames { get; set; }
|
||||
public IEnumerable<GamingSystem> AllSystems { get; set; }
|
||||
public IEnumerable<Publisher> AllPublishers { get; set; }
|
||||
public IEnumerable<Category> AllCategories { get; set; }
|
||||
|
||||
public IEnumerable<SelectListItem> 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<QuoteSubmitModel> 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<QuoteSubmitModel> html, int cellsPerRow = 8) {
|
||||
return MakeTable(
|
||||
cellsPerRow,
|
||||
AllPublishers,
|
||||
publisher => CreateCheckbox(html, "PublisherIds", publisher.Id, "publisher_" + publisher.Id, publisher.Name)
|
||||
);
|
||||
}
|
||||
|
||||
public string MakeSystemTable(HtmlHelper<QuoteSubmitModel> 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<QuoteSubmitModel> html, int cellsPerRow = 8) {
|
||||
return MakeTable(
|
||||
cellsPerRow,
|
||||
AllCategories,
|
||||
category => CreateCheckbox(html, "CategoryIds", category.Id, "category_" + category.Id, category.Name)
|
||||
);
|
||||
}
|
||||
|
||||
public string MakeRegionTable(HtmlHelper<QuoteSubmitModel> html, int cellsPerRow = 8) {
|
||||
return MakeTable(
|
||||
cellsPerRow,
|
||||
(IEnumerable<Region>)Enum.GetValues(typeof(Region)),
|
||||
region => CreateCheckbox(html, "GameRegions", region, "region_" + (int)region, region.ToString())
|
||||
);
|
||||
}
|
||||
|
||||
private static string CreateCheckbox(HtmlHelper<QuoteSubmitModel> html, string name, object value, string id, string labelText) {
|
||||
return string.Format("<input type=\"checkbox\" name=\"{0}\" value=\"{1}\" id=\"{2}\"/>", name, value, id)
|
||||
+ html.Label(labelText, id);
|
||||
}
|
||||
}
|
||||
}
|
@ -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<Game> GetAllGames();
|
||||
IEnumerable<GamingSystem> GetAllSystems();
|
||||
IEnumerable<Publisher> GetAllPublishers();
|
||||
IEnumerable<Category> 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<Game> gameRepository;
|
||||
private readonly IRepository<GamingSystem> systemRepository;
|
||||
private readonly IRepository<Publisher> publisherRepository;
|
||||
private readonly IRepository<Category> categoryRepository;
|
||||
|
||||
public QuoteService(
|
||||
IRepository<Quote> quoteRepository,
|
||||
IRepository<Game> gameRepository,
|
||||
IRepository<GamingSystem> systemRepository,
|
||||
IRepository<Publisher> publisherRepository
|
||||
IRepository<Publisher> publisherRepository, IRepository<Category> 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<Api.GamingSystem> GetAllSystems() {
|
||||
public IEnumerable<GamingSystem> GetAllSystems() {
|
||||
return systemRepository.Records;
|
||||
}
|
||||
|
||||
@ -52,6 +57,11 @@ namespace VideoGameQuotes.Web.Services {
|
||||
return publisherRepository.Records;
|
||||
}
|
||||
|
||||
[UnitOfWork]
|
||||
public IEnumerable<Category> 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
|
||||
<%= Html.ValidationSummary() %>
|
||||
|
||||
<div id="create-quote-form">
|
||||
<% using (Html.BeginForm()) { %>
|
||||
<p>
|
||||
<span id="game-select">
|
||||
@ -33,6 +34,12 @@
|
||||
<%= Html.TextBoxFor(model => model.GameWebsite) %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= Html.LabelFor(model => model.GameRegions) %>
|
||||
<br />
|
||||
<%= Model.MakeRegionTable(Html) %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<span id="system-select">
|
||||
<%= Html.LabelFor(model => model.SystemIds) %>
|
||||
@ -101,8 +108,17 @@
|
||||
<%= Html.TextAreaFor(model => model.QuoteText) %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= Html.LabelFor(model => model.CategoryIds) %>
|
||||
<br />
|
||||
<%= Model.MakeCategoryTable(Html) %>
|
||||
|
||||
<a href="#" id="create-category-link">Create new category</a>
|
||||
</p>
|
||||
|
||||
<%= Html.Submit("Submit") %>
|
||||
<% } %>
|
||||
</div>
|
||||
</asp:Content>
|
||||
<asp:Content runat="server" ID="DeferrableScripts" ContentPlaceHolderID="DeferrableScripts">
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
|
@ -132,9 +132,19 @@ legend {
|
||||
border-bottom: 2px solid #000000;
|
||||
}
|
||||
|
||||
#create-game-form, #create-system-form {
|
||||
#create-game-form, #create-system-form, #create-publisher-form {
|
||||
display: none;
|
||||
}
|
||||
#create-quote-form input[type="text"] {
|
||||
width: 300px;
|
||||
}
|
||||
#create-quote-form textarea {
|
||||
width: 500px;
|
||||
height: 100px;
|
||||
}
|
||||
#create-quote-form td {
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
#footer {
|
||||
text-align: center;
|
||||
|
Loading…
Reference in New Issue
Block a user