Example #1
0
        public IActionResult PostNewHomepageItem([FromForm] HomePageItem item)
        {
            if (UserHasAdminRoles() == false)
            {
                return(View("_Error", "You are not authorized to do this"));
            }

            using (var db = new ChaliceDb())
            {
                db.BeginTransaction();

                db.InsertWithIdentity(new Article
                {
                    Section  = "homepage",
                    Title    = item.Title,
                    Content  = item.Content,
                    PostedBy = User.Identity.Name,
                    Posted   = System.DateTime.Now
                });

                db.InsertWithIdentity(new UserHistory
                {
                    UserName = User.Identity.Name,
                    Action   = "new_article",
                    Target   = "homepage",
                    Value    = item.Title,
                    Created  = System.DateTime.Now
                });

                db.CommitTransaction();
            }

            return(Redirect("/"));
        }
Example #2
0
 public IEnumerable <int> AllBosses()
 {
     using (var db = new ChaliceDb())
     {
         return(db.DungeonBosses.Select(b => b.Id).ToList());
     }
 }
Example #3
0
 public DungeonGlyph GlyphById(string id)
 {
     using (var db = new ChaliceDb())
     {
         return(db.DungeonGlyphs.FirstOrDefault(g => g.Glyph == id));
     }
 }
Example #4
0
 public IEnumerable <string> AllChalices()
 {
     using (var db = new ChaliceDb())
     {
         return(db.RootChalices.Select(c => c.ChaliceId).ToList());
     }
 }
Example #5
0
 public DungeonBoss BossById(int id)
 {
     using (var db = new ChaliceDb())
     {
         return(db.DungeonBosses.FirstOrDefault(b => b.Id == id));
     }
 }
Example #6
0
 public RootChalice ChaliceById(string id)
 {
     using (var db = new ChaliceDb())
     {
         return(db.RootChalices.FirstOrDefault(b => b.ChaliceId == id));
     }
 }
        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 bool SubmitComment([FromBody] CommentSubmissionModel cm)
        {
            var sanitizer = new Ganss.XSS.HtmlSanitizer();

            using (var db = new ChaliceDb())
            {
                db.BeginTransaction();

                var comment = new Comment
                {
                    Glyph       = cm.Glyph,
                    CommentText = sanitizer.Sanitize(cm.Text),
                    PostedBy    = User.Identity.Name,
                    Posted      = System.DateTime.Now
                };

                var history = new UserHistory
                {
                    UserName = User.Identity.Name,
                    Action   = "comment",
                    Target   = cm.Glyph,
                    Value    = "",
                    Created  = System.DateTime.Now
                };

                db.InsertWithIdentity(comment);
                db.InsertWithIdentity(history);

                db.CommitTransaction();
            }

            return(true);
        }
Example #9
0
 public IEnumerable <int> AllLoot()
 {
     using (var db = new ChaliceDb())
     {
         return(db.Loot.Select(l => l.Id).ToList());
     }
 }
Example #10
0
 public Loot LootById(int id)
 {
     using (var db = new ChaliceDb())
     {
         return(db.Loot.FirstOrDefault(l => l.Id == id));
     }
 }
Example #11
0
        public IActionResult Index()
        {
            var model = new HomeViewStats();

            using (var db = new ChaliceDb())
            {
                model.LatestGlyph = db.DungeonGlyphs
                                    .OrderByDescending(d => d.Updated)
                                    .FirstOrDefault()
                                    ?.Glyph;

                var mostSubmittedQuery = (from entry in db.DungeonGlyphs
                                          group entry by entry.Submitter into entries
                                          let count = entries.Count()
                                                      orderby count descending
                                                      select new { Submitter = entries.Key, Count = count })
                                         .FirstOrDefault();

                if (mostSubmittedQuery != null)
                {
                    model.MostSubmissions = new Tuple <string, int>(mostSubmittedQuery.Submitter, mostSubmittedQuery.Count);
                }

                model.Articles = db.Articles.OrderByDescending(a => a.Posted).Take(5).ToList();
            }

            ViewBag.TestString = Startup.ConnectionString;

            return(View(model));
        }
Example #12
0
 public IEnumerable <string> AllGlyphIds()
 {
     using (var db = new ChaliceDb())
     {
         return(db.DungeonGlyphs.Select(g => g.Glyph).ToList());
     }
 }
