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 : InstructionSetsController.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Instruction sets 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:24:00 +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 InstructionSetsController : Controller
|
|
|
|
|
|
{
|
2020-02-10 02:47:39 +00:00
|
|
|
|
readonly MarechaiContext _context;
|
2018-08-11 10:50:22 +01:00
|
|
|
|
|
2020-02-10 02:47:39 +00:00
|
|
|
|
public InstructionSetsController(MarechaiContext context)
|
2018-08-11 10:50:22 +01:00
|
|
|
|
{
|
|
|
|
|
|
_context = context;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GET: Admin/InstructionSets
|
2019-05-18 20:37:10 +01:00
|
|
|
|
public async Task<IActionResult> Index() =>
|
|
|
|
|
|
View(await _context.InstructionSets.OrderBy(s => s.Name).ToListAsync());
|
2018-08-11 10:50:22 +01:00
|
|
|
|
|
|
|
|
|
|
// GET: Admin/InstructionSets/Details/5
|
|
|
|
|
|
public async Task<IActionResult> Details(int? id)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(id == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
|
|
InstructionSet instructionSet = await _context.InstructionSets.FirstOrDefaultAsync(m => m.Id == id);
|
|
|
|
|
|
if(instructionSet == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
|
|
return View(instructionSet);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GET: Admin/InstructionSets/Create
|
2019-05-18 03:02:49 +01:00
|
|
|
|
public IActionResult Create() => View();
|
2018-08-11 10:50:22 +01:00
|
|
|
|
|
|
|
|
|
|
// POST: Admin/InstructionSets/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,Name")] InstructionSet instructionSet)
|
|
|
|
|
|
{
|
2019-05-18 20:37:10 +01:00
|
|
|
|
if(!ModelState.IsValid) return View(instructionSet);
|
2018-08-11 10:50:22 +01:00
|
|
|
|
|
2019-05-18 20:37:10 +01:00
|
|
|
|
_context.Add(instructionSet);
|
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
2018-08-11 10:50:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GET: Admin/InstructionSets/Edit/5
|
|
|
|
|
|
public async Task<IActionResult> Edit(int? id)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(id == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
|
|
InstructionSet instructionSet = await _context.InstructionSets.FindAsync(id);
|
|
|
|
|
|
if(instructionSet == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
|
|
return View(instructionSet);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// POST: Admin/InstructionSets/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,Name")] InstructionSet instructionSet)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(id != instructionSet.Id) return NotFound();
|
|
|
|
|
|
|
|
|
|
|
|
if(ModelState.IsValid)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
_context.Update(instructionSet);
|
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch(DbUpdateConcurrencyException)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!InstructionSetExists(instructionSet.Id)) return NotFound();
|
|
|
|
|
|
|
|
|
|
|
|
throw;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return View(instructionSet);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GET: Admin/InstructionSets/Delete/5
|
|
|
|
|
|
public async Task<IActionResult> Delete(int? id)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(id == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
|
|
InstructionSet instructionSet = await _context.InstructionSets.FirstOrDefaultAsync(m => m.Id == id);
|
|
|
|
|
|
if(instructionSet == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
|
|
return View(instructionSet);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// POST: Admin/InstructionSets/Delete/5
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
[ActionName("Delete")]
|
|
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
|
public async Task<IActionResult> DeleteConfirmed(int id)
|
|
|
|
|
|
{
|
|
|
|
|
|
InstructionSet instructionSet = await _context.InstructionSets.FindAsync(id);
|
|
|
|
|
|
_context.InstructionSets.Remove(instructionSet);
|
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InstructionSetExists(int id)
|
|
|
|
|
|
{
|
|
|
|
|
|
return _context.InstructionSets.Any(e => e.Id == id);
|
|
|
|
|
|
}
|
2019-05-19 22:24:00 +01:00
|
|
|
|
|
|
|
|
|
|
[AcceptVerbs("Get", "Post")]
|
|
|
|
|
|
public IActionResult VerifyUnique(string name) =>
|
|
|
|
|
|
_context.InstructionSets.Any(i => string.Equals(i.Name, name, StringComparison.InvariantCultureIgnoreCase))
|
|
|
|
|
|
? Json("Instruction set already exists.")
|
|
|
|
|
|
: Json(true);
|
2018-08-11 10:50:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|