diff options
| author | Michael <[email protected]> | 2017-04-06 15:08:47 -0400 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-04-06 15:08:47 -0400 |
| commit | e28195596b54360767a50be97f7976d7f8004aa3 (patch) | |
| tree | d20a7ce35d9e816b2a55978f1d0be0b282af9745 /Project-Unite/Controllers/WikiControllerController.cs | |
| parent | eb6e71596650fdfa29322fde4892eb94209676c2 (diff) | |
| download | project-unite-e28195596b54360767a50be97f7976d7f8004aa3.tar.gz project-unite-e28195596b54360767a50be97f7976d7f8004aa3.tar.bz2 project-unite-e28195596b54360767a50be97f7976d7f8004aa3.zip | |
"Add Wiki Page" page added.'
Diffstat (limited to 'Project-Unite/Controllers/WikiControllerController.cs')
| -rw-r--r-- | Project-Unite/Controllers/WikiControllerController.cs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/Project-Unite/Controllers/WikiControllerController.cs b/Project-Unite/Controllers/WikiControllerController.cs index b49a39e..f6b09cd 100644 --- a/Project-Unite/Controllers/WikiControllerController.cs +++ b/Project-Unite/Controllers/WikiControllerController.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; +using Microsoft.AspNet.Identity; using Project_Unite.Models; namespace Project_Unite.Controllers @@ -18,5 +19,48 @@ namespace Project_Unite.Controllers model.Page = db.WikiPages.FirstOrDefault(x => x.Id == id); return View(model); } + + [Authorize] + public ActionResult AddPage() + { + return View(new AddWikiPageViewModel()); + } + + [Authorize] + [HttpPost] + [ValidateAntiForgeryToken] + public ActionResult AddPage(AddWikiPageViewModel model) + { + if (!ModelState.IsValid) + return View(model); + + var db = new ApplicationDbContext(); + var page = new WikiPage(); + page.CategoryId = model.ParentId; + page.Contents = model.Content; + page.Name = model.Name; + + string allowed = "abcdefghijklmnopqrstuvwxyz1234567890_"; + page.Id = page.Name.ToLower(); + foreach(var c in page.Id.ToCharArray()) + { + if (!allowed.Contains(c)) + page.Id = page.Id.Replace(c, '_'); + } + + var edit = new ForumPostEdit(); + edit.Id = Guid.NewGuid().ToString(); + edit.Parent = page.Id; + edit.EditedAt = DateTime.Now; + edit.EditReason = "Page created."; + edit.PreviousState = page.Contents; + edit.UserId = User.Identity.GetUserId(); + + db.ForumPostEdits.Add(edit); + db.WikiPages.Add(page); + db.SaveChanges(); + + return RedirectToAction("Index", new { id = edit.Id }); + } } }
\ No newline at end of file |
