2019-11-08 00:03:43 +00:00
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using DiscImageChef.CommonTypes.Metadata;
|
|
|
|
|
using DiscImageChef.Server.Models;
|
2019-11-08 00:37:51 +00:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2019-11-08 20:30:13 +00:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2019-11-08 00:03:43 +00:00
|
|
|
|
|
|
|
|
namespace DiscImageChef.Server.Areas.Admin.Controllers
|
|
|
|
|
{
|
2019-11-08 20:30:13 +00:00
|
|
|
[Area("Admin"), Authorize]
|
2019-11-08 00:03:43 +00:00
|
|
|
public class TestedMediasController : Controller
|
|
|
|
|
{
|
2019-11-08 20:30:13 +00:00
|
|
|
readonly DicServerContext _context;
|
2019-11-08 00:03:43 +00:00
|
|
|
|
2019-11-08 20:30:13 +00:00
|
|
|
public TestedMediasController(DicServerContext context) => _context = context;
|
2019-11-08 00:03:43 +00:00
|
|
|
|
|
|
|
|
// GET: Admin/TestedMedias
|
2019-11-18 00:29:55 +00:00
|
|
|
public async Task<IActionResult> Index() => View(await _context.
|
|
|
|
|
TestedMedia.OrderBy(m => m.Manufacturer).
|
|
|
|
|
ThenBy(m => m.Model).ThenBy(m => m.MediumTypeName).
|
|
|
|
|
ThenBy(m => m.MediaIsRecognized).
|
|
|
|
|
ThenBy(m => m.LongBlockSize).ThenBy(m => m.BlockSize).
|
|
|
|
|
ThenBy(m => m.Blocks).ToListAsync());
|
2019-11-08 00:03:43 +00:00
|
|
|
|
|
|
|
|
// GET: Admin/TestedMedias/Details/5
|
|
|
|
|
public async Task<IActionResult> Details(int? id)
|
|
|
|
|
{
|
2019-11-08 20:30:13 +00:00
|
|
|
if(id == null)
|
2019-11-08 00:03:43 +00:00
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-08 20:30:13 +00:00
|
|
|
TestedMedia testedMedia = await _context.TestedMedia.FirstOrDefaultAsync(m => m.Id == id);
|
|
|
|
|
|
|
|
|
|
if(testedMedia == null)
|
2019-11-08 00:03:43 +00:00
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View(testedMedia);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: Admin/TestedMedias/Edit/5
|
|
|
|
|
public async Task<IActionResult> Edit(int? id)
|
|
|
|
|
{
|
2019-11-08 20:30:13 +00:00
|
|
|
if(id == null)
|
2019-11-08 00:03:43 +00:00
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-08 20:30:13 +00:00
|
|
|
TestedMedia testedMedia = await _context.TestedMedia.FindAsync(id);
|
|
|
|
|
|
|
|
|
|
if(testedMedia == null)
|
2019-11-08 00:03:43 +00:00
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
2019-11-08 20:30:13 +00:00
|
|
|
|
2019-11-08 00:03:43 +00:00
|
|
|
return View(testedMedia);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: Admin/TestedMedias/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]
|
2019-11-19 00:22:25 +00:00
|
|
|
public async Task<IActionResult> Edit(
|
|
|
|
|
int id, [Bind("Id,Blocks,BlockSize,LongBlockSize,Manufacturer,MediumTypeName,Model")]
|
|
|
|
|
TestedMedia testedMedia)
|
2019-11-08 00:03:43 +00:00
|
|
|
{
|
2019-11-08 20:30:13 +00:00
|
|
|
if(id != testedMedia.Id)
|
2019-11-08 00:03:43 +00:00
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-08 20:30:13 +00:00
|
|
|
if(ModelState.IsValid)
|
2019-11-08 00:03:43 +00:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_context.Update(testedMedia);
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
}
|
2019-11-08 20:30:13 +00:00
|
|
|
catch(DbUpdateConcurrencyException)
|
2019-11-08 00:03:43 +00:00
|
|
|
{
|
2019-11-08 20:30:13 +00:00
|
|
|
if(!TestedMediaExists(testedMedia.Id))
|
2019-11-08 00:03:43 +00:00
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
2019-11-08 20:30:13 +00:00
|
|
|
|
|
|
|
|
throw;
|
2019-11-08 00:03:43 +00:00
|
|
|
}
|
2019-11-08 20:30:13 +00:00
|
|
|
|
2019-11-08 00:03:43 +00:00
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
2019-11-08 20:30:13 +00:00
|
|
|
|
2019-11-08 00:03:43 +00:00
|
|
|
return View(testedMedia);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: Admin/TestedMedias/Delete/5
|
|
|
|
|
public async Task<IActionResult> Delete(int? id)
|
|
|
|
|
{
|
2019-11-08 20:30:13 +00:00
|
|
|
if(id == null)
|
2019-11-08 00:03:43 +00:00
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-08 20:30:13 +00:00
|
|
|
TestedMedia testedMedia = await _context.TestedMedia.FirstOrDefaultAsync(m => m.Id == id);
|
|
|
|
|
|
|
|
|
|
if(testedMedia == null)
|
2019-11-08 00:03:43 +00:00
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View(testedMedia);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: Admin/TestedMedias/Delete/5
|
2019-11-08 20:30:13 +00:00
|
|
|
[HttpPost, ActionName("Delete"), ValidateAntiForgeryToken]
|
2019-11-08 00:03:43 +00:00
|
|
|
public async Task<IActionResult> DeleteConfirmed(int id)
|
|
|
|
|
{
|
2019-11-08 20:30:13 +00:00
|
|
|
TestedMedia testedMedia = await _context.TestedMedia.FindAsync(id);
|
2019-11-08 00:03:43 +00:00
|
|
|
_context.TestedMedia.Remove(testedMedia);
|
|
|
|
|
await _context.SaveChangesAsync();
|
2019-11-08 20:30:13 +00:00
|
|
|
|
2019-11-08 00:03:43 +00:00
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-08 20:30:13 +00:00
|
|
|
bool TestedMediaExists(int id) => _context.TestedMedia.Any(e => e.Id == id);
|
2019-11-08 00:03:43 +00:00
|
|
|
}
|
2019-11-08 20:30:13 +00:00
|
|
|
}
|