Fix topic delete bug

This commit is contained in:
Michael 2017-03-21 20:38:14 -04:00
parent 10e1866c9e
commit 872b3fb32e

View file

@ -154,16 +154,21 @@ public ActionResult DeletePost(string id)
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});
}