add get/post for addwikicategory

This commit is contained in:
Michael 2017-04-06 11:38:15 -04:00
parent 1f6ab0dbbe
commit 687d62912c

View file

@ -140,6 +140,54 @@ public ActionResult Wiki()
var cats = db.WikiCategories; var cats = db.WikiCategories;
return View(cats); 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");
}
} }