2019-05-19 16:22:21 +01:00
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-02-10 02:10:18 +00:00
|
|
|
using Marechai.Database.Models;
|
2020-02-10 02:20:48 +00:00
|
|
|
using Marechai.Areas.Admin.Models;
|
2019-05-19 16:22:21 +01:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2019-05-20 00:38:13 +01:00
|
|
|
using Microsoft.EntityFrameworkCore.Query;
|
2019-05-19 16:22:21 +01:00
|
|
|
|
2020-02-10 02:20:48 +00:00
|
|
|
namespace Marechai.Areas.Admin.Controllers
|
2019-05-19 16:22:21 +01:00
|
|
|
{
|
|
|
|
|
[Area("Admin")]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class SoundByMachineController : Controller
|
|
|
|
|
{
|
2020-02-10 02:47:39 +00:00
|
|
|
readonly MarechaiContext _context;
|
2019-05-19 16:22:21 +01:00
|
|
|
|
2020-02-10 02:47:39 +00:00
|
|
|
public SoundByMachineController(MarechaiContext context)
|
2019-05-19 16:22:21 +01:00
|
|
|
{
|
|
|
|
|
_context = context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: SoundByMachine
|
|
|
|
|
public async Task<IActionResult> Index()
|
|
|
|
|
{
|
2020-02-10 02:47:39 +00:00
|
|
|
IIncludableQueryable<SoundByMachine, SoundSynth> marechaiContext =
|
2019-05-20 00:38:13 +01:00
|
|
|
_context.SoundByMachine.Include(s => s.Machine).Include(s => s.SoundSynth);
|
2020-02-10 02:47:39 +00:00
|
|
|
return View(await marechaiContext.OrderBy(s => s.Machine.Name).ThenBy(s => s.SoundSynth.Name)
|
2019-05-20 00:38:13 +01:00
|
|
|
.Select(s => new SoundByMachineViewModel
|
|
|
|
|
{
|
|
|
|
|
Id = s.Id,
|
|
|
|
|
Machine = s.Machine.Name,
|
|
|
|
|
SoundSynth = s.SoundSynth.Name
|
|
|
|
|
}).ToListAsync());
|
2019-05-19 16:22:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: SoundByMachine/Details/5
|
|
|
|
|
public async Task<IActionResult> Details(long? id)
|
|
|
|
|
{
|
2019-05-20 00:38:13 +01:00
|
|
|
if(id == null) return NotFound();
|
2019-05-19 16:22:21 +01:00
|
|
|
|
2019-05-20 00:38:13 +01:00
|
|
|
SoundByMachine soundByMachine = await _context.SoundByMachine
|
|
|
|
|
.Include(s => s.Machine).Include(s => s.SoundSynth)
|
|
|
|
|
.FirstOrDefaultAsync(m => m.Id == id);
|
|
|
|
|
if(soundByMachine == null) return NotFound();
|
2019-05-19 16:22:21 +01:00
|
|
|
|
|
|
|
|
return View(soundByMachine);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: SoundByMachine/Create
|
|
|
|
|
public IActionResult Create()
|
|
|
|
|
{
|
2019-05-20 00:38:13 +01:00
|
|
|
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name");
|
2019-05-19 16:22:21 +01:00
|
|
|
ViewData["SoundSynthId"] = new SelectList(_context.SoundSynths, "Id", "Name");
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: SoundByMachine/Create
|
|
|
|
|
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
|
|
|
|
|
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
public async Task<IActionResult> Create([Bind("SoundSynthId,MachineId,Id")] SoundByMachine soundByMachine)
|
|
|
|
|
{
|
2019-05-20 00:38:13 +01:00
|
|
|
if(ModelState.IsValid)
|
2019-05-19 16:22:21 +01:00
|
|
|
{
|
|
|
|
|
_context.Add(soundByMachine);
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
2019-05-20 00:38:13 +01:00
|
|
|
|
|
|
|
|
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", soundByMachine.MachineId);
|
2019-05-19 16:22:21 +01:00
|
|
|
ViewData["SoundSynthId"] = new SelectList(_context.SoundSynths, "Id", "Name", soundByMachine.SoundSynthId);
|
|
|
|
|
return View(soundByMachine);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: SoundByMachine/Edit/5
|
|
|
|
|
public async Task<IActionResult> Edit(long? id)
|
|
|
|
|
{
|
2019-05-20 00:38:13 +01:00
|
|
|
if(id == null) return NotFound();
|
2019-05-19 16:22:21 +01:00
|
|
|
|
2019-05-20 00:38:13 +01:00
|
|
|
SoundByMachine soundByMachine = await _context.SoundByMachine.FindAsync(id);
|
|
|
|
|
if(soundByMachine == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", soundByMachine.MachineId);
|
2019-05-19 16:22:21 +01:00
|
|
|
ViewData["SoundSynthId"] = new SelectList(_context.SoundSynths, "Id", "Name", soundByMachine.SoundSynthId);
|
|
|
|
|
return View(soundByMachine);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: SoundByMachine/Edit/5
|
|
|
|
|
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
|
|
|
|
|
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ValidateAntiForgeryToken]
|
2019-05-20 00:38:13 +01:00
|
|
|
public async Task<IActionResult> Edit(
|
|
|
|
|
long id, [Bind("SoundSynthId,MachineId,Id")] SoundByMachine soundByMachine)
|
2019-05-19 16:22:21 +01:00
|
|
|
{
|
2019-05-20 00:38:13 +01:00
|
|
|
if(id != soundByMachine.Id) return NotFound();
|
2019-05-19 16:22:21 +01:00
|
|
|
|
2019-05-20 00:38:13 +01:00
|
|
|
if(ModelState.IsValid)
|
2019-05-19 16:22:21 +01:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_context.Update(soundByMachine);
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
}
|
2019-05-20 00:38:13 +01:00
|
|
|
catch(DbUpdateConcurrencyException)
|
2019-05-19 16:22:21 +01:00
|
|
|
{
|
2019-05-20 00:38:13 +01:00
|
|
|
if(!SoundByMachineExists(soundByMachine.Id)) return NotFound();
|
|
|
|
|
|
|
|
|
|
throw;
|
2019-05-19 16:22:21 +01:00
|
|
|
}
|
2019-05-20 00:38:13 +01:00
|
|
|
|
2019-05-19 16:22:21 +01:00
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
2019-05-20 00:38:13 +01:00
|
|
|
|
|
|
|
|
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", soundByMachine.MachineId);
|
2019-05-19 16:22:21 +01:00
|
|
|
ViewData["SoundSynthId"] = new SelectList(_context.SoundSynths, "Id", "Name", soundByMachine.SoundSynthId);
|
|
|
|
|
return View(soundByMachine);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: SoundByMachine/Delete/5
|
|
|
|
|
public async Task<IActionResult> Delete(long? id)
|
|
|
|
|
{
|
2019-05-20 00:38:13 +01:00
|
|
|
if(id == null) return NotFound();
|
2019-05-19 16:22:21 +01:00
|
|
|
|
2019-05-20 00:38:13 +01:00
|
|
|
SoundByMachine soundByMachine = await _context.SoundByMachine
|
|
|
|
|
.Include(s => s.Machine).Include(s => s.SoundSynth)
|
|
|
|
|
.FirstOrDefaultAsync(m => m.Id == id);
|
|
|
|
|
if(soundByMachine == null) return NotFound();
|
2019-05-19 16:22:21 +01:00
|
|
|
|
|
|
|
|
return View(soundByMachine);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: SoundByMachine/Delete/5
|
2019-05-20 00:38:13 +01:00
|
|
|
[HttpPost]
|
|
|
|
|
[ActionName("Delete")]
|
2019-05-19 16:22:21 +01:00
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
public async Task<IActionResult> DeleteConfirmed(long id)
|
|
|
|
|
{
|
2019-05-20 00:38:13 +01:00
|
|
|
SoundByMachine soundByMachine = await _context.SoundByMachine.FindAsync(id);
|
2019-05-19 16:22:21 +01:00
|
|
|
_context.SoundByMachine.Remove(soundByMachine);
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-20 00:38:13 +01:00
|
|
|
bool SoundByMachineExists(long id)
|
2019-05-19 16:22:21 +01:00
|
|
|
{
|
|
|
|
|
return _context.SoundByMachine.Any(e => e.Id == id);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-20 00:38:13 +01:00
|
|
|
}
|