Fix bug with skin repo page IDs

This commit is contained in:
Michael 2017-04-12 19:01:27 -04:00
parent da39089abf
commit db70be6c4b
2 changed files with 13 additions and 3 deletions

View file

@ -20,7 +20,7 @@ public ActionResult Index()
public ActionResult ViewSkin(string id)
{
var db = new ApplicationDbContext();
var skn = db.Skins.FirstOrDefault(x => x.Name == id);
var skn = db.Skins.FirstOrDefault(x => x.Id == id);
if (skn == null)
return new HttpStatusCodeResult(404);
return View(skn);
@ -44,7 +44,17 @@ public ActionResult PostSkin(CreateSkinViewModel model)
}
var db = new ApplicationDbContext();
var skin = new Skin();
skin.Id = Guid.NewGuid().ToString();
string allowed = "abcdefghijklmnopqrstuvwxyz1234567890-_";
string id = model.Title.ToLower();
foreach(char c in id.ToCharArray())
{
if (!allowed.Contains(c))
id = id.Replace(c, '_');
}
skin.Id = id;
skin.Name = model.Title;
skin.ShortDescription = model.ShortDescription;
skin.PostedAt = DateTime.Now;

View file

@ -28,7 +28,7 @@
<tr>
<td><img src="@skin.ScreenshotUrl" style="max-width:320px;width:auto;height:auto;"/></td>
<td>
@Html.ActionLink(skin.Name, "ViewSkin", "Skins", new { id = skin.Name }, null) <br/>
@Html.ActionLink(skin.Name, "ViewSkin", "Skins", new { id = skin.Id }, null) <br/>
<p>By @Html.UserLink(skin.UserId) on @skin.PostedAt</p>
</td>
<td>