public IActionResult SubmitNewGlyph(SubmitGlyphModel glyph) { var sanitizer = new Ganss.XSS.HtmlSanitizer(); glyph.Submitter = HttpContext.User.Identity.Name; glyph.Notes = sanitizer.Sanitize(glyph.Notes); if (glyph.Screenshots != null && glyph.Screenshots.Count > 0) { string[] validFileTypes = { "image/jpeg", "image/gif", "image/png" }; foreach (var file in glyph.Screenshots) { if (file.Length < 0) { continue; } if (validFileTypes.Contains(file.ContentType) == false) { continue; } SaveImage(glyph.DungeonGlyph, file); } } string res = ChaliceDb.NewGlyphFromModel(glyph); if (res == "<EXISTS>") { return(View("_Error", "This glyph alreadt exists")); } return(Redirect($"/dungeon/viewglyph/{res}")); }
public IActionResult SubmitGlyphEdit(SubmitGlyphModel glp) { var sanitizer = new Ganss.XSS.HtmlSanitizer(); glp.Submitter = HttpContext.User.Identity.Name; glp.Notes = sanitizer.Sanitize(glp.Notes); string ssDirPath = Path.Combine("wwwroot", "Screenshots", glp.DungeonGlyph); if (glp.DeletedImages != null) { var ids = glp.DeletedImages.Split(';'); foreach (var id in ids) { var mainFile = Path.Combine(ssDirPath, $"{id}.png"); var thumbFile = Path.Combine(ssDirPath, $"{id}-thumb.png"); if (FileIo.Exists(mainFile)) { FileIo.Delete(mainFile); } if (FileIo.Exists(thumbFile)) { FileIo.Delete(thumbFile); } } } if (glp.Screenshots != null && glp.Screenshots.Count > 0) { string[] validFileTypes = { "image/jpeg", "image/gif", "image/png" }; foreach (var file in glp.Screenshots) { if (file.Length <= 0) { continue; } if (validFileTypes.Contains(file.ContentType) == false) { continue; // Skip when file is not a supported imagetype } SaveImage(glp.DungeonGlyph, file); } } ChaliceDb.UpdateGlyphFromModel(glp); return(Redirect($"/dungeon/viewglyph/{glp.DungeonGlyph}")); }
public static string NewGlyphFromModel(SubmitGlyphModel glyph) { var hs = new Ganss.XSS.HtmlSanitizer(); var nGlyph = new DungeonGlyph { Glyph = hs.Sanitize(glyph.DungeonGlyph), ShortDescription = hs.Sanitize(glyph.ShortDescription), Layers = glyph.Layers, RootChalice = glyph.RootChalice, Fetid = glyph.Fetid, Rotted = glyph.Rotted, Cursed = glyph.Cursed, Sinister = glyph.Sinister, SaveEdited = glyph.SaveEdited, Bosses = $";{string.Join(';', glyph.Bosses)};", Notes = hs.Sanitize(glyph.Notes), Submitter = glyph.Submitter, Upvotes = 1, Downvotes = 0, Updated = DateTime.Now }; using (var db = new ChaliceDb()) { // Check if glyph exists if (db.DungeonGlyphs.Any(g => g.Glyph == nGlyph.Glyph)) { return("<EXISTS>"); } nGlyph.Loot = $";{VerifyLootList(glyph.Loot)};"; db.Insert(nGlyph); db.InsertWithIdentity(new UserHistory { UserName = nGlyph.Submitter, Target = nGlyph.Glyph, Action = "new_glyph", Value = nGlyph.Glyph, Created = DateTime.Now }); return(nGlyph.Glyph); } }
internal static bool UpdateGlyphFromModel(SubmitGlyphModel glp) { var hs = new Ganss.XSS.HtmlSanitizer(); using (var db = new ChaliceDb()) { db.DungeonGlyphs .Where(d => d.Glyph == glp.DungeonGlyph) .Set(d => d.RootChalice, hs.Sanitize(glp.RootChalice)) .Set(d => d.Fetid, glp.Fetid) .Set(d => d.Rotted, glp.Rotted) .Set(d => d.Cursed, glp.Cursed) .Set(d => d.Sinister, glp.Sinister) .Set(d => d.SaveEdited, glp.SaveEdited) .Set(d => d.Bosses, $";{string.Join(';', glp.Bosses)};") .Set(d => d.Loot, $";{VerifyLootList(glp.Loot)};") .Set(d => d.Notes, hs.Sanitize(glp.Notes)) .Set(d => d.Updated, DateTime.Now) .Update(); } return(true); }