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});
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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">
|
||||||
|
Loading…
Reference in New Issue
Block a user