uploading game icons
This commit is contained in:
parent
ff3499b3b9
commit
e2bb88498d
@ -91,4 +91,14 @@ namespace VideoGameQuotes.Api {
|
|||||||
public IEnumerable<PublisherDto> Publishers { get; set; }
|
public IEnumerable<PublisherDto> Publishers { get; set; }
|
||||||
public IEnumerable<string> Regions { get; set; }
|
public IEnumerable<string> Regions { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class GameExtensions {
|
||||||
|
public static string GetBase64EncodedIcon(this Game game) {
|
||||||
|
if (game.Icon == null || game.Icon.Length == 0) {
|
||||||
|
return "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAHBSURBVDjLlVM9aMJQEP6eNEF0sbiUouLgoLRkKXS1IG4dC6Xg2LXQRXATHbqVzq4iQjc3sVscnUSnYIdIB9GC4L/xL333IEFsBj04jpf77nt3l+8x0zRxaMViMbTdbtXVahVer9dYLBY/0+k0mcvltEPsGRzMMIyPQCAQ9ng8IAJd14OdTuedp+4PsS4ngslkctFoNNBsNgWB2+3GaDQKOWEdCTgY2WyW9Xo9QbBcLoUfTSDLsoiMMUFgkRxNwHeAdDpt+nw+8EUKp29O5rhEvnEoigJJktBqteD3+0/rgINNulHTNCjzGR5++1Bvb67x+vLF/dmxg3K5HOZB2+12MncxfzAYxJ25wcXjE5ixZCu9m/wufybfUqnLUqmUtwmomAtKi0ajcrVaxWAwQKFQEHOfK1dQajUwrwdSrw8ZEiKRSC4ej0NV1TwjJXI2IxaLyZwA4/FYFHL12T6fz+3o9XrhcrmQyWTQbreZ6IAnZS5dVCoVEpFYmFVEPpvNxJm+0zmRSIhoj0AJunU4HNogq3C/EwtHuqBfaxNQkhJ8NpGwAPtxs9n8c5ug2+2iXq/bojl0S41URKPuv2Dm9JxPsT8W0mO2IJm2EgAAAABJRU5ErkJggg==";
|
||||||
|
}
|
||||||
|
|
||||||
|
return Convert.ToBase64String(game.Icon);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using System.Linq;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Portoa.Persistence;
|
using Portoa.Persistence;
|
||||||
using Portoa.Util;
|
using Portoa.Util;
|
||||||
@ -47,15 +48,24 @@ namespace VideoGameQuotes.Web.Controllers {
|
|||||||
ModelState.AddModelError("GameId", "Invalid game ID");
|
ModelState.AddModelError("GameId", "Invalid game ID");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var icon = new byte[0];
|
||||||
|
if (model.GameIcon != null) {
|
||||||
|
icon = Convert.FromBase64String(model.GameIcon);
|
||||||
|
if (icon.Length > 1024) {
|
||||||
|
ModelState.AddModelError("GameIcon", "Icon must be smaller than 1KB");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!ModelState.IsValid) {
|
if (!ModelState.IsValid) {
|
||||||
return Json(this.CreateJsonErrorResponse("Some errors occurred"));
|
return Json(this.CreateJsonErrorResponse("Some errors occurred"));
|
||||||
}
|
}
|
||||||
|
|
||||||
var game = gameService.FindById(model.GameId);
|
var game = gameService.FindById(model.GameId);
|
||||||
game.Name = model.GameName;
|
game.Name = model.GameName;
|
||||||
|
game.Icon = icon;
|
||||||
game.Region = model.GameRegions;
|
game.Region = model.GameRegions;
|
||||||
game.Website = model.GameWebsite;
|
game.Website = model.GameWebsite;
|
||||||
|
|
||||||
game.ClearPublishers();
|
game.ClearPublishers();
|
||||||
game.ClearSystems();
|
game.ClearSystems();
|
||||||
(model.PublisherIds ?? Enumerable.Empty<int>()).Walk(id => game.AddPublisher(new Publisher { Id = id }));
|
(model.PublisherIds ?? Enumerable.Empty<int>()).Walk(id => game.AddPublisher(new Publisher { Id = id }));
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Web;
|
|
||||||
using VideoGameQuotes.Api;
|
using VideoGameQuotes.Api;
|
||||||
|
|
||||||
namespace VideoGameQuotes.Web.Models {
|
namespace VideoGameQuotes.Web.Models {
|
||||||
@ -16,7 +15,7 @@ namespace VideoGameQuotes.Web.Models {
|
|||||||
public List<int> PublisherIds { get; set; }
|
public List<int> PublisherIds { get; set; }
|
||||||
[Required(ErrorMessage = "At least one system must be specified, uglyface")]
|
[Required(ErrorMessage = "At least one system must be specified, uglyface")]
|
||||||
public List<int> SystemIds { get; set; }
|
public List<int> SystemIds { get; set; }
|
||||||
public HttpPostedFileBase GameIcon { get; set; }
|
public string GameIcon { get; set; }
|
||||||
public int GameId { get; set; }
|
public int GameId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -48,6 +48,7 @@ namespace VideoGameQuotes.Web.Models {
|
|||||||
public IEnumerable<Publisher> AllPublishers { get; set; }
|
public IEnumerable<Publisher> AllPublishers { get; set; }
|
||||||
public IEnumerable<Category> AllCategories { get; set; }
|
public IEnumerable<Category> AllCategories { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public IEnumerable<SelectListItem> GetGameList() {
|
public IEnumerable<SelectListItem> GetGameList() {
|
||||||
return AllGames.Select(game => new SelectListItem { Value = game.Id.ToString(), Text = game.Name });
|
return AllGames.Select(game => new SelectListItem { Value = game.Id.ToString(), Text = game.Name });
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,14 @@
|
|||||||
<%= Html.TextBox("GameWebsite") %>
|
<%= Html.TextBox("GameWebsite") %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<% if (Model.CurrentUser != null && Model.CurrentUser.Group >= UserGroup.Admin) { %>
|
||||||
|
<p>
|
||||||
|
<%= Html.Label("Icon", "GameIcon", new { @class = "label" })%>
|
||||||
|
<br />
|
||||||
|
<%= Html.TextBox("GameIcon") %>
|
||||||
|
</p>
|
||||||
|
<% } %>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<span id="GameRegions" class="label">Regions</span>
|
<span id="GameRegions" class="label">Regions</span>
|
||||||
<br />
|
<br />
|
||||||
|
@ -43,7 +43,12 @@
|
|||||||
|
|
||||||
<div class="quote-categories">
|
<div class="quote-categories">
|
||||||
<ul class="menu clearfix">
|
<ul class="menu clearfix">
|
||||||
<li><%= Html.ActionLink(Model.Quote.Game.Name, "browse", "Quote", new { qualifiers = "game/" + Model.Quote.Game.Id }, new { @class = "quote-game-link", title = string.Format("browse quotes from the game \"{0}\"", Model.Quote.Game.Name) }) %></li>
|
<li>
|
||||||
|
<a class="game-link" href="<%= Url.Action("browse", "quote", new { qualifiers = "game/" + Model.Quote.Game.Id }) %>" title="browse quotes from the game "<%: Model.Quote.Game.Name %>"">
|
||||||
|
<img src="data:image/png;base64,<%= Model.Quote.Game.GetBase64EncodedIcon() %>" alt="icon" />
|
||||||
|
<%: Model.Quote.Game.Name %>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
<% foreach (var category in Model.Quote.Categories.OrderBy(category => category.Name)) { %>
|
<% foreach (var category in Model.Quote.Categories.OrderBy(category => category.Name)) { %>
|
||||||
<li><%= Html.ActionLink(category.Name, "browse", "Quote", new { qualifiers = "category/" + category.Id }, new { title = string.Format("browse quotes categorized as \"{0}\"", category.Name) })%></li>
|
<li><%= Html.ActionLink(category.Name, "browse", "Quote", new { qualifiers = "category/" + category.Id }, new { title = string.Format("browse quotes categorized as \"{0}\"", category.Name) })%></li>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
Loading…
Reference in New Issue
Block a user