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

93 lines
3.3 KiB
C#
Raw Normal View History

2019-11-13 00:48:14 +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 MmcController : Controller
{
2019-11-08 20:30:13 +00:00
readonly DicServerContext _context;
2019-11-08 20:30:13 +00:00
public MmcController(DicServerContext context) => _context = context;
// GET: Admin/Mmc
public IActionResult Index() => View(_context.Mmc.Where(m => m.ModeSense2AData != null).
Select(m => new MmcModelForView
{
Id = m.Id, FeaturesId = m.FeaturesId,
DataLength = m.ModeSense2AData.Length
}).ToList().
Concat(_context.Mmc.Where(m => m.ModeSense2AData == null).
Select(m => new MmcModelForView
{
Id = m.Id, FeaturesId = m.FeaturesId,
DataLength = 0
}).ToList()).OrderBy(m => m.Id));
// GET: Admin/Mmc/Details/5
public async Task<IActionResult> Details(int? id)
{
2019-11-08 20:30:13 +00:00
if(id == null)
{
return NotFound();
}
2019-11-08 20:30:13 +00:00
Mmc mmc = await _context.Mmc.FirstOrDefaultAsync(m => m.Id == id);
if(mmc == null)
{
return NotFound();
}
return View(mmc);
}
// GET: Admin/Mmc/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
Mmc mmc = await _context.Mmc.FirstOrDefaultAsync(m => m.Id == id);
if(mmc == null)
{
return NotFound();
}
return View(mmc);
}
// POST: Admin/Mmc/Delete/5
2019-11-08 20:30:13 +00:00
[HttpPost, ActionName("Delete"), ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(int id)
{
Mmc mmc = await _context.Mmc.FindAsync(id);
MmcFeatures feature = await _context.MmcFeatures.FirstOrDefaultAsync(f => f.Id == mmc.FeaturesId);
_context.MmcFeatures.Remove(feature);
_context.Mmc.Remove(mmc);
await _context.SaveChangesAsync();
2019-11-08 20:30:13 +00:00
return RedirectToAction(nameof(Index));
}
2019-11-13 00:48:14 +00:00
public IActionResult Decode(int id) => throw new NotImplementedException();
2019-11-13 00:48:14 +00:00
public async Task<IActionResult> Clean()
2019-11-13 00:48:14 +00:00
{
_context.Mmc.RemoveRange(_context.Mmc.Where(m => m.FeaturesId == null && m.ModeSense2AData == null));
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
2019-11-13 00:48:14 +00:00
}
}
2019-11-08 20:30:13 +00:00
}