Files
yavsc/src/Yavsc/Controllers/Musical/InstrumentsController.cs
Paul Schneider a9b809f5e5
Some checks failed
Dotnet build and test / log-the-inputs (push) Failing after 1s
Dotnet build and test / build (push) Failing after 1s
Refactoring
The main server owns the migrations, it's the server part,
it's simpler.

It's Yavsc, not one of its lib.
2025-07-15 20:17:39 +01:00

124 lines
3.2 KiB
C#

using System.Linq;
using Microsoft.AspNetCore.Mvc;
namespace Yavsc.Controllers
{
using System.Security.Claims;
using Models;
using Models.Musical;
using Yavsc.Helpers;
using Yavsc.Server.Helpers;
public class InstrumentsController : Controller
{
private readonly ApplicationDbContext _context;
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)
{
return NotFound();
}
Instrument instrument = _context.Instrument.Single(m => m.Id == id);
if (instrument == null)
{
return NotFound();
}
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)
{
return NotFound();
}
Instrument instrument = _context.Instrument.Single(m => m.Id == id);
if (instrument == null)
{
return NotFound();
}
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)
{
return NotFound();
}
Instrument instrument = _context.Instrument.Single(m => m.Id == id);
if (instrument == null)
{
return NotFound();
}
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");
}
}
}