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

50 lines
1.5 KiB
C#
Raw Normal View History

2019-11-10 23:41:33 +00:00
using System.Linq;
2019-11-07 22:43:37 +00:00
using System.Threading.Tasks;
using DiscImageChef.Server.Models;
using Microsoft.AspNetCore.Authorization;
2019-11-07 22:43:37 +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]
2019-11-07 22:43:37 +00:00
public class MediaFormatsController : Controller
{
readonly DicServerContext _context;
public MediaFormatsController(DicServerContext context) => _context = context;
// GET: Admin/MediaFormats
2019-11-10 23:41:33 +00:00
public async Task<IActionResult> Index() =>
View(await _context.MediaFormats.OrderBy(mf => mf.Name).ToListAsync());
2019-11-07 22:43:37 +00:00
// GET: Admin/MediaFormats/Delete/5
public async Task<IActionResult> Delete(int? id)
{
if(id == null)
{
return NotFound();
}
MediaFormat mediaFormat = await _context.MediaFormats.FirstOrDefaultAsync(m => m.Id == id);
if(mediaFormat == null)
{
return NotFound();
}
return View(mediaFormat);
}
// POST: Admin/MediaFormats/Delete/5
[HttpPost, ActionName("Delete"), ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(int id)
{
MediaFormat mediaFormat = await _context.MediaFormats.FindAsync(id);
_context.MediaFormats.Remove(mediaFormat);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
}
}