diff --git a/Trunk/Server/Forum/Forum/Controllers/HomeController.cs b/Trunk/Server/Forum/Forum/Controllers/HomeController.cs index c9691d5..e6e7b6d 100644 --- a/Trunk/Server/Forum/Forum/Controllers/HomeController.cs +++ b/Trunk/Server/Forum/Forum/Controllers/HomeController.cs @@ -133,6 +133,25 @@ namespace Forum.Controllers return RedirectToAction("Question", new {id = model.QuestionId}); } + [Authorize] + [System.Web.Mvc.Route("Home/DeleteAnswer/{id}")] + public ActionResult DeleteAnswer(int? id) + { + var answer = _dbContext.Answers.Find(id); + var question = _dbContext.Questions.FirstOrDefault(x => x.Answers.Any(y => y.Id == id)); + + if (answer != null) + { + _dbContext.Answers.Remove(answer); + _dbContext.SaveChanges(); + } + + if (question != null) + return RedirectToAction("Question", new {id = question.Id}); + + return HttpNotFound(); + } + } } \ No newline at end of file diff --git a/Trunk/Server/Forum/Forum/Views/Home/Question.cshtml b/Trunk/Server/Forum/Forum/Views/Home/Question.cshtml index beec3c6..e02470c 100644 --- a/Trunk/Server/Forum/Forum/Views/Home/Question.cshtml +++ b/Trunk/Server/Forum/Forum/Views/Home/Question.cshtml @@ -30,7 +30,7 @@ foreach (var answer in Model.Answers) {