2011-02-12 23:53:43 +00:00
|
|
|
|
using System;
|
2011-02-13 09:55:01 +00:00
|
|
|
|
using System.Collections;
|
2011-02-12 23:53:43 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Web.Mvc;
|
|
|
|
|
using System.Web.Mvc.Html;
|
|
|
|
|
using Portoa.Web.Util;
|
|
|
|
|
using VideoGameQuotes.Api;
|
|
|
|
|
|
|
|
|
|
namespace VideoGameQuotes.Web.Models {
|
|
|
|
|
public class QuoteSubmitModel {
|
|
|
|
|
[Required, DisplayName("Quote")]
|
|
|
|
|
public string QuoteText { get; set; }
|
2011-02-13 09:55:01 +00:00
|
|
|
|
[DisplayName("Categories")]
|
|
|
|
|
public IList<int> CategoryIds { get; set; }
|
2011-02-12 23:53:43 +00:00
|
|
|
|
|
|
|
|
|
public int GameId { get; set; }
|
|
|
|
|
|
|
|
|
|
//if a new game is created
|
|
|
|
|
[DisplayName("Name")]
|
|
|
|
|
public string GameName { get; set; }
|
|
|
|
|
[DisplayName("Website")]
|
|
|
|
|
public string GameWebsite { get; set; }
|
|
|
|
|
[DisplayName("Region")]
|
2011-02-13 09:55:01 +00:00
|
|
|
|
public Region GameRegions { get; set; }
|
2011-02-12 23:53:43 +00:00
|
|
|
|
[DisplayName("Publishers")]
|
|
|
|
|
public IList<int> PublisherIds { get; set; }
|
|
|
|
|
[DisplayName("Systems")]
|
|
|
|
|
public IList<int> SystemIds { get; set; }
|
|
|
|
|
|
|
|
|
|
//if a new publisher is created
|
|
|
|
|
[DisplayName("Name")]
|
|
|
|
|
public string PublisherName { get; set; }
|
|
|
|
|
[DisplayName("Website")]
|
|
|
|
|
public string PublisherWebsite { get; set; }
|
|
|
|
|
|
|
|
|
|
//if a new system is created
|
|
|
|
|
[DisplayName("Name")]
|
|
|
|
|
public string SystemName { get; set; }
|
|
|
|
|
[DisplayName("Abbreviation")]
|
|
|
|
|
public string SystemAbbreviation { get; set; }
|
|
|
|
|
[DisplayName("Release Date")]
|
|
|
|
|
public DateTime SystemReleaseDate { get; set; }
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Game> AllGames { get; set; }
|
|
|
|
|
public IEnumerable<GamingSystem> AllSystems { get; set; }
|
|
|
|
|
public IEnumerable<Publisher> AllPublishers { get; set; }
|
2011-02-13 09:55:01 +00:00
|
|
|
|
public IEnumerable<Category> AllCategories { get; set; }
|
2011-02-12 23:53:43 +00:00
|
|
|
|
|
|
|
|
|
public IEnumerable<SelectListItem> GetGameList() {
|
|
|
|
|
return new[] { new SelectListItem { Value = "0", Text = "--none--" } }
|
|
|
|
|
.Concat(AllGames.Select(game => new SelectListItem { Value = game.Id.ToString(), Text = game.Name }));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string MakeTable<T>(int cellsPerRow, IEnumerable<T> items, Func<T, string> cellDataCallback) {
|
|
|
|
|
var table = new TagBuilder("table");
|
|
|
|
|
var count = 0;
|
|
|
|
|
var row = new TagBuilder("tr");
|
|
|
|
|
var cell = new TagBuilder("td");
|
|
|
|
|
|
|
|
|
|
foreach (var item in items) {
|
|
|
|
|
if (count % cellsPerRow == 0) {
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
table.InnerHtml += row.ToString(TagRenderMode.Normal);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
row.InnerHtml = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cell.InnerHtml = cellDataCallback(item);
|
|
|
|
|
row.InnerHtml += cell.ToString(TagRenderMode.Normal);
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
//last row
|
|
|
|
|
table.InnerHtml += row.ToString(TagRenderMode.Normal);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return table.ToString(TagRenderMode.Normal);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-13 09:55:01 +00:00
|
|
|
|
public string MakePublisherTable(HtmlHelper<QuoteSubmitModel> html, int cellsPerRow = 8) {
|
|
|
|
|
return MakeTable(
|
|
|
|
|
cellsPerRow,
|
|
|
|
|
AllPublishers,
|
|
|
|
|
publisher => CreateCheckbox(html, "PublisherIds", publisher.Id, "publisher_" + publisher.Id, publisher.Name)
|
|
|
|
|
);
|
2011-02-12 23:53:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string MakeSystemTable(HtmlHelper<QuoteSubmitModel> html, int cellsPerRow = 8) {
|
2011-02-13 09:55:01 +00:00
|
|
|
|
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);
|
2011-02-12 23:53:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|