Files
Aaru.Server/DiscImageChef.Server/Areas/Admin/Controllers/FireWiresController.cs

110 lines
3.2 KiB
C#
Raw Normal View History

2019-11-10 23:15:27 +00:00
using System;
using System.Linq;
using System.Threading.Tasks;
using DiscImageChef.CommonTypes.Metadata;
using DiscImageChef.Server.Models;
using Microsoft.AspNetCore.Authorization;
2019-11-08 20:30:13 +00:00
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace DiscImageChef.Server.Areas.Admin.Controllers
{
2019-11-08 20:30:13 +00:00
[Area("Admin"), Authorize]
public class FireWiresController : Controller
{
2019-11-08 20:30:13 +00:00
readonly DicServerContext _context;
2019-11-08 20:30:13 +00:00
public FireWiresController(DicServerContext context) => _context = context;
// GET: Admin/FireWires
2019-11-10 23:26:07 +00:00
public async Task<IActionResult> Index() =>
View(await _context.FireWire.OrderBy(f => f.Manufacturer).ThenBy(f => f.Product).ToListAsync());
// GET: Admin/FireWires/Edit/5
public async Task<IActionResult> Edit(int? id)
{
2019-11-08 20:30:13 +00:00
if(id == null)
{
return NotFound();
}
2019-11-08 20:30:13 +00:00
FireWire fireWire = await _context.FireWire.FindAsync(id);
if(fireWire == null)
{
return NotFound();
}
2019-11-08 20:30:13 +00:00
return View(fireWire);
}
// POST: Admin/FireWires/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.
2019-11-08 20:30:13 +00:00
[HttpPost, ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(
int id, [Bind("Id,VendorID,ProductID,Manufacturer,Product,RemovableMedia")]
FireWire fireWire)
{
2019-11-08 20:30:13 +00:00
if(id != fireWire.Id)
{
return NotFound();
}
2019-11-08 20:30:13 +00:00
if(ModelState.IsValid)
{
try
{
_context.Update(fireWire);
await _context.SaveChangesAsync();
}
2019-11-08 20:30:13 +00:00
catch(DbUpdateConcurrencyException)
{
2019-11-08 20:30:13 +00:00
if(!FireWireExists(fireWire.Id))
{
return NotFound();
}
2019-11-08 20:30:13 +00:00
throw;
}
2019-11-08 20:30:13 +00:00
return RedirectToAction(nameof(Index));
}
2019-11-08 20:30:13 +00:00
return View(fireWire);
}
// GET: Admin/FireWires/Delete/5
public async Task<IActionResult> Delete(int? id)
{
2019-11-08 20:30:13 +00:00
if(id == null)
{
return NotFound();
}
2019-11-08 20:30:13 +00:00
FireWire fireWire = await _context.FireWire.FirstOrDefaultAsync(m => m.Id == id);
if(fireWire == null)
{
return NotFound();
}
return View(fireWire);
}
// POST: Admin/FireWires/Delete/5
2019-11-08 20:30:13 +00:00
[HttpPost, ActionName("Delete"), ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(int id)
{
2019-11-08 20:30:13 +00:00
FireWire fireWire = await _context.FireWire.FindAsync(id);
_context.FireWire.Remove(fireWire);
await _context.SaveChangesAsync();
2019-11-08 20:30:13 +00:00
return RedirectToAction(nameof(Index));
}
2019-11-08 20:30:13 +00:00
bool FireWireExists(int id) => _context.FireWire.Any(e => e.Id == id);
2019-11-10 23:15:27 +00:00
public IActionResult Consolidate() => throw new NotImplementedException();
}
2019-11-08 20:30:13 +00:00
}