From 1675a18905e395320da710485c4052a3f28606dc Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 6 Apr 2017 15:13:41 -0400 Subject: "Random page" link in wiki --- Project-Unite/Controllers/WikiControllerController.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'Project-Unite/Controllers/WikiControllerController.cs') diff --git a/Project-Unite/Controllers/WikiControllerController.cs b/Project-Unite/Controllers/WikiControllerController.cs index f6b09cd..435e5bd 100644 --- a/Project-Unite/Controllers/WikiControllerController.cs +++ b/Project-Unite/Controllers/WikiControllerController.cs @@ -20,6 +20,18 @@ namespace Project_Unite.Controllers return View(model); } + public ActionResult Random() + { + var db = new ApplicationDbContext(); + var rnd = new Random(); + var index = rnd.Next(0, db.WikiPages.Count()); + if (db.WikiPages.Count() == 0) + return RedirectToAction("Index"); + + var wiki = db.WikiPages.ToArray()[index].Id; + return RedirectToAction("Index", new { id = wiki }); + } + [Authorize] public ActionResult AddPage() { -- cgit v1.2.3