2018-08-11 10:50:22 +01:00
|
|
|
|
/******************************************************************************
|
2020-02-10 01:52:56 +00:00
|
|
|
|
// MARECHAI: Master repository of computing history artifacts information
|
2018-08-11 10:50:22 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : InstructionSetExtensionsController.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Instruction set extensions admin controller
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
|
// it under the terms of the GNU General Public License as
|
|
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
|
//
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
//
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
// Copyright © 2003-2018 Natalia Portillo
|
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
2019-05-19 22:29:16 +01:00
|
|
|
|
using System;
|
2018-08-11 10:50:22 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2020-02-10 02:10:18 +00:00
|
|
|
|
using Marechai.Database.Models;
|
2019-05-18 03:02:49 +01:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2018-08-11 10:50:22 +01:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
2020-02-10 02:20:48 +00:00
|
|
|
|
namespace Marechai.Areas.Admin.Controllers
|
2018-08-11 10:50:22 +01:00
|
|
|
|
{
|
|
|
|
|
|
[Area("Admin")]
|
2019-05-18 03:02:49 +01:00
|
|
|
|
[Authorize]
|
2018-08-11 10:50:22 +01:00
|
|
|
|
public class InstructionSetExtensionsController : Controller
|
|
|
|
|
|
{
|
|
|
|
|
|
readonly cicmContext _context;
|
|
|
|
|
|
|
|
|
|
|
|
public InstructionSetExtensionsController(cicmContext context)
|
|
|
|
|
|
{
|
|
|
|
|
|
_context = context;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GET: Admin/InstructionSetExtensions
|
2019-05-19 22:29:16 +01:00
|
|
|
|
public async Task<IActionResult> Index() =>
|
|
|
|
|
|
View(await _context.InstructionSetExtensions.OrderBy(e => e.Extension).ToListAsync());
|
2018-08-11 10:50:22 +01:00
|
|
|
|
|
|
|
|
|
|
// GET: Admin/InstructionSetExtensions/Details/5
|
|
|
|
|
|
public async Task<IActionResult> Details(int? id)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(id == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
|
|
InstructionSetExtension instructionSetExtension =
|
|
|
|
|
|
await _context.InstructionSetExtensions.FirstOrDefaultAsync(m => m.Id == id);
|
|
|
|
|
|
if(instructionSetExtension == null) return NotFound();
|
|
|
|
|
|
|
2019-05-19 23:10:19 +01:00
|
|
|
|
ViewBag.Processors = _context.InstructionSetExtensionsByProcessor.Where(e => e.ExtensionId == id)
|
|
|
|
|
|
.Join(_context.Processors, p => p.ProcessorId, i => i.Id, (p, i) => i)
|
|
|
|
|
|
.Select(p => p.Name);
|
|
|
|
|
|
|
2018-08-11 10:50:22 +01:00
|
|
|
|
return View(instructionSetExtension);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GET: Admin/InstructionSetExtensions/Create
|
2019-05-18 03:02:49 +01:00
|
|
|
|
public IActionResult Create() => View();
|
2018-08-11 10:50:22 +01:00
|
|
|
|
|
|
|
|
|
|
// POST: Admin/InstructionSetExtensions/Create
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
|
public async Task<IActionResult> Create([Bind("Id,Extension")] InstructionSetExtension instructionSetExtension)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(ModelState.IsValid)
|
|
|
|
|
|
{
|
|
|
|
|
|
_context.Add(instructionSetExtension);
|
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return View(instructionSetExtension);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GET: Admin/InstructionSetExtensions/Edit/5
|
|
|
|
|
|
public async Task<IActionResult> Edit(int? id)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(id == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
|
|
InstructionSetExtension instructionSetExtension = await _context.InstructionSetExtensions.FindAsync(id);
|
|
|
|
|
|
if(instructionSetExtension == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
|
|
return View(instructionSetExtension);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// POST: Admin/InstructionSetExtensions/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.
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
|
public async Task<IActionResult> Edit(
|
|
|
|
|
|
int id, [Bind("Id,Extension")] InstructionSetExtension instructionSetExtension)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(id != instructionSetExtension.Id) return NotFound();
|
|
|
|
|
|
|
|
|
|
|
|
if(ModelState.IsValid)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
_context.Update(instructionSetExtension);
|
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch(DbUpdateConcurrencyException)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!InstructionSetExtensionExists(instructionSetExtension.Id)) return NotFound();
|
|
|
|
|
|
|
|
|
|
|
|
throw;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return View(instructionSetExtension);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GET: Admin/InstructionSetExtensions/Delete/5
|
|
|
|
|
|
public async Task<IActionResult> Delete(int? id)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(id == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
|
|
InstructionSetExtension instructionSetExtension =
|
|
|
|
|
|
await _context.InstructionSetExtensions.FirstOrDefaultAsync(m => m.Id == id);
|
|
|
|
|
|
if(instructionSetExtension == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
|
|
return View(instructionSetExtension);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// POST: Admin/InstructionSetExtensions/Delete/5
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
[ActionName("Delete")]
|
|
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
|
public async Task<IActionResult> DeleteConfirmed(int id)
|
|
|
|
|
|
{
|
|
|
|
|
|
InstructionSetExtension instructionSetExtension = await _context.InstructionSetExtensions.FindAsync(id);
|
|
|
|
|
|
_context.InstructionSetExtensions.Remove(instructionSetExtension);
|
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InstructionSetExtensionExists(int id)
|
|
|
|
|
|
{
|
|
|
|
|
|
return _context.InstructionSetExtensions.Any(e => e.Id == id);
|
|
|
|
|
|
}
|
2019-05-19 22:29:16 +01:00
|
|
|
|
|
|
|
|
|
|
[AcceptVerbs("Get", "Post")]
|
|
|
|
|
|
public IActionResult VerifyUnique(string extension) =>
|
|
|
|
|
|
_context.InstructionSetExtensions.Any(i => string.Equals(i.Extension, extension,
|
|
|
|
|
|
StringComparison.InvariantCultureIgnoreCase))
|
|
|
|
|
|
? Json("Instruction set extension already exists.")
|
|
|
|
|
|
: Json(true);
|
2018-08-11 10:50:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|