Example #13
0
        public IActionResult LoadGlyphsByBoss(string bossId)
        {
            var resultList = new List <SearchResultEntry>();

            using (var db = new ChaliceDb())
            {
                var glyphs = db
                             .Query <DungeonGlyph>(
                    $"SELECT Glyph, ShortDescription, RootChalice, Submitter, Upvotes, Downvotes, Closedvotes Updated FROM DungeonGlyphs WHERE(',' + RTRIM(Bosses) + ';') LIKE '%;{bossId};%'")
                             .ToList();

                foreach (var g in glyphs)
                {
                    if (resultList.Any(x => x.Glyph == g.Glyph))
                    {
                        continue;
                    }
                    resultList.Add(new SearchResultEntry
                    {
                        Glyph            = g.Glyph,
                        ShortDescription = g.ShortDescription,
                        RootChalice      = db.RootChalices.FirstOrDefault(r => r.ChaliceId == g.RootChalice).ChaliceName,
                        Submitter        = g.Submitter,
                        Upvotes          = g.Upvotes,
                        Downvotes        = g.Downvotes,
                        Closedvotes      = g.ClosedVotes,
                        Updated          = g.Updated
                    });
                }
            }

            return(PartialView("Lists/_GlyphsResultView", resultList));
        }
Example #14
0
        public IActionResult UserManagement()
        {
            using (var db = new ChaliceDb())
            {
                var model = db.Users.ToList();

                return(View(model));
            }
        }
Example #15
0
        public IActionResult ViewPost(int id)
        {
            using (var db = new ChaliceDb())
            {
                var article = db.Articles.FirstOrDefault(a => a.Id == id);

                return(View(article));
            }
        }
Example #16
0
        public IActionResult RebuildGlyphVotes([FromBody] string glyphId)
        {
            if (UserHasAdminRoles() == false)
            {
                return(View("_Error", "You are not authorized to do this"));
            }

            ChaliceDb.RebuildGlyphVotes(glyphId);

            return(Ok("rebuild"));
        }
Example #17
0
        public IActionResult GlyphsByBoss()
        {
            var model = new List <DungeonBoss>();

            using (var db = new ChaliceDb())
            {
                model.AddRange(db.DungeonBosses.ToList());
            }

            return(View(model));
        }
Example #18
0
        public IActionResult GlyphsByLoot()
        {
            List <Loot> model = new List <Loot>();

            using (var db = new ChaliceDb())
            {
                model.AddRange(db.Loot.ToList());
            }

            return(View(model));
        }
Example #19
0
        public IActionResult GlyphsByRootChalices()
        {
            var model = new List <RootChalice>();

            using (var db = new ChaliceDb())
            {
                model.AddRange(db.RootChalices.ToList());
            }

            return(View(model));
        }
        public IActionResult Search()
        {
            var query      = Request.Query["q"];
            var searchType = Request.Query["t"];

            var model = ChaliceDb.SearchGlyph(query, searchType);

            ViewBag.SearchQuery = query;
            ViewBag.SearchType  = searchType;

            return(View(model));
        }
