submit form now works, except for categories, and error handling, and handling failed transactions, and...

This commit is contained in:
tmont 2011-02-13 09:55:01 +00:00
parent f0221f2a7b
commit 2409a207cf
8 changed files with 187 additions and 115 deletions

View File

@ -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" />

View File

@ -11,8 +11,6 @@ namespace VideoGameQuotes.Api {
Japan = 2,
Europe = 4,
PAL = 8,
Australia = 16,
All = NorthAmerica | Japan | Europe | PAL | Australia
Australia = 16
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -6,103 +6,119 @@
<%= Html.ValidationSummary() %>
<% using (Html.BeginForm()) { %>
<p>
<span id="game-select">
<%= Html.Label("Game", "GameId") %>
<div id="create-quote-form">
<% using (Html.BeginForm()) { %>
<p>
<span id="game-select">
<%= Html.Label("Game", "GameId") %>
<br />
<%= Html.DropDownListFor(model => model.GameId, Model.GetGameList()) %>
</span>
<a href="#" id="create-game-link">Create new game</a>
</p>
<div id="create-game-form">
<fieldset>
<legend>Create new game</legend>
<p>
<%= Html.LabelFor(model => model.GameName) %>
<br />
<%= Html.TextBoxFor(model => model.GameName) %>
</p>
<p>
<%= Html.LabelFor(model => model.GameWebsite) %> <small>(link to Wikipedia page or something)</small>
<br />
<%= 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) %>
<br />
<%= Model.MakeSystemTable(Html) %>
</span>
<a href="#" id="create-system-link">Create new system</a>
</p>
<div id="create-system-form">
<fieldset>
<legend>Create new system</legend>
<p>
<%= Html.LabelFor(model => model.SystemName) %>
<br />
<%= Html.TextBoxFor(model => model.SystemName) %>
</p>
<p>
<%= Html.LabelFor(model => model.SystemAbbreviation) %>
<br />
<%= Html.TextBoxFor(model => model.SystemAbbreviation) %>
</p>
<p>
<%= Html.LabelFor(model => model.SystemReleaseDate) %>
<br />
<%= Html.TextBox("SystemReleaseDate", DateTime.UtcNow.ToString("yyyy-MM-dd")) %>
</p>
</fieldset>
</div>
<p>
<span id="publisher-select">
<%= Html.LabelFor(model => model.PublisherIds) %>
<br />
<%= Model.MakePublisherTable(Html) %>
</span>
<a href="#" id="create-publisher-link">Create new publisher</a>
</p>
<div id="create-publisher-form">
<fieldset>
<legend>Create new publisher</legend>
<p>
<%= Html.LabelFor(model => model.PublisherName) %>
<br />
<%= Html.TextBoxFor(model => model.PublisherName) %>
</p>
<p>
<%= Html.LabelFor(model => model.PublisherWebsite) %>
<br />
<%= Html.TextBoxFor(model => model.PublisherWebsite) %>
</p>
</fieldset>
</div>
</fieldset>
</div>
<p>
<%= Html.LabelFor(model => model.QuoteText) %>
<br />
<%= Html.DropDownListFor(model => model.GameId, Model.GetGameList()) %>
</span>
<%= Html.TextAreaFor(model => model.QuoteText) %>
</p>
<a href="#" id="create-game-link">Create new game</a>
</p>
<p>
<%= Html.LabelFor(model => model.CategoryIds) %>
<br />
<%= Model.MakeCategoryTable(Html) %>
<div id="create-game-form">
<fieldset>
<legend>Create new game</legend>
<a href="#" id="create-category-link">Create new category</a>
</p>
<p>
<%= Html.LabelFor(model => model.GameName) %>
<br />
<%= Html.TextBoxFor(model => model.GameName) %>
</p>
<p>
<%= Html.LabelFor(model => model.GameWebsite) %> <small>(link to Wikipedia page or something)</small>
<br />
<%= Html.TextBoxFor(model => model.GameWebsite) %>
</p>
<p>
<span id="system-select">
<%= Html.LabelFor(model => model.SystemIds) %>
<br />
<%= Model.MakeSystemTable(Html) %>
</span>
<a href="#" id="create-system-link">Create new system</a>
</p>
<div id="create-system-form">
<fieldset>
<legend>Create new system</legend>
<p>
<%= Html.LabelFor(model => model.SystemName) %>
<br />
<%= Html.TextBoxFor(model => model.SystemName) %>
</p>
<p>
<%= Html.LabelFor(model => model.SystemAbbreviation) %>
<br />
<%= Html.TextBoxFor(model => model.SystemAbbreviation) %>
</p>
<p>
<%= Html.LabelFor(model => model.SystemReleaseDate) %>
<br />
<%= Html.TextBox("SystemReleaseDate", DateTime.UtcNow.ToString("yyyy-MM-dd")) %>
</p>
</fieldset>
</div>
<p>
<span id="publisher-select">
<%= Html.LabelFor(model => model.PublisherIds) %>
<br />
<%= Model.MakePublisherTable(Html) %>
</span>
<a href="#" id="create-publisher-link">Create new publisher</a>
</p>
<div id="create-publisher-form">
<fieldset>
<legend>Create new publisher</legend>
<p>
<%= Html.LabelFor(model => model.PublisherName) %>
<br />
<%= Html.TextBoxFor(model => model.PublisherName) %>
</p>
<p>
<%= Html.LabelFor(model => model.PublisherWebsite) %>
<br />
<%= Html.TextBoxFor(model => model.PublisherWebsite) %>
</p>
</fieldset>
</div>
</fieldset>
</div>
<p>
<%= Html.LabelFor(model => model.QuoteText) %>
<br />
<%= Html.TextAreaFor(model => model.QuoteText) %>
</p>
<%= Html.Submit("Submit") %>
<% } %>
<%= Html.Submit("Submit") %>
<% } %>
</div>
</asp:Content>
<asp:Content runat="server" ID="DeferrableScripts" ContentPlaceHolderID="DeferrableScripts">
<script type="text/javascript">//<![CDATA[

View File

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