From 872b3fb32e592605def11e0d13a57064e096b9a7 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 21 Mar 2017 20:38:14 -0400 Subject: [PATCH] Fix topic delete bug --- Project-Unite/Controllers/ForumController.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Project-Unite/Controllers/ForumController.cs b/Project-Unite/Controllers/ForumController.cs index 9ac2685..4236286 100644 --- a/Project-Unite/Controllers/ForumController.cs +++ b/Project-Unite/Controllers/ForumController.cs @@ -154,16 +154,21 @@ namespace Project_Unite.Controllers acl_perm = "CanDeleteOwnPosts"; if (!ACL.Granted(User.Identity.Name, acl_perm)) return new HttpStatusCodeResult(403); - db.ForumPosts.Remove(topic); var parent = db.ForumTopics.FirstOrDefault(x => x.Id == topic.Parent); - db.SaveChanges(); - if (parent.Posts.Length == 0) + bool redirectToParent = false; + string cat = ""; + if (parent.Posts.Length - 1 == 0) { - string cat = parent.Parent; + cat = parent.Parent; db.ForumTopics.Remove(parent); db.SaveChanges(); - RedirectToAction("ViewForum", new { id = cat }); + redirectToParent = true; } + db.ForumPosts.Remove(topic); + db.SaveChanges(); + if(redirectToParent) + return RedirectToAction("ViewForum", new { id = cat }); + return RedirectToAction("ViewTopic", new { id = db.ForumTopics.FirstOrDefault(x => x.Id == topic.Parent).Discriminator}); }