Example #21
0
        public IActionResult LoadGlyphsByRootChalice(string chaliceId, string rites)
        {
            var resultList = new List <SearchResultEntry>();

            using (var db = new ChaliceDb())
            {
                var glyphsQuery = db.DungeonGlyphs.Where(d => d.RootChalice == chaliceId);

                if (rites != "all")
                {
                    string[] ritesArr = rites.Split(",", System.StringSplitOptions.RemoveEmptyEntries);
                    foreach (var r in ritesArr)
                    {
                        switch (r)
                        {
                        case "fetid": glyphsQuery = glyphsQuery.Where(g => g.Fetid); break;

                        case "rotted": glyphsQuery = glyphsQuery.Where(g => g.Rotted); break;

                        case "cursed": glyphsQuery = glyphsQuery.Where(g => g.Cursed); break;

                        case "sinister": glyphsQuery = glyphsQuery.Where(g => g.Sinister); break;

                        case "saveedit": glyphsQuery = glyphsQuery.Where(g => g.SaveEdited); break;
                        }
                    }
                }

                var glyphs = glyphsQuery.ToList();

                foreach (var g in glyphs)
                {
                    if (resultList.Any(x => x.Glyph == g.Glyph))
                    {
                        continue;
                    }
                    resultList.Add(new SearchResultEntry
                    {
                        Glyph            = g.Glyph,
                        ShortDescription = g.ShortDescription,
                        RootChalice      = db.RootChalices.FirstOrDefault(r => r.ChaliceId == g.RootChalice).ChaliceName,
                        Submitter        = g.Submitter,
                        Upvotes          = g.Upvotes,
                        Downvotes        = g.Downvotes,
                        Closedvotes      = g.ClosedVotes,
                        Updated          = g.Updated
                    });
                }
            }

            return(PartialView("Lists/_GlyphsResultView", resultList));
        }
        public IActionResult AddGlyph()
        {
            var model = new AddGlyphModel();

            using (var db = new ChaliceDb())
            {
                model.RootChalices = db.RootChalices.OrderBy(c => c.ChaliceName).ToList();
                model.Bosses       = db.DungeonBosses.OrderBy(b => b.BossName).ToList();
                model.Loot         = db.Loot.OrderBy(l => l.ItemName).ToList();
            }

            return(View(model));
        }
        public IActionResult Edit(string glyph)
        {
            var model = new EditGlyphModel();

            using (var db = new ChaliceDb())
            {
                model.Dungeon = db.DungeonGlyphs.FirstOrDefault(g => g.Glyph == glyph);

                if (model.Dungeon == null)
                {
                    return(View("_Error", "Glyph not found"));
                }

                foreach (var bossIdString in model.Dungeon.Bosses.Split(';', System.StringSplitOptions.RemoveEmptyEntries))
                {
                    var id   = int.Parse(bossIdString);
                    var boss = db.DungeonBosses.FirstOrDefault(b => b.Id == id);
                    model.Bosses.Add(boss);
                }

                foreach (var lootIdString in model.Dungeon.Loot.Split(';', System.StringSplitOptions.RemoveEmptyEntries))
                {
                    var id   = int.Parse(lootIdString);
                    var loot = db.Loot.FirstOrDefault(l => l.Id == id);
                    model.Loot.Add(loot);
                }

                model.RootChaliceDisplayName = db.RootChalices.FirstOrDefault(c => c.ChaliceId == model.Dungeon.RootChalice).ChaliceName;

                model.Lists.RootChalices = db.RootChalices.OrderBy(c => c.ChaliceName).ToList();
                model.Lists.Bosses       = db.DungeonBosses.OrderBy(b => b.BossName).ToList();
                model.Lists.Loot         = db.Loot.OrderBy(l => l.ItemName).ToList();
            }

            string ssDirPath = Path.Combine("wwwroot", "Screenshots", glyph);

            if (Directory.Exists(ssDirPath))
            {
                string[] files = Directory.GetFiles(ssDirPath);

                foreach (var file in files)
                {
                    var fileName = Path.GetFileName(file);
                    model.Screenshots.Add(fileName);
                }
            }

            ViewBag.CurrentGlyph = model.Dungeon.Glyph;

            return(View("EditGlyph", model));
        }
        public IActionResult LoadComments(string glyph)
        {
            var model = new CommentsViewModel
            {
                Glyph = glyph
            };

            using (var db = new ChaliceDb())
            {
                model.Comments.AddRange(db.Comments.Where(c => c.Glyph == glyph).OrderByDescending(c => c.Posted).ToList());
            }

            return(PartialView("_CommentList", model));
        }
        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 IActionResult ViewGlyph(string glyph)
        {
            var model = new ViewGlyphModel();

            using (var db = new ChaliceDb())
            {
                model.Dungeon = db.DungeonGlyphs.FirstOrDefault(g => g.Glyph == glyph);

                if (model.Dungeon == null)
                {
                    return(View("_Error", "Glyph not found"));
                }

                foreach (var bossIdString in model.Dungeon.Bosses.Split(';', System.StringSplitOptions.RemoveEmptyEntries))
                {
                    var id   = int.Parse(bossIdString);
                    var boss = db.DungeonBosses.FirstOrDefault(b => b.Id == id);
                    model.Bosses.Add(boss);
                }

                foreach (var lootIdString in model.Dungeon.Loot.Split(';', System.StringSplitOptions.RemoveEmptyEntries))
                {
                    var id   = int.Parse(lootIdString);
                    var loot = db.Loot.FirstOrDefault(l => l.Id == id);
                    model.Loot.Add(loot);
                }

                model.RootChaliceDisplayName = db.RootChalices.FirstOrDefault(c => c.ChaliceId == model.Dungeon.RootChalice).ChaliceName;

                var usrname = HttpContext.User.Identity.Name;
                model.HasVoted = db.UserHistory.Any(h => h.UserName == usrname && h.Action == "vote" && h.Target == glyph);

                string ssDirPath = Path.Combine("wwwroot", "Screenshots", glyph);
                if (Directory.Exists(ssDirPath))
                {
                    string[] files = Directory.GetFiles(ssDirPath);

                    foreach (var file in files)
                    {
                        var fileName = Path.GetFileName(file);
                        model.Screenshots.Add(fileName);
                    }
                }
            }

            ViewBag.CurrentGlyph = model.Dungeon.Glyph;
            return(View(model));
        }
