This commit is contained in:
Paul Schneider 2026-02-28 21:17:54 +00:00
commit 40e8e08690
3487 changed files with 39 additions and 21 deletions

View file

@ -0,0 +1,146 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using Yavsc.Models;
using Yavsc.Models.Musical;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{
public class InstrumentRatingController : Controller
{
private readonly ApplicationDbContext _context;
public InstrumentRatingController(ApplicationDbContext context)
{
_context = context;
}
// GET: InstrumentRating
public async Task<IActionResult> Index()
{
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
var applicationDbContext =
_context.InstrumentRating
.Include(i => i.Profile)
.Include(i => i.Instrument)
.Where(i => i.OwnerId == uid);
return View(await applicationDbContext.ToListAsync());
}
// GET: InstrumentRating/Details/5
public async Task<IActionResult> Details(long? id)
{
if (id == null)
{
return NotFound();
}
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
InstrumentRating instrumentRating = await _context.InstrumentRating
.Include(i => i.Instrument).SingleAsync(m => m.Id == id);
if (instrumentRating == null)
{
return NotFound();
}
return View(instrumentRating);
}
// GET: InstrumentRating/Create
public async Task<IActionResult> Create()
{
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
var actual = await _context.InstrumentRating
.Where(m => m.OwnerId == uid). Select( r => r.InstrumentId ).ToArrayAsync();
ViewBag.YetAvailableInstruments = _context.Instrument.Select(k=>new SelectListItem
{ Text = k.Name, Value = k.Id.ToString(), Disabled = actual.Contains(k.Id) });
if (User.IsInMsRole("Administrator"))
ViewBag.OwnerIds = new SelectList(_context.Performers, "PerformerId", "Profile");
return View();
}
// POST: InstrumentRating/Create
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(InstrumentRating instrumentRating)
{
if (ModelState.IsValid)
{
_context.InstrumentRating.Add(instrumentRating);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
ViewData["OwnerId"] = new SelectList(_context.Performers, "PerformerId", "Profile", instrumentRating.OwnerId);
return View(instrumentRating);
}
// GET: InstrumentRating/Edit/5
public async Task<IActionResult> Edit(long? id)
{
if (id == null)
{
return NotFound();
}
InstrumentRating instrumentRating = await _context.InstrumentRating.SingleAsync(m => m.Id == id);
if (instrumentRating == null)
{
return NotFound();
}
ViewData["OwnerId"] = new SelectList(_context.Performers, "PerformerId", "Profile", instrumentRating.OwnerId);
return View(instrumentRating);
}
// POST: InstrumentRating/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(InstrumentRating instrumentRating)
{
if (ModelState.IsValid)
{
_context.Update(instrumentRating);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
ViewData["OwnerId"] = new SelectList(_context.Performers, "PerformerId", "Profile", instrumentRating.OwnerId);
return View(instrumentRating);
}
// GET: InstrumentRating/Delete/5
[ActionName("Delete")]
public async Task<IActionResult> Delete(long? id)
{
if (id == null)
{
return NotFound();
}
InstrumentRating instrumentRating = await _context.InstrumentRating
.Include(i => i.Instrument).SingleAsync(m => m.Id == id);
if (instrumentRating == null)
{
return NotFound();
}
return View(instrumentRating);
}
// POST: InstrumentRating/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(long id)
{
InstrumentRating instrumentRating = await _context.InstrumentRating.SingleAsync(m => m.Id == id);
_context.InstrumentRating.Remove(instrumentRating);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
}
}

View file

@ -0,0 +1,149 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Musical.Profiles;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{
[Authorize]
public class InstrumentationController : Controller
{
private readonly ApplicationDbContext _context;
public InstrumentationController(ApplicationDbContext context)
{
_context = context;
}
// GET: Instrumentation
public async Task<IActionResult> Index()
{
return View(await _context.Instrumentation.ToListAsync());
}
// GET: Instrumentation/Details/5
public async Task<IActionResult> Details(string id)
{
if (id == null)
{
return NotFound();
}
Instrumentation musicianSettings = await _context.Instrumentation.SingleAsync(m => m.UserId == id);
if (musicianSettings == null)
{
return NotFound();
}
return View(musicianSettings);
}
// GET: Instrumentation/Create
public IActionResult Create()
{
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
var owned = _context.Instrumentation.Include(i=>i.Tool).Where(i=>i.UserId==uid).Select(i=>i.InstrumentId);
var ownedArray = owned.ToArray();
ViewBag.YetAvailableInstruments = _context.Instrument.Select(k=>new SelectListItem
{ Text = k.Name, Value = k.Id.ToString(), Disabled = ownedArray.Contains(k.Id) });
return View(new Instrumentation { UserId = uid });
}
// POST: Instrumentation/Create
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(Instrumentation model)
{
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
if (ModelState.IsValid)
{
if (model.UserId != uid) if (!User.IsInMsRole(Constants.AdminGroupName))
return new ChallengeResult();
_context.Instrumentation.Add(model);
await _context.SaveChangesAsync(User.GetUserId());
return RedirectToAction("Index");
}
return View(model);
}
// GET: Instrumentation/Edit/5
public async Task<IActionResult> Edit(string id)
{
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
if (id == null)
{
return NotFound();
}
if (id != uid) if (!User.IsInMsRole(Constants.AdminGroupName))
return new ChallengeResult();
Instrumentation musicianSettings = await _context.Instrumentation.SingleAsync(m => m.UserId == id);
if (musicianSettings == null)
{
return NotFound();
}
return View(musicianSettings);
}
// POST: Instrumentation/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(Instrumentation musicianSettings)
{
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
if (musicianSettings.UserId != uid) if (!User.IsInMsRole(Constants.AdminGroupName))
return new ChallengeResult();
if (ModelState.IsValid)
{
_context.Update(musicianSettings);
await _context.SaveChangesAsync(User.GetUserId());
return RedirectToAction("Index");
}
return View(musicianSettings);
}
// GET: Instrumentation/Delete/5
[ActionName("Delete")]
public async Task<IActionResult> Delete(string id)
{
if (id == null)
{
return NotFound();
}
Instrumentation musicianSettings = await _context.Instrumentation.SingleAsync(m => m.UserId == id);
if (musicianSettings == null)
{
return NotFound();
}
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
if (musicianSettings.UserId != uid) if (!User.IsInMsRole(Constants.AdminGroupName))
return new ChallengeResult();
return View(musicianSettings);
}
// POST: Instrumentation/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(string id)
{
Instrumentation musicianSettings = await _context.Instrumentation.SingleAsync(m => m.UserId == id);
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
if (musicianSettings.UserId != uid) if (!User.IsInMsRole(Constants.AdminGroupName))
return new ChallengeResult();
_context.Instrumentation.Remove(musicianSettings);
await _context.SaveChangesAsync(User.GetUserId());
return RedirectToAction("Index");
}
}
}

View file

@ -0,0 +1,123 @@
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");
}
}
}