diff options
| author | Michael <[email protected]> | 2017-05-31 18:41:36 -0400 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-05-31 18:41:36 -0400 |
| commit | 82c0215b9743c8cc7e90a054b6cff9fb8f6cebe7 (patch) | |
| tree | 6e87b173f9650fc6c5a8e772f70ebe00d22614e8 /Project-Unite/Controllers | |
| parent | 1dcba9a68839ac0eac372030b20d9c0c8f2f8e0e (diff) | |
| download | project-unite-82c0215b9743c8cc7e90a054b6cff9fb8f6cebe7.tar.gz project-unite-82c0215b9743c8cc7e90a054b6cff9fb8f6cebe7.tar.bz2 project-unite-82c0215b9743c8cc7e90a054b6cff9fb8f6cebe7.zip | |
User-submitted quotes.
Diffstat (limited to 'Project-Unite/Controllers')
| -rw-r--r-- | Project-Unite/Controllers/QuotesController.cs | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/Project-Unite/Controllers/QuotesController.cs b/Project-Unite/Controllers/QuotesController.cs new file mode 100644 index 0000000..cce8f24 --- /dev/null +++ b/Project-Unite/Controllers/QuotesController.cs @@ -0,0 +1,82 @@ +using System; +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 +{ + [Authorize] + public class QuotesController : Controller + { + // GET: Quotes + public ActionResult Index() + { + return View(); + } + + [HttpPost] + [ValidateAntiForgeryToken] + public ActionResult Index(Models.Quote model) + { + if (!ModelState.IsValid) + return View(model); + + var db = new Models.ApplicationDbContext(); + model.Id = (db.Quotes.Count() + 1).ToString(); + model.IsApproved = false; + db.Quotes.Add(model); + db.SaveChanges(); + + var users = db.Users.ToArray(); + foreach (var user in users) + { + try + { + if (user.HighestRole.IsAdmin) + { + NotificationDaemon.NotifyUser(User.Identity.GetUserId(), user.Id, "New quote submitted.", "Please review user-submitted quotes.", Url.Action("ReviewAll")); + } + } + catch { } + } + return View(model); + } + + [RequiresModerator] + public ActionResult ReviewAll() + { + var db = new ApplicationDbContext(); + return View(db.Quotes.Where(x => x.IsApproved == false)); + } + + [RequiresModerator] + public ActionResult Deny(string id) + { + var db = new ApplicationDbContext(); + var quote = db.Quotes.FirstOrDefault(x => x.Id == id); + if (quote == null) + return new HttpStatusCodeResult(404); + if (quote.IsApproved == true) + return new HttpStatusCodeResult(403); + db.Quotes.Remove(quote); + db.SaveChanges(); + return RedirectToAction("ReviewAll"); + + } + + [RequiresModerator] + public ActionResult Approve(string id) + { + var db = new ApplicationDbContext(); + var quote = db.Quotes.FirstOrDefault(x => x.Id == id); + if (quote == null) + return new HttpStatusCodeResult(404); + quote.IsApproved = true; + db.SaveChanges(); + return RedirectToAction("ReviewAll"); + } + } +}
\ No newline at end of file |
