100 lines
2.6 KiB
C#
100 lines
2.6 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using YAPContracts.AdapterContracts;
|
|
using YAPContracts.BindingModels;
|
|
|
|
namespace YAPWebApplication.Controllers
|
|
{
|
|
[Authorize]
|
|
public class CommentController : Controller
|
|
{
|
|
private readonly ICommentAdapter _commentAdapter;
|
|
|
|
public CommentController(ICommentAdapter commentAdapter)
|
|
{
|
|
_commentAdapter = commentAdapter;
|
|
}
|
|
|
|
// GET: /Comment/
|
|
public IActionResult Index()
|
|
{
|
|
var comments = _commentAdapter.GetList();
|
|
return View(comments);
|
|
}
|
|
|
|
// GET: /Comment/Details/{id}
|
|
public IActionResult Details(string id)
|
|
{
|
|
var comment = _commentAdapter.GetCommentById(id);
|
|
if (comment == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
return View(comment);
|
|
}
|
|
|
|
// GET: /Comment/Create
|
|
public IActionResult Create()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
// POST: /Comment/Create
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public IActionResult Create(CommentBindingModel model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
_commentAdapter.Create(model);
|
|
return RedirectToAction(nameof(Index));
|
|
}
|
|
return View(model);
|
|
}
|
|
|
|
// GET: /Comment/Edit/{id}
|
|
public IActionResult Edit(string id)
|
|
{
|
|
var comment = _commentAdapter.GetCommentById(id);
|
|
if (comment == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
return View(comment);
|
|
}
|
|
|
|
// POST: /Comment/Edit
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public IActionResult Edit(CommentBindingModel model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
_commentAdapter.Update(model);
|
|
return RedirectToAction(nameof(Index));
|
|
}
|
|
return View(model);
|
|
}
|
|
|
|
// GET: /Comment/Delete/{id}
|
|
public IActionResult Delete(string id)
|
|
{
|
|
var comment = _commentAdapter.GetCommentById(id);
|
|
if (comment == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
return View(comment);
|
|
}
|
|
|
|
// POST: /Comment/Delete
|
|
[HttpPost, ActionName("Delete")]
|
|
[ValidateAntiForgeryToken]
|
|
public IActionResult DeleteConfirmed(string id)
|
|
{
|
|
_commentAdapter.Delete(id);
|
|
return RedirectToAction(nameof(Index));
|
|
}
|
|
}
|
|
}
|