yavsc/src/Yavsc/Controllers/Musical/InstrumentsController.cs

122 lines
3.2 KiB
C#
Raw Normal View History

2018-05-04 13:56:22 +02:00
using System.Linq;
2023-03-19 17:57:55 +00:00
using Microsoft.AspNetCore.Mvc;
2018-05-04 13:56:22 +02:00
namespace Yavsc.Controllers
{
using System.Security.Claims;
using Models;
using Models.Musical;
2023-03-19 17:57:55 +00:00
using Yavsc.Helpers;
2018-05-04 13:56:22 +02:00
public class InstrumentsController : Controller
{
2020-10-09 19:35:39 +01:00
private readonly ApplicationDbContext _context;
2018-05-04 13:56:22 +02:00
public InstrumentsController(ApplicationDbContext context)
{
_context = context;
}
// GET: Instruments
public IActionResult Index()
{
return View(_context.Instrument.ToList());
}
// GET: Instruments/Details/5
public IActionResult Details(long? id)
{
if (id == null)
{
2023-03-19 17:57:55 +00:00
return NotFound();
2018-05-04 13:56:22 +02:00
}
Instrument instrument = _context.Instrument.Single(m => m.Id == id);
if (instrument == null)
{
2023-03-19 17:57:55 +00:00
return NotFound();
2018-05-04 13:56:22 +02:00
}
return View(instrument);
}
// GET: Instruments/Create
public IActionResult Create()
{
return View();
}
// POST: Instruments/Create
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Create(Instrument instrument)
{
if (ModelState.IsValid)
{
_context.Instrument.Add(instrument);
_context.SaveChanges(User.GetUserId());
return RedirectToAction("Index");
}
return View(instrument);
}
// GET: Instruments/Edit/5
public IActionResult Edit(long? id)
{
if (id == null)
{
2023-03-19 17:57:55 +00:00
return NotFound();
2018-05-04 13:56:22 +02:00
}
Instrument instrument = _context.Instrument.Single(m => m.Id == id);
if (instrument == null)
{
2023-03-19 17:57:55 +00:00
return NotFound();
2018-05-04 13:56:22 +02:00
}
return View(instrument);
}
// POST: Instruments/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Edit(Instrument instrument)
{
if (ModelState.IsValid)
{
_context.Update(instrument);
_context.SaveChanges(User.GetUserId());
return RedirectToAction("Index");
}
return View(instrument);
}
// GET: Instruments/Delete/5
[ActionName("Delete")]
public IActionResult Delete(long? id)
{
if (id == null)
{
2023-03-19 17:57:55 +00:00
return NotFound();
2018-05-04 13:56:22 +02:00
}
Instrument instrument = _context.Instrument.Single(m => m.Id == id);
if (instrument == null)
{
2023-03-19 17:57:55 +00:00
return NotFound();
2018-05-04 13:56:22 +02:00
}
return View(instrument);
}
// POST: Instruments/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public IActionResult DeleteConfirmed(long id)
{
Instrument instrument = _context.Instrument.Single(m => m.Id == id);
_context.Instrument.Remove(instrument);
_context.SaveChanges(User.GetUserId());
return RedirectToAction("Index");
}
}
}