From 687d62912c9eea205306df17422dbdba718344a8 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 6 Apr 2017 11:38:15 -0400 Subject: [PATCH] add get/post for addwikicategory --- .../Controllers/DeveloperController.cs | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/Project-Unite/Controllers/DeveloperController.cs b/Project-Unite/Controllers/DeveloperController.cs index 9e3d6c0..f656132 100644 --- a/Project-Unite/Controllers/DeveloperController.cs +++ b/Project-Unite/Controllers/DeveloperController.cs @@ -140,6 +140,54 @@ namespace Project_Unite.Controllers var cats = db.WikiCategories; return View(cats); } + + public ActionResult AddWikiCategory() + { + if (!ACL.Granted(User.Identity.Name, "CanAccessDevCP")) + return new HttpStatusCodeResult(403); + + var mdl = new AddWikiCategoryViewModel(); + return View(mdl); + + } + + [HttpPost] + [ValidateAntiForgeryToken] + public ActionResult AddWikiCategory(AddWikiCategoryViewModel model) + { + if (!ACL.Granted(User.Identity.Name, "CanAccessDevCP")) + return new HttpStatusCodeResult(403); + + if (!ModelState.IsValid) + return View(model); + + var db = new ApplicationDbContext(); + var cat = new WikiCategory(); + + var new_id = model.Name.ToLower(); + + foreach(var c in new_id.ToArray()) + { + if(c == '.' || !ApprovedIdChars.Contains(c)) + { + new_id = new_id.Replace(c, '_'); + } + } + + cat.Id = new_id; + cat.Name = model.Name; + + cat.Parent = model.ParentId; + + db.WikiCategories.Add(cat); + db.SaveChanges(); + + return RedirectToAction("Wiki"); + + + + } + }