using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using YAPContracts.AdapterContracts; using YAPContracts.BindingModels; namespace YAPWebApplication.Controllers { [Authorize] public class ComponentController : Controller { private readonly IComponentAdapter _componentAdapter; public ComponentController(IComponentAdapter componentAdapter) { _componentAdapter = componentAdapter; } // GET: /Component/ public IActionResult Index() { var sets = _componentAdapter.GetList(true); return View(sets); } // GET: /Component/Details/{id} public IActionResult Details(string id) { var set = _componentAdapter.GetComponentByData(id); if (set == null) { return NotFound(); } return View(set); } // GET: /Component/Create public IActionResult Create() { return View(); } // POST: /Component/Create [HttpPost] [ValidateAntiForgeryToken] public IActionResult Create(ComponentBindingModel model) { if (ModelState.IsValid) { _componentAdapter.Insert(model); return RedirectToAction(nameof(Index)); } return View(model); } // GET: /Component/Edit/{id} public IActionResult Edit(string id) { var set = _componentAdapter.GetComponentByData(id); if (set == null) { return NotFound(); } return View(set); } // POST: /Component/Edit [HttpPost] [ValidateAntiForgeryToken] public IActionResult Edit(ComponentBindingModel model) { if (ModelState.IsValid) { _componentAdapter.Update(model); return RedirectToAction(nameof(Index)); } return View(model); } // GET: /Component/Delete/{id} public IActionResult Delete(string id) { var set = _componentAdapter.GetComponentByData(id); if (set == null) { return NotFound(); } return View(set); } // POST: /Component/Delete [HttpPost, ActionName("Delete")] [ValidateAntiForgeryToken] public IActionResult DeleteConfirmed(string id) { _componentAdapter.Delete(id); return RedirectToAction(nameof(Index)); } } }