Dodani usuwanie odpowiedzi
This commit is contained in:
parent
d72384efe2
commit
a0c5d4357b
@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -30,7 +30,7 @@
|
||||
foreach (var answer in Model.Answers)
|
||||
{
|
||||
<li class="answer-list__single-answer">
|
||||
<div class="answer-list__answer__info" @{if(answer.Professional!=null){<text>style="background-color: #7ecc2a"</text>}}>
|
||||
<div class="answer-list__answer__info" @{if (answer.Professional != null) { <text> style="background-color: #7ecc2a" </text> }}>
|
||||
@{
|
||||
if (answer.Professional != null)
|
||||
{
|
||||
@ -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">
|
||||
|
Loading…
Reference in New Issue
Block a user