Example #27
0
        public List <DungeonBoss> GetBossObjects()
        {
            var list = new List <DungeonBoss>();

            using (var db = new ChaliceDb())
            {
                foreach (var bossIdString in Bosses.Split(';'))
                {
                    var id   = int.Parse(bossIdString);
                    var boss = db.DungeonBosses.FirstOrDefault(b => b.Id == id);
                    list.Add(boss);
                }
            }

            return(list);
        }
Example #28
0
        public IActionResult DeleteGlyph([FromBody] string glyphId)
        {
            if (UserHasAdminRoles() == false)
            {
                return(View("_Error", "You are not authorized to do this"));
            }

            // Delete glyph and associated history items (created + votes)
            using (var db = new ChaliceDb())
            {
                db.BeginTransaction();

                db.DungeonGlyphs.Delete(d => d.Glyph == glyphId);
                db.UserHistory.Delete(h => h.Target == glyphId);

                db.CommitTransaction();
            }

            return(Ok("deleted"));
        }
Example #29
0
        public IActionResult DeleteUser([FromBody] int userId)
        {
            if (UserHasAdminRoles() == false)
            {
                return(View("_Error", "You are not authorized to do this"));
            }

            using (var db = new ChaliceDb())
            {
                db.BeginTransaction();

                var user = db.Users.FirstOrDefault(u => u.Id == userId);

                if (user == null)
                {
                    return(NotFound("user not found"));
                }

                var glyphs = db.DungeonGlyphs.Where(g => g.Submitter == user.UserName).ToList();
                if (glyphs.Count > 0)
                {
                    foreach (var g in glyphs)
                    {
                        g.Submitter = "[RemovedUser]";
                        db.Update(g);
                    }
                }

                db.Users.Delete(u => u.Id == userId);
                db.UserHistory.Delete(h => h.UserName == user.UserName);

                db.CommitTransaction();
            }

            return(Ok("user deleted"));
        }
        public bool SubmitVote([FromBody] VotePackageModel vote)
        {
            using (var db = new ChaliceDb())
            {
                db.BeginTransaction();

                var glyph = db.DungeonGlyphs.FirstOrDefault(d => d.Glyph == vote.Glyph);
                switch (vote.Vote.ToLower())
                {
                case "up":
                    glyph.Upvotes += 1;
                    break;

                case "down":
                    glyph.Downvotes += 1;
                    break;

                case "retract":
                {
                    var prevVote = db.UserHistory.FirstOrDefault(h => h.UserName == User.Identity.Name && h.Target == vote.Glyph && h.Action == "vote");
                    switch (prevVote.Value)
                    {
                    case "up": glyph.Upvotes -= 1; break;

                    case "down": glyph.Downvotes -= 1; break;

                    case "closed": glyph.ClosedVotes -= 1; break;
                    }
                    db.Delete(prevVote);
                }
                break;

                case "closed":
                {
                    // Delete previous vote if needed
                    var prevVote = db.UserHistory.FirstOrDefault(h => h.UserName == User.Identity.Name && h.Target == vote.Glyph && h.Action == "vote");
                    if (prevVote != null)
                    {
                        switch (prevVote.Value)
                        {
                        case "up": glyph.Upvotes -= 1; break;

                        case "down": glyph.Downvotes -= 1; break;
                        }
                        db.Delete(prevVote);
                    }
                    glyph.ClosedVotes += 1;
                }
                break;
                }

                db.Update(glyph);

                // Don't write history for vote retraction
                if (vote.Vote.ToLower() != "retract")
                {
                    db.InsertWithIdentity(new UserHistory
                    {
                        UserName = User.Identity.Name,
                        Action   = "vote",
                        Target   = vote.Glyph,
                        Value    = vote.Vote,
                        Created  = System.DateTime.Now
                    });
                }

                db.CommitTransaction();
            }

            return(true);
        }