Dodani usuwanie odpowiedzi

This commit is contained in:
Bartosz Chyzy 2018-12-19 23:26:12 +01:00
parent d72384efe2
commit a0c5d4357b
2 changed files with 26 additions and 1 deletions

View File

@ -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();
}
}
}

View File

@ -41,6 +41,12 @@
<span class="username">@answer.Nick napisał(a)</span>
}
}
@{
if (User.Identity.IsAuthenticated)
{
@Html.ActionLink("Usuń odpowiedź", "DeleteAnswer", new {id = answer.Id},new{@style="color:#fff;"});
}
}
@answer.Date
</div>
<div class="answer-list__content">