Пример #1
0
        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}"));
        }