2019-11-07 22:43:37 +00:00
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using DiscImageChef.Server.Models;
|
2019-11-08 00:37:51 +00:00
|
|
|
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 DeviceStatsController : Controller
|
|
|
|
|
{
|
|
|
|
|
readonly DicServerContext _context;
|
|
|
|
|
|
|
|
|
|
public DeviceStatsController(DicServerContext context) => _context = context;
|
|
|
|
|
|
|
|
|
|
// GET: Admin/DeviceStats
|
2019-11-10 20:03:05 +00:00
|
|
|
public async Task<IActionResult> Index() =>
|
2019-11-25 00:54:39 +00:00
|
|
|
View(await _context.DeviceStats.OrderBy(d => d.Manufacturer).ThenBy(d => d.Model).ThenBy(d => d.Bus).
|
|
|
|
|
ToListAsync());
|
2019-11-07 22:43:37 +00:00
|
|
|
|
|
|
|
|
// GET: Admin/DeviceStats/Edit/5
|
|
|
|
|
public async Task<IActionResult> Edit(int? id)
|
|
|
|
|
{
|
|
|
|
|
if(id == null)
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DeviceStat deviceStat = await _context.DeviceStats.FindAsync(id);
|
|
|
|
|
|
|
|
|
|
if(deviceStat == null)
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View(deviceStat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: Admin/DeviceStats/Edit/5
|
2019-11-08 00:37:51 +00:00
|
|
|
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
|
2019-11-07 22:43:37 +00:00
|
|
|
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
|
|
|
|
[HttpPost, ValidateAntiForgeryToken]
|
|
|
|
|
public async Task<IActionResult> Edit(int id, [Bind("Id,Manufacturer,Model,Revision,Bus")]
|
2019-12-27 17:13:10 +00:00
|
|
|
DeviceStat changedModel)
|
2019-11-07 22:43:37 +00:00
|
|
|
{
|
2019-12-27 17:13:10 +00:00
|
|
|
if(id != changedModel.Id)
|
|
|
|
|
return NotFound();
|
|
|
|
|
|
|
|
|
|
if(!ModelState.IsValid)
|
|
|
|
|
return View(changedModel);
|
|
|
|
|
|
|
|
|
|
DeviceStat model = await _context.DeviceStats.FirstOrDefaultAsync(m => m.Id == id);
|
|
|
|
|
|
|
|
|
|
if(model is null)
|
2019-11-07 22:43:37 +00:00
|
|
|
return NotFound();
|
|
|
|
|
|
2019-12-27 17:13:10 +00:00
|
|
|
model.Manufacturer = changedModel.Manufacturer;
|
|
|
|
|
model.Model = changedModel.Model;
|
|
|
|
|
model.Revision = changedModel.Revision;
|
|
|
|
|
model.Bus = changedModel.Bus;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_context.Update(model);
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
}
|
|
|
|
|
catch(DbUpdateConcurrencyException)
|
2019-11-07 22:43:37 +00:00
|
|
|
{
|
2019-12-27 17:13:10 +00:00
|
|
|
ModelState.AddModelError("Concurrency", "Concurrency error, please report to the administrator.");
|
2019-11-07 22:43:37 +00:00
|
|
|
}
|
|
|
|
|
|
2019-12-27 17:13:10 +00:00
|
|
|
return RedirectToAction(nameof(Index));
|
2019-11-07 22:43:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: Admin/DeviceStats/Delete/5
|
|
|
|
|
public async Task<IActionResult> Delete(int? id)
|
|
|
|
|
{
|
|
|
|
|
if(id == null)
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DeviceStat deviceStat = await _context.DeviceStats.FirstOrDefaultAsync(m => m.Id == id);
|
|
|
|
|
|
|
|
|
|
if(deviceStat == null)
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View(deviceStat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: Admin/DeviceStats/Delete/5
|
|
|
|
|
[HttpPost, ActionName("Delete"), ValidateAntiForgeryToken]
|
|
|
|
|
public async Task<IActionResult> DeleteConfirmed(int id)
|
|
|
|
|
{
|
|
|
|
|
DeviceStat deviceStat = await _context.DeviceStats.FindAsync(id);
|
|
|
|
|
_context.DeviceStats.Remove(deviceStat);
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|