mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Add instruction set creation in admin view.
This commit is contained in:
@@ -1,170 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// MARECHAI: Master repository of computing history artifacts information
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// 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-2020 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Marechai.Database.Models;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace Marechai.Areas.Admin.Controllers
|
|
||||||
{
|
|
||||||
[Area("Admin"), Authorize]
|
|
||||||
public class InstructionSetExtensionsController : Controller
|
|
||||||
{
|
|
||||||
readonly MarechaiContext _context;
|
|
||||||
|
|
||||||
public InstructionSetExtensionsController(MarechaiContext context) => _context = context;
|
|
||||||
|
|
||||||
// GET: Admin/InstructionSetExtensions
|
|
||||||
public async Task<IActionResult> Index() =>
|
|
||||||
View(await _context.InstructionSetExtensions.OrderBy(e => e.Extension).ToListAsync());
|
|
||||||
|
|
||||||
// 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();
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
return View(instructionSetExtension);
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET: Admin/InstructionSetExtensions/Create
|
|
||||||
public IActionResult Create() => View();
|
|
||||||
|
|
||||||
// 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) => _context.InstructionSetExtensions.Any(e => e.Id == id);
|
|
||||||
|
|
||||||
[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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,160 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// MARECHAI: Master repository of computing history artifacts information
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// 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-2020 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Marechai.Database.Models;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace Marechai.Areas.Admin.Controllers
|
|
||||||
{
|
|
||||||
[Area("Admin"), Authorize]
|
|
||||||
public class InstructionSetsController : Controller
|
|
||||||
{
|
|
||||||
readonly MarechaiContext _context;
|
|
||||||
|
|
||||||
public InstructionSetsController(MarechaiContext context) => _context = context;
|
|
||||||
|
|
||||||
// GET: Admin/InstructionSets
|
|
||||||
public async Task<IActionResult> Index() =>
|
|
||||||
View(await _context.InstructionSets.OrderBy(s => s.Name).ToListAsync());
|
|
||||||
|
|
||||||
// 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
|
|
||||||
public IActionResult Create() => View();
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
{
|
|
||||||
if(!ModelState.IsValid)
|
|
||||||
return View(instructionSet);
|
|
||||||
|
|
||||||
_context.Add(instructionSet);
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
|
|
||||||
return RedirectToAction(nameof(Index));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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) => _context.InstructionSets.Any(e => e.Id == id);
|
|
||||||
|
|
||||||
[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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// MARECHAI: Master repository of computing history artifacts information
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : Create.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Admin view create
|
|
||||||
//
|
|
||||||
// --[ 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-2020 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@model Marechai.Database.Models.InstructionSetExtension
|
|
||||||
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Create";
|
|
||||||
}
|
|
||||||
<h2>Create</h2>
|
|
||||||
<h4>Instruction set extension</h4>
|
|
||||||
<hr />
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-4">
|
|
||||||
<form asp-action="Create">
|
|
||||||
<div asp-validation-summary="ModelOnly" class="text-danger">
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Extension" class="control-label">
|
|
||||||
</label>
|
|
||||||
<input asp-for="Extension" class="form-control" />
|
|
||||||
<span asp-validation-for="Extension" class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<input class="btn btn-primary" type="submit" value="Create" />
|
|
||||||
<a asp-action="Index" class="btn btn-secondary">
|
|
||||||
Back to List
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@section Scripts {
|
|
||||||
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// MARECHAI: Master repository of computing history artifacts information
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : Create.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Admin view create
|
|
||||||
//
|
|
||||||
// --[ 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-2020 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@model Marechai.Database.Models.InstructionSet
|
|
||||||
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Create";
|
|
||||||
}
|
|
||||||
<h2>Create</h2>
|
|
||||||
<h4>Instruction set</h4>
|
|
||||||
<hr />
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-4">
|
|
||||||
<form asp-action="Create">
|
|
||||||
<div asp-validation-summary="ModelOnly" class="text-danger">
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Name" class="control-label">
|
|
||||||
</label>
|
|
||||||
<input asp-for="Name" class="form-control" />
|
|
||||||
<span asp-validation-for="Name" class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<input class="btn btn-primary" type="submit" value="Create" />
|
|
||||||
<a asp-action="Index" class="btn btn-secondary">
|
|
||||||
Back to List
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@section Scripts {
|
|
||||||
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
<Version>3.0.99.1245</Version>
|
<Version>3.0.99.1246</Version>
|
||||||
<Company>Canary Islands Computer Museum</Company>
|
<Company>Canary Islands Computer Museum</Company>
|
||||||
<Copyright>Copyright © 2003-2020 Natalia Portillo</Copyright>
|
<Copyright>Copyright © 2003-2020 Natalia Portillo</Copyright>
|
||||||
<Product>Canary Islands Computer Museum Website</Product>
|
<Product>Canary Islands Computer Museum Website</Product>
|
||||||
@@ -132,5 +132,7 @@
|
|||||||
<_ContentIncludedByDefault Remove="Areas\Admin\Views\DocumentCompanies\Create.cshtml" />
|
<_ContentIncludedByDefault Remove="Areas\Admin\Views\DocumentCompanies\Create.cshtml" />
|
||||||
<_ContentIncludedByDefault Remove="Areas\Admin\Views\DocumentPeople\Create.cshtml" />
|
<_ContentIncludedByDefault Remove="Areas\Admin\Views\DocumentPeople\Create.cshtml" />
|
||||||
<_ContentIncludedByDefault Remove="Areas\Admin\Views\Gpus\Create.cshtml" />
|
<_ContentIncludedByDefault Remove="Areas\Admin\Views\Gpus\Create.cshtml" />
|
||||||
|
<_ContentIncludedByDefault Remove="Areas\Admin\Views\InstructionSetExtensions\Create.cshtml" />
|
||||||
|
<_ContentIncludedByDefault Remove="Areas\Admin\Views\InstructionSets\Create.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
@page "/admin/instruction_sets/details/{Id:int}"
|
@page "/admin/instruction_sets/details/{Id:int}"
|
||||||
@page "/admin/instruction_sets/edit/{Id:int}"
|
@page "/admin/instruction_sets/edit/{Id:int}"
|
||||||
|
@page "/admin/instruction_sets/create"
|
||||||
@inherits OwningComponentBase<InstructionSetsService>
|
@inherits OwningComponentBase<InstructionSetsService>
|
||||||
@inject IStringLocalizer<InstructionSetsService> L
|
@inject IStringLocalizer<InstructionSetsService> L
|
||||||
@attribute [Authorize(Roles = "UberAdmin, Admin")]
|
@attribute [Authorize(Roles = "UberAdmin, Admin")]
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ namespace Marechai.Pages.Admin.Details
|
|||||||
{
|
{
|
||||||
public partial class InstructionSet
|
public partial class InstructionSet
|
||||||
{
|
{
|
||||||
|
bool _creating;
|
||||||
bool _editing;
|
bool _editing;
|
||||||
bool _loaded;
|
bool _loaded;
|
||||||
Database.Models.InstructionSet _model;
|
Database.Models.InstructionSet _model;
|
||||||
@@ -21,12 +22,17 @@ namespace Marechai.Pages.Admin.Details
|
|||||||
|
|
||||||
_loaded = true;
|
_loaded = true;
|
||||||
|
|
||||||
if(Id <= 0)
|
_creating = NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
|
||||||
|
StartsWith("admin/instruction_sets/create",
|
||||||
|
StringComparison.InvariantCulture);
|
||||||
|
|
||||||
|
if(Id <= 0 &&
|
||||||
|
!_creating)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_model = await Service.GetAsync(Id);
|
_model = _creating ? new Database.Models.InstructionSet() : await Service.GetAsync(Id);
|
||||||
|
|
||||||
_editing = NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
|
_editing = _creating || NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
|
||||||
StartsWith("admin/instruction_sets/edit/",
|
StartsWith("admin/instruction_sets/edit/",
|
||||||
StringComparison.InvariantCulture);
|
StringComparison.InvariantCulture);
|
||||||
|
|
||||||
@@ -42,6 +48,14 @@ namespace Marechai.Pages.Admin.Details
|
|||||||
async void OnCancelClicked()
|
async void OnCancelClicked()
|
||||||
{
|
{
|
||||||
_editing = false;
|
_editing = false;
|
||||||
|
|
||||||
|
if(_creating)
|
||||||
|
{
|
||||||
|
NavigationManager.ToBaseRelativePath("admin/instruction_sets");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_model = await Service.GetAsync(Id);
|
_model = await Service.GetAsync(Id);
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
@@ -53,8 +67,13 @@ namespace Marechai.Pages.Admin.Details
|
|||||||
!Service.VerifyUnique(_model.Name))
|
!Service.VerifyUnique(_model.Name))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_editing = false;
|
if(_creating)
|
||||||
|
Id = await Service.CreateAsync(_model);
|
||||||
|
else
|
||||||
await Service.UpdateAsync(_model);
|
await Service.UpdateAsync(_model);
|
||||||
|
|
||||||
|
_editing = false;
|
||||||
|
_creating = false;
|
||||||
_model = await Service.GetAsync(Id);
|
_model = await Service.GetAsync(Id);
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,9 +42,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
<p>
|
<p>
|
||||||
<span class="btn btn-primary">
|
<a class="btn btn-primary" href="/admin/instruction_sets/create">@L["Create new"]</a>
|
||||||
@L["Create new"]
|
|
||||||
</span>
|
|
||||||
</p>
|
</p>
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
|
|||||||
@@ -37,6 +37,19 @@ namespace Marechai.Services
|
|||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<int> CreateAsync(InstructionSet viewModel)
|
||||||
|
{
|
||||||
|
var model = new InstructionSet
|
||||||
|
{
|
||||||
|
Name = viewModel.Name
|
||||||
|
};
|
||||||
|
|
||||||
|
await _context.InstructionSets.AddAsync(model);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
return model.Id;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task DeleteAsync(int id)
|
public async Task DeleteAsync(int id)
|
||||||
{
|
{
|
||||||
InstructionSet item = await _context.InstructionSets.FindAsync(id);
|
InstructionSet item = await _context.InstructionSets.FindAsync(id);
|
||||||
|
|||||||
Reference in New Issue
Block a user