From cd9437be6d05222ddb8981990ffae8001c5a4574 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 26 Mar 2017 11:28:57 -0400 Subject: [PATCH] Delete likes from topics. --- Project-Unite/Controllers/AdminController.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Project-Unite/Controllers/AdminController.cs b/Project-Unite/Controllers/AdminController.cs index 4ec5f0d..06836aa 100644 --- a/Project-Unite/Controllers/AdminController.cs +++ b/Project-Unite/Controllers/AdminController.cs @@ -175,7 +175,9 @@ public void DeleteTopic(ForumTopic topic) { DeletePost(post); } - db.ForumTopics.Remove(topic); + string id = topic.Id; + db.Likes.RemoveRange(db.Likes.Where(x => x.Topic == id)); + db.ForumTopics.Remove(db.ForumTopics.FirstOrDefault(x=>x.Id==id)); } public ActionResult AccessControl() @@ -225,7 +227,9 @@ public ActionResult SetPermission(string id, string role, string permission) public void DeletePost(ForumPost post) { - db.ForumPosts.Remove(post); + string id = post.Id; + + db.ForumPosts.Remove(db.ForumPosts.FirstOrDefault(x=>x.Id==id)); }