summaryrefslogtreecommitdiff
path: root/Project-Unite/Controllers
diff options
context:
space:
mode:
authorMichael <[email protected]>2017-04-07 09:57:24 -0400
committerMichael <[email protected]>2017-04-07 09:57:24 -0400
commit5860170c1fed2342232d7e35015b669e8b8ec471 (patch)
treebfd2113a5b98421c94344d313cf35c2d1e2d171c /Project-Unite/Controllers
parent6989516207321b6d99c6b04879b5a9a438527107 (diff)
downloadproject-unite-5860170c1fed2342232d7e35015b669e8b8ec471.tar.gz
project-unite-5860170c1fed2342232d7e35015b669e8b8ec471.tar.bz2
project-unite-5860170c1fed2342232d7e35015b669e8b8ec471.zip
Add "edit page" button to wiki
Diffstat (limited to 'Project-Unite/Controllers')
-rw-r--r--Project-Unite/Controllers/WikiControllerController.cs44
1 files changed, 44 insertions, 0 deletions
diff --git a/Project-Unite/Controllers/WikiControllerController.cs b/Project-Unite/Controllers/WikiControllerController.cs
index a8e9f26..391c57d 100644
--- a/Project-Unite/Controllers/WikiControllerController.cs
+++ b/Project-Unite/Controllers/WikiControllerController.cs
@@ -22,6 +22,50 @@ namespace Project_Unite.Controllers
return View(model);
}
+ [Authorize]
+ public ActionResult EditPage(string id)
+ {
+ var db = new ApplicationDbContext();
+ var model = new AddWikiPageViewModel();
+ var wiki = db.WikiPages.FirstOrDefault(x => x.Id == id);
+ if (wiki == null)
+ return new HttpStatusCodeResult(404);
+ model.Content = wiki.Contents;
+ model.Name = wiki.Name;
+ model.ParentId = wiki.CategoryId;
+ model.PageId = id;
+ return View(model);
+ }
+
+ [Authorize]
+ [ValidateAntiForgeryToken]
+ [HttpPost]
+ public ActionResult EditPage(AddWikiPageViewModel model)
+ {
+ if (!ModelState.IsValid)
+ return View(model);
+ var db = new ApplicationDbContext();
+
+ var wiki = db.WikiPages.FirstOrDefault(x => x.Id == model.PageId);
+ if (wiki == null)
+ return new HttpStatusCodeResult(404);
+ var edit = new ForumPostEdit();
+ edit.PreviousState = wiki.Contents;
+ edit.EditedAt = DateTime.Now;
+ edit.UserId = User.Identity.GetUserId();
+ edit.Id = Guid.NewGuid().ToString();
+ edit.Parent = wiki.Id;
+
+ db.ForumPostEdits.Add(edit);
+
+ wiki.Contents = model.Content;
+ wiki.CategoryId = model.ParentId;
+
+ db.SaveChanges();
+
+ return RedirectToAction("Index", new { id = model.PageId });
+ }
+
public ActionResult Random()
{
var db = new ApplicationDbContext();