diff options
| author | Michael <[email protected]> | 2017-03-21 20:38:14 -0400 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-03-21 20:38:14 -0400 |
| commit | 872b3fb32e592605def11e0d13a57064e096b9a7 (patch) | |
| tree | d5e6548032689b77992b9e7b42113f2a29dded1a /Project-Unite/Controllers/ForumController.cs | |
| parent | 10e1866c9e994dabe5b6c748a5b9a7372b01886f (diff) | |
| download | project-unite-872b3fb32e592605def11e0d13a57064e096b9a7.tar.gz project-unite-872b3fb32e592605def11e0d13a57064e096b9a7.tar.bz2 project-unite-872b3fb32e592605def11e0d13a57064e096b9a7.zip | |
Fix topic delete bug
Diffstat (limited to 'Project-Unite/Controllers/ForumController.cs')
| -rw-r--r-- | Project-Unite/Controllers/ForumController.cs | 15 |
1 files 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}); } |
