FindByNameOrAbbreviation(string name, string abbreviation) {
+ return repository
+ .Records
+ .Where(system => system.Abbreviation == abbreviation || system.Name == name);
+ }
+
+ [UnitOfWork]
+ public GamingSystem Save(GamingSystem system) {
+ return repository.Save(system);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Src/VideoGameQuotes.Web/VideoGameQuotes.Web.csproj b/Src/VideoGameQuotes.Web/VideoGameQuotes.Web.csproj
index 5a1d27b..9f6e933 100644
--- a/Src/VideoGameQuotes.Web/VideoGameQuotes.Web.csproj
+++ b/Src/VideoGameQuotes.Web/VideoGameQuotes.Web.csproj
@@ -87,12 +87,19 @@
+
+
+
+
+
+
+
diff --git a/Src/VideoGameQuotes.Web/Views/Quote/EditQuoteForm.ascx b/Src/VideoGameQuotes.Web/Views/Quote/EditQuoteForm.ascx
index f0758bf..3b71b09 100644
--- a/Src/VideoGameQuotes.Web/Views/Quote/EditQuoteForm.ascx
+++ b/Src/VideoGameQuotes.Web/Views/Quote/EditQuoteForm.ascx
@@ -5,12 +5,10 @@
<% using (Html.BeginForm(Model.ActionName, Model.ControllerName)) { %>
<%= Html.HiddenFor(model => model.QuoteId, new { id = "quote-id" })%>
-
-
- <%= Html.Label("Game", "GameId") %>
-
- <%= Html.DropDownListFor(model => model.GameId, Model.GetGameList()) %>
-
+
+ <%= Html.Label("Game", "GameId") %>
+
+ <%= Html.DropDownListFor(model => model.GameId, Model.GetGameList()) %>
Create new game
@@ -20,82 +18,87 @@
- <%= Html.LabelFor(model => model.GameName) %>
+ <%= Html.Label("Name", "GameName") %>
- <%= Html.TextBoxFor(model => model.GameName) %>
+ <%= Html.TextBox("GameName") %>
- <%= Html.LabelFor(model => model.GameWebsite) %> (link to Wikipedia page or something)
+ <%= Html.Label("Website", "GameWebsite") %> (link to Wikipedia page or something)
- <%= Html.TextBoxFor(model => model.GameWebsite) %>
+ <%= Html.TextBox("GameWebsite") %>
- <%= Html.LabelFor(model => model.GameRegions) %>
+ Regions
<%= Model.MakeRegionTable() %>
-
-
- <%= Html.LabelFor(model => model.SystemIds) %>
-
- <%= Model.MakeSystemTable(Html) %>
-
+
-
-
- <%= Html.LabelFor(model => model.PublisherIds) %>
-
- <%= Model.MakePublisherTable(Html) %>
-
+
+
+ <%= Html.Button("Create Game", new { id = "create-game-submit" })%>
+ <%= Html.Button("Cancel", new { id = "create-game-cancel" })%>
diff --git a/Src/VideoGameQuotes.Web/media/js/vgquotes.js b/Src/VideoGameQuotes.Web/media/js/vgquotes.js
index 3a9303c..e7a6965 100644
--- a/Src/VideoGameQuotes.Web/media/js/vgquotes.js
+++ b/Src/VideoGameQuotes.Web/media/js/vgquotes.js
@@ -225,43 +225,104 @@
};
var setupQuoteForm = function() {
- $("#create-game-link").click(function() {
- var $form = $("#create-game-form");
- if ($form.is(":visible")) {
- $("#create-game-link").text("Create new game");
- } else {
- $("#create-game-link").text("Use existing game");
- $("#GameId").val("0");
+ var toggleFormAndLink = function(type) {
+ return function() {
+ $("#create-" + type + "-form").toggle();
+ $("#" + type + "-select").toggle();
+ return false;
+ }
+ };
+
+ var addNewCheckbox = function($table, name, value, text, cellsPerRow) {
+ var $row = $table.find("tr:last");
+ if ($row.find("td").length === cellsPerRow) {
+ $row = $("
");
+ $table.append($row);
}
- $form.toggle();
- $("#game-select").toggle();
+ var $cell = $(" | ").append($("").attr({
+ type: "checkbox",
+ name: name,
+ value: value,
+ id: name + "_" + value,
+ checked: "checked"
+ })).append($("").attr("for", name + "_" + value).text(text));
+
+ $row.append($cell);
+ $table.append($row);
+ };
+
+ $("#create-game-link, #create-game-cancel").click(toggleFormAndLink("game"));
+ $("#create-system-link, #create-system-cancel").click(toggleFormAndLink("system"));
+ $("#create-publisher-link, #create-publisher-cancel").click(toggleFormAndLink("publisher"));
+
+ $("#create-system-submit").click(function() {
+ $.ajax("/system/create", {
+ type: "POST",
+ data: { Name: $("#SystemName").val(), Abbreviation: $("#SystemAbbreviation").val(), ReleaseDate: $("#SystemReleaseDate").val() },
+ success: function(data, statux, $xhr) {
+ if (data.Error !== null) {
+ alert(data.Error);
+ return;
+ }
+
+ //add checkbox to table
+ addNewCheckbox($("#system-checkbox-table"), "SystemIds", data.Data.Id, data.Data.Abbreviation, 8);
+ toggleFormAndLink("system")();
+ }
+ });
+
return false;
});
-
- $("#create-system-link").click(function() {
- var $form = $("#create-system-form");
- if ($form.is(":visible")) {
- $("#create-system-link").text("Create new system");
- } else {
- $("#create-system-link").text("Use existing system");
- }
-
- $form.toggle();
- $("#system-select").toggle();
+
+ $("#create-publisher-submit").click(function() {
+ $.ajax("/publisher/create", {
+ type: "POST",
+ data: { Name: $("#PublisherName").val(), Website: $("#PublisherWebsite").val() },
+ success: function(data, statux, $xhr) {
+ if (data.Error !== null) {
+ alert(data.Error);
+ return;
+ }
+
+ addNewCheckbox($("#publisher-checkbox-table"), "PublisherIds", data.Data.Id, data.Data.Name, 8);
+ toggleFormAndLink("publisher")();
+ }
+ });
+
return false;
});
-
- $("#create-publisher-link").click(function() {
- var $form = $("#create-publisher-form");
- if ($form.is(":visible")) {
- $("#create-publisher-link").text("Create new publisher");
- } else {
- $("#create-publisher-link").text("Use existing publisher");
- }
-
- $form.toggle();
- $("#publisher-select").toggle();
+
+ $("#create-game-submit").click(function() {
+ var regions = [], publishers = [], systems = [];
+ $("input:checked[name='GameRegions']").each(function(index, input) { regions.push(input.value); });
+ $("input:checked[name='SystemIds']").each(function(index, input) { systems.push(input.value); });
+ $("input:checked[name='PublisherIds']").each(function(index, input) { publishers.push(input.value); });
+
+ $.ajax("/game/create", {
+ type: "POST",
+ data: {
+ Name: $("#GameName").val(),
+ Website: $("#GameWebsite").val(),
+ Region: regions,
+ SystemIds: systems,
+ PublisherIds: publishers
+ },
+ traditional: true,
+ success: function(data, statux, $xhr) {
+ if (data.Error !== null) {
+ alert(data.Error);
+ return;
+ }
+
+ $("#GameId")
+ .append($("").attr({ value: data.Data.Id}).text(data.Data.Name))
+ .val(data.Data.Id);
+
+ toggleFormAndLink("game")();
+ }
+ });
+
return false;
});