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

@ -30,7 +30,7 @@
foreach (var answer in Model.Answers) foreach (var answer in Model.Answers)
{ {
<li class="answer-list__single-answer"> <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) if (answer.Professional != null)
{ {
@ -41,6 +41,12 @@
<span class="username">@answer.Nick napisał(a)</span> <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 @answer.Date
</div> </div>
<div class="answer-list__content"> <div class="answer-list__content">