mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Allow to add and remove memories from machine details in admin view.
This commit is contained in:
@@ -1,184 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
// MARECHAI: Master repository of computing history artifacts information
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : MemoryByMachinesController.cs
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Memory by machines 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.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Marechai.Areas.Admin.Models;
|
|
||||||
using Marechai.Database.Models;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore.Query;
|
|
||||||
|
|
||||||
namespace Marechai.Areas.Admin.Controllers
|
|
||||||
{
|
|
||||||
[Area("Admin"), Authorize]
|
|
||||||
public class MemoryByMachinesController : Controller
|
|
||||||
{
|
|
||||||
readonly MarechaiContext _context;
|
|
||||||
|
|
||||||
public MemoryByMachinesController(MarechaiContext context) => _context = context;
|
|
||||||
|
|
||||||
// GET: Admin/MemoryByMachines
|
|
||||||
public async Task<IActionResult> Index()
|
|
||||||
{
|
|
||||||
IIncludableQueryable<MemoryByMachine, Machine> marechaiContext =
|
|
||||||
_context.MemoryByMachine.Include(m => m.Machine);
|
|
||||||
|
|
||||||
return View(await marechaiContext.OrderBy(m => m.Machine.Name).ThenBy(m => m.Usage).ThenBy(m => m.Size).
|
|
||||||
ThenBy(m => m.Type).Select(m => new MemoryByMachineViewModel
|
|
||||||
{
|
|
||||||
Id = m.Id, Machine = m.Machine.Name, Size = m.Size, Speed = m.Speed,
|
|
||||||
Type = m.Type, Usage = m.Usage
|
|
||||||
}).ToListAsync());
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET: Admin/MemoryByMachines/Details/5
|
|
||||||
public async Task<IActionResult> Details(long? id)
|
|
||||||
{
|
|
||||||
if(id == null)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
MemoryByMachine memoryByMachine =
|
|
||||||
await _context.MemoryByMachine.Include(m => m.Machine).FirstOrDefaultAsync(m => m.Id == id);
|
|
||||||
|
|
||||||
if(memoryByMachine == null)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
return View(memoryByMachine);
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET: Admin/MemoryByMachines/Create
|
|
||||||
public IActionResult Create()
|
|
||||||
{
|
|
||||||
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name");
|
|
||||||
|
|
||||||
return View();
|
|
||||||
}
|
|
||||||
|
|
||||||
// POST: Admin/MemoryByMachines/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("MachineId,Type,Usage,Size,Speed,Id")]
|
|
||||||
MemoryByMachine memoryByMachine)
|
|
||||||
{
|
|
||||||
if(ModelState.IsValid)
|
|
||||||
{
|
|
||||||
_context.Add(memoryByMachine);
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
|
|
||||||
return RedirectToAction(nameof(Index));
|
|
||||||
}
|
|
||||||
|
|
||||||
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", memoryByMachine.MachineId);
|
|
||||||
|
|
||||||
return View(memoryByMachine);
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET: Admin/MemoryByMachines/Edit/5
|
|
||||||
public async Task<IActionResult> Edit(long? id)
|
|
||||||
{
|
|
||||||
if(id == null)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
MemoryByMachine memoryByMachine = await _context.MemoryByMachine.FindAsync(id);
|
|
||||||
|
|
||||||
if(memoryByMachine == null)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", memoryByMachine.MachineId);
|
|
||||||
|
|
||||||
return View(memoryByMachine);
|
|
||||||
}
|
|
||||||
|
|
||||||
// POST: Admin/MemoryByMachines/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(long id, [Bind("MachineId,Type,Usage,Size,Speed,Id")]
|
|
||||||
MemoryByMachine memoryByMachine)
|
|
||||||
{
|
|
||||||
if(id != memoryByMachine.Id)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
if(ModelState.IsValid)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_context.Update(memoryByMachine);
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
catch(DbUpdateConcurrencyException)
|
|
||||||
{
|
|
||||||
if(!MemoryByMachineExists(memoryByMachine.Id))
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
return RedirectToAction(nameof(Index));
|
|
||||||
}
|
|
||||||
|
|
||||||
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", memoryByMachine.MachineId);
|
|
||||||
|
|
||||||
return View(memoryByMachine);
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET: Admin/MemoryByMachines/Delete/5
|
|
||||||
public async Task<IActionResult> Delete(long? id)
|
|
||||||
{
|
|
||||||
if(id == null)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
MemoryByMachine memoryByMachine =
|
|
||||||
await _context.MemoryByMachine.Include(m => m.Machine).FirstOrDefaultAsync(m => m.Id == id);
|
|
||||||
|
|
||||||
if(memoryByMachine == null)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
return View(memoryByMachine);
|
|
||||||
}
|
|
||||||
|
|
||||||
// POST: Admin/MemoryByMachines/Delete/5
|
|
||||||
[HttpPost, ActionName("Delete"), ValidateAntiForgeryToken]
|
|
||||||
public async Task<IActionResult> DeleteConfirmed(long id)
|
|
||||||
{
|
|
||||||
MemoryByMachine memoryByMachine = await _context.MemoryByMachine.FindAsync(id);
|
|
||||||
_context.MemoryByMachine.Remove(memoryByMachine);
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
|
|
||||||
return RedirectToAction(nameof(Index));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MemoryByMachineExists(long id) => _context.MemoryByMachine.Any(e => e.Id == id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,94 +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
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@using Marechai.Database
|
|
||||||
@model Marechai.Database.Models.MemoryByMachine
|
|
||||||
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Create";
|
|
||||||
}
|
|
||||||
<h2>Create</h2>
|
|
||||||
<h4>Memory by machine</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="Machine" class="control-label">
|
|
||||||
</label>
|
|
||||||
<select asp-for="MachineId" class="form-control" asp-items="ViewBag.MachineId">
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Usage" class="control-label">
|
|
||||||
</label>
|
|
||||||
<select asp-for="Usage" class="form-control" asp-items="Html.GetEnumSelectList<MemoryUsage>().OrderBy(s => s.Text)">
|
|
||||||
</select>
|
|
||||||
<span asp-validation-for="Usage" class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Type" class="control-label">
|
|
||||||
</label>
|
|
||||||
<select asp-for="Type" class="form-control" asp-items="Html.GetEnumSelectList<MemoryType>().OrderBy(s => s.Text)">
|
|
||||||
</select>
|
|
||||||
<span asp-validation-for="Type" class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Size" class="control-label">
|
|
||||||
</label>
|
|
||||||
<input asp-for="Size" class="form-control" />
|
|
||||||
<span asp-validation-for="Size" class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Speed" class="control-label">
|
|
||||||
</label>
|
|
||||||
<input asp-for="Speed" class="form-control" />
|
|
||||||
<span asp-validation-for="Speed" 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,81 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// MARECHAI: Master repository of computing history artifacts information
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : Delete.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Admin view delete
|
|
||||||
//
|
|
||||||
// --[ 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.MemoryByMachine
|
|
||||||
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Delete";
|
|
||||||
}
|
|
||||||
<h2>Delete</h2>
|
|
||||||
<h3>Are you sure you want to delete this?</h3>
|
|
||||||
<div>
|
|
||||||
<h4>Memory by machine</h4>
|
|
||||||
<hr />
|
|
||||||
<dl class="dl-horizontal">
|
|
||||||
<dt>
|
|
||||||
@Html.DisplayNameFor(model => model.Machine)
|
|
||||||
</dt>
|
|
||||||
<dd>
|
|
||||||
@Html.DisplayFor(model => model.Machine.Name)
|
|
||||||
</dd>
|
|
||||||
<dt>
|
|
||||||
@Html.DisplayNameFor(model => model.Usage)
|
|
||||||
</dt>
|
|
||||||
<dd>
|
|
||||||
@Html.DisplayFor(model => model.Usage)
|
|
||||||
</dd>
|
|
||||||
<dt>
|
|
||||||
@Html.DisplayNameFor(model => model.Type)
|
|
||||||
</dt>
|
|
||||||
<dd>
|
|
||||||
@Html.DisplayFor(model => model.Type)
|
|
||||||
</dd>
|
|
||||||
<dt>
|
|
||||||
@Html.DisplayNameFor(model => model.Size)
|
|
||||||
</dt>
|
|
||||||
<dd>
|
|
||||||
@Html.DisplayFor(model => model.Size)
|
|
||||||
</dd>
|
|
||||||
<dt>
|
|
||||||
@Html.DisplayNameFor(model => model.Speed)
|
|
||||||
</dt>
|
|
||||||
<dd>
|
|
||||||
@Html.DisplayFor(model => model.Speed)
|
|
||||||
</dd>
|
|
||||||
</dl>
|
|
||||||
<form asp-action="Delete">
|
|
||||||
<input type="hidden" asp-for="Id" />
|
|
||||||
<input class="btn btn-danger" type="submit" value="Delete" />
|
|
||||||
<a asp-action="Index" class="btn btn-secondary">
|
|
||||||
Back to List
|
|
||||||
</a>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// MARECHAI: Master repository of computing history artifacts information
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : Details.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Admin view details
|
|
||||||
//
|
|
||||||
// --[ 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.MemoryByMachine
|
|
||||||
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Details";
|
|
||||||
}
|
|
||||||
<h2>Details</h2>
|
|
||||||
<div>
|
|
||||||
<h4>Memory by machine</h4>
|
|
||||||
<hr />
|
|
||||||
<dl class="dl-horizontal">
|
|
||||||
<dt>
|
|
||||||
@Html.DisplayNameFor(model => model.Machine)
|
|
||||||
</dt>
|
|
||||||
<dd>
|
|
||||||
@Html.DisplayFor(model => model.Machine.Name)
|
|
||||||
</dd>
|
|
||||||
<dt>
|
|
||||||
@Html.DisplayNameFor(model => model.Usage)
|
|
||||||
</dt>
|
|
||||||
<dd>
|
|
||||||
@Html.DisplayFor(model => model.Usage)
|
|
||||||
</dd>
|
|
||||||
<dt>
|
|
||||||
@Html.DisplayNameFor(model => model.Type)
|
|
||||||
</dt>
|
|
||||||
<dd>
|
|
||||||
@Html.DisplayFor(model => model.Type)
|
|
||||||
</dd>
|
|
||||||
<dt>
|
|
||||||
@Html.DisplayNameFor(model => model.Size)
|
|
||||||
</dt>
|
|
||||||
<dd>
|
|
||||||
@Html.DisplayFor(model => model.Size)
|
|
||||||
</dd>
|
|
||||||
<dt>
|
|
||||||
@Html.DisplayNameFor(model => model.Speed)
|
|
||||||
</dt>
|
|
||||||
<dd>
|
|
||||||
@Html.DisplayFor(model => model.Speed)
|
|
||||||
</dd>
|
|
||||||
</dl>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<a asp-action="Edit" asp-route-id="@Model.Id" class="btn btn-primary">
|
|
||||||
Edit
|
|
||||||
</a>
|
|
||||||
<a asp-action="Index" class="btn btn-secondary">
|
|
||||||
Back to List
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// MARECHAI: Master repository of computing history artifacts information
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : Edit.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Admin view edit
|
|
||||||
//
|
|
||||||
// --[ 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 Marechai.Database
|
|
||||||
@model Marechai.Database.Models.MemoryByMachine
|
|
||||||
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Edit";
|
|
||||||
}
|
|
||||||
<h2>Edit</h2>
|
|
||||||
<h4>Memory by machine</h4>
|
|
||||||
<hr />
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-4">
|
|
||||||
<form asp-action="Edit">
|
|
||||||
<div asp-validation-summary="ModelOnly" class="text-danger">
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="MachineId" class="control-label">
|
|
||||||
</label>
|
|
||||||
<select asp-for="MachineId" class="form-control" asp-items="ViewBag.MachineId">
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Usage" class="control-label">
|
|
||||||
</label>
|
|
||||||
<select asp-for="Usage" class="form-control" asp-items="Html.GetEnumSelectList<MemoryUsage>().OrderBy(s => s.Text)">
|
|
||||||
</select>
|
|
||||||
<span asp-validation-for="Usage" class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Type" class="control-label">
|
|
||||||
</label>
|
|
||||||
<select asp-for="Type" class="form-control" asp-items="Html.GetEnumSelectList<MemoryType>().OrderBy(s => s.Text)">
|
|
||||||
</select>
|
|
||||||
<span asp-validation-for="Type" class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Size" class="control-label">
|
|
||||||
</label>
|
|
||||||
<input asp-for="Size" class="form-control" />
|
|
||||||
<span asp-validation-for="Size" class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Speed" class="control-label">
|
|
||||||
</label>
|
|
||||||
<input asp-for="Speed" class="form-control" />
|
|
||||||
<span asp-validation-for="Speed" class="text-danger">
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<input type="hidden" asp-for="Id" />
|
|
||||||
<div class="form-group">
|
|
||||||
<input class="btn btn-primary" type="submit" value="Save" />
|
|
||||||
<a asp-action="Index" class="btn btn-secondary">
|
|
||||||
Back to List
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@section Scripts {
|
|
||||||
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
|
||||||
}
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// MARECHAI: Master repository of computing history artifacts information
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : Index.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ Description ] ----------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Admin view index
|
|
||||||
//
|
|
||||||
// --[ 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 IEnumerable<Marechai.Areas.Admin.Models.MemoryByMachineViewModel>
|
|
||||||
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Memory by machines (Admin)";
|
|
||||||
}
|
|
||||||
<h2>Memory by machines</h2>
|
|
||||||
<p>
|
|
||||||
<a asp-action="Create" class="btn btn-primary">
|
|
||||||
Create new
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
<table class="table">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
@Html.DisplayNameFor(model => model.Machine)
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
@Html.DisplayNameFor(model => model.Usage)
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
@Html.DisplayNameFor(model => model.Type)
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
@Html.DisplayNameFor(model => model.Size)
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
@Html.DisplayNameFor(model => model.Speed)
|
|
||||||
</th>
|
|
||||||
<th></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
@foreach (var item in Model)
|
|
||||||
{
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
@Html.DisplayFor(modelItem => item.Machine)
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
@Html.DisplayFor(modelItem => item.Usage)
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
@Html.DisplayFor(modelItem => item.Type)
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
@Html.DisplayFor(modelItem => item.Size)
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
@Html.DisplayFor(modelItem => item.Speed)
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<a asp-action="Details" asp-route-id="@item.Id" class="btn btn-primary">
|
|
||||||
Details
|
|
||||||
</a>
|
|
||||||
<a asp-action="Edit" asp-route-id="@item.Id" class="btn btn-secondary">
|
|
||||||
Edit
|
|
||||||
</a>
|
|
||||||
<a asp-action="Delete" asp-route-id="@item.Id" class="btn btn-danger">
|
|
||||||
Delete
|
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
@@ -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.1385</Version>
|
<Version>3.0.99.1387</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>
|
||||||
@@ -159,5 +159,10 @@
|
|||||||
<_ContentIncludedByDefault Remove="Areas\Admin\Views\ProcessorsByMachines\Details.cshtml" />
|
<_ContentIncludedByDefault Remove="Areas\Admin\Views\ProcessorsByMachines\Details.cshtml" />
|
||||||
<_ContentIncludedByDefault Remove="Areas\Admin\Views\ProcessorsByMachines\Edit.cshtml" />
|
<_ContentIncludedByDefault Remove="Areas\Admin\Views\ProcessorsByMachines\Edit.cshtml" />
|
||||||
<_ContentIncludedByDefault Remove="Areas\Admin\Views\ProcessorsByMachines\Index.cshtml" />
|
<_ContentIncludedByDefault Remove="Areas\Admin\Views\ProcessorsByMachines\Index.cshtml" />
|
||||||
|
<_ContentIncludedByDefault Remove="Areas\Admin\Views\MemoryByMachines\Create.cshtml" />
|
||||||
|
<_ContentIncludedByDefault Remove="Areas\Admin\Views\MemoryByMachines\Delete.cshtml" />
|
||||||
|
<_ContentIncludedByDefault Remove="Areas\Admin\Views\MemoryByMachines\Details.cshtml" />
|
||||||
|
<_ContentIncludedByDefault Remove="Areas\Admin\Views\MemoryByMachines\Edit.cshtml" />
|
||||||
|
<_ContentIncludedByDefault Remove="Areas\Admin\Views\MemoryByMachines\Index.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -45,6 +45,7 @@
|
|||||||
@inject SoundSynthsService SoundSynthsService
|
@inject SoundSynthsService SoundSynthsService
|
||||||
@inject ProcessorsByMachineService ProcessorsByMachineService
|
@inject ProcessorsByMachineService ProcessorsByMachineService
|
||||||
@inject ProcessorsService ProcessorsService
|
@inject ProcessorsService ProcessorsService
|
||||||
|
@inject MemoriesByMachineService MemoriesByMachineService
|
||||||
@attribute [Authorize(Roles = "UberAdmin, Admin")]
|
@attribute [Authorize(Roles = "UberAdmin, Admin")]
|
||||||
<h3>@L["Machine details"]</h3>
|
<h3>@L["Machine details"]</h3>
|
||||||
<hr />
|
<hr />
|
||||||
@@ -345,6 +346,123 @@
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<hr />
|
||||||
|
<h3>@L["Memory belonging to this machine"]</h3>
|
||||||
|
<Button Color="Color.Success" Clicked="OnAddMemoryClick" Disabled="_addingMemory">@L["Add new (memory by machine)"]</Button>
|
||||||
|
@if (_addingMemory)
|
||||||
|
{
|
||||||
|
<div>
|
||||||
|
<Field>
|
||||||
|
<FieldLabel>@L["Memory type"]</FieldLabel>
|
||||||
|
<Select TValue="int" @bind-SelectedValue="@_addingMemoryType">
|
||||||
|
@foreach (int type in Enum.GetValues(typeof(MemoryType)))
|
||||||
|
{
|
||||||
|
<SelectItem TValue="int" Value="@type">@(((MemoryType)type).ToString())</SelectItem>
|
||||||
|
}
|
||||||
|
</Select>
|
||||||
|
</Field>
|
||||||
|
<Field>
|
||||||
|
<FieldLabel>@L["Memory usage"]</FieldLabel>
|
||||||
|
<Select TValue="int" @bind-SelectedValue="@_addingMemoryUsage">
|
||||||
|
@foreach (int usage in Enum.GetValues(typeof(MemoryUsage)))
|
||||||
|
{
|
||||||
|
<SelectItem TValue="int" Value="@usage">@(((MemoryUsage)usage).ToString())</SelectItem>
|
||||||
|
}
|
||||||
|
</Select>
|
||||||
|
</Field>
|
||||||
|
<Field>
|
||||||
|
<FieldLabel>@L["Nominal speed (MHz)"]</FieldLabel>
|
||||||
|
<Check TValue="bool" @bind-Checked="@_unknownMemorySpeed">@L["Unknown (memory by machine speed)"]</Check>
|
||||||
|
@if (!_unknownMemorySpeed)
|
||||||
|
{
|
||||||
|
<Validation Validator="@ValidateMemorySpeed">
|
||||||
|
<NumericEdit TValue="double?" Decimals="3" @bind-Value="@_addingMemorySpeed" >
|
||||||
|
<Feedback>
|
||||||
|
<ValidationError>@L["Please enter a valid speed for this memory."]</ValidationError>
|
||||||
|
</Feedback>
|
||||||
|
</NumericEdit>
|
||||||
|
</Validation>
|
||||||
|
}
|
||||||
|
</Field>
|
||||||
|
<Field>
|
||||||
|
<FieldLabel>@L["Memory size (bytes)"]</FieldLabel>
|
||||||
|
<Check TValue="bool" @bind-Checked="@_unknownMemorySize">@L["Unknown (memory by machine size)"]</Check>
|
||||||
|
@if (!_unknownMemorySize)
|
||||||
|
{
|
||||||
|
<Validation Validator="@ValidateMemorySize">
|
||||||
|
<NumericEdit TValue="long?" Decimals="0" @bind-Value="@_addingMemorySize" >
|
||||||
|
<Feedback>
|
||||||
|
<ValidationError>@L["Please enter a valid size for this memory."]</ValidationError>
|
||||||
|
</Feedback>
|
||||||
|
</NumericEdit>
|
||||||
|
</Validation>
|
||||||
|
}
|
||||||
|
</Field>
|
||||||
|
<Button Color="Color.Primary" Clicked="@CancelAddMemory" Disabled="@_savingMemory">@L["Cancel"]</Button>
|
||||||
|
<Button Color="Color.Success" Clicked="@ConfirmAddMemory" Disabled="@_savingMemory">@L["Add"]</Button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
@if (_machineMemories?.Count > 0)
|
||||||
|
{
|
||||||
|
<div>
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
@L["Type"]
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
@L["Usage"]
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
@L["Size"]
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
@L["Speed"]
|
||||||
|
</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach (var item in _machineMemories)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
@item.Type
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@item.Usage
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@if (item.Size.HasValue)
|
||||||
|
{
|
||||||
|
@string.Format(L["{0} bytes"], item.Size)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
@L["Unknown (memory by machine speed)"]
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@if (item.Speed.HasValue)
|
||||||
|
{
|
||||||
|
@string.Format(L["{0:F3} MHz"], item.Speed)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
@L["Unknown (memory by machine speed)"]
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<Button Color="Color.Danger" Clicked="() => {ShowMemoryDeleteModal(item.Id);}" Disabled="@_addingMemory">@L["Delete"]</Button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
<Modal @ref="_frmDelete" IsCentered="true" Closing="@ModalClosing">
|
<Modal @ref="_frmDelete" IsCentered="true" Closing="@ModalClosing">
|
||||||
<ModalBackdrop />
|
<ModalBackdrop />
|
||||||
<ModalContent Centered="true">
|
<ModalContent Centered="true">
|
||||||
|
|||||||
@@ -12,10 +12,16 @@ namespace Marechai.Pages.Admin.Details
|
|||||||
{
|
{
|
||||||
public partial class Machine
|
public partial class Machine
|
||||||
{
|
{
|
||||||
bool _addingCpu;
|
bool _addingCpu;
|
||||||
int? _addingCpuId;
|
int? _addingCpuId;
|
||||||
bool _addingGpu;
|
bool _addingGpu;
|
||||||
int? _addingGpuId;
|
int? _addingGpuId;
|
||||||
|
bool _addingMemory;
|
||||||
|
long? _addingMemorySize;
|
||||||
|
double? _addingMemorySpeed;
|
||||||
|
|
||||||
|
int _addingMemoryType;
|
||||||
|
int _addingMemoryUsage;
|
||||||
float? _addingProcessorSpeed;
|
float? _addingProcessorSpeed;
|
||||||
bool _addingSound;
|
bool _addingSound;
|
||||||
int? _addingSoundId;
|
int? _addingSoundId;
|
||||||
@@ -24,12 +30,14 @@ namespace Marechai.Pages.Admin.Details
|
|||||||
bool _creating;
|
bool _creating;
|
||||||
ProcessorByMachineViewModel _currentCpuByMachine;
|
ProcessorByMachineViewModel _currentCpuByMachine;
|
||||||
GpuByMachineViewModel _currentGpuByMachine;
|
GpuByMachineViewModel _currentGpuByMachine;
|
||||||
|
MemoryByMachineViewModel _currentMemoryByMachine;
|
||||||
SoundSynthByMachineViewModel _currentSoundByMachine;
|
SoundSynthByMachineViewModel _currentSoundByMachine;
|
||||||
bool _deleteInProgress;
|
bool _deleteInProgress;
|
||||||
string _deleteText;
|
string _deleteText;
|
||||||
string _deleteTitle;
|
string _deleteTitle;
|
||||||
bool _deletingCpuByMachine;
|
bool _deletingCpuByMachine;
|
||||||
bool _deletingGpuByMachine;
|
bool _deletingGpuByMachine;
|
||||||
|
bool _deletingMemoryByMachine;
|
||||||
bool _deletingSoundByMachine;
|
bool _deletingSoundByMachine;
|
||||||
bool _editing;
|
bool _editing;
|
||||||
List<MachineFamilyViewModel> _families;
|
List<MachineFamilyViewModel> _families;
|
||||||
@@ -38,15 +46,19 @@ namespace Marechai.Pages.Admin.Details
|
|||||||
bool _loaded;
|
bool _loaded;
|
||||||
List<ProcessorByMachineViewModel> _machineCpus;
|
List<ProcessorByMachineViewModel> _machineCpus;
|
||||||
List<GpuByMachineViewModel> _machineGpus;
|
List<GpuByMachineViewModel> _machineGpus;
|
||||||
|
List<MemoryByMachineViewModel> _machineMemories;
|
||||||
List<SoundSynthByMachineViewModel> _machineSound;
|
List<SoundSynthByMachineViewModel> _machineSound;
|
||||||
MachineViewModel _model;
|
MachineViewModel _model;
|
||||||
bool _noFamily;
|
bool _noFamily;
|
||||||
bool _prototype;
|
bool _prototype;
|
||||||
bool _savingCpu;
|
bool _savingCpu;
|
||||||
bool _savingGpu;
|
bool _savingGpu;
|
||||||
|
bool _savingMemory;
|
||||||
bool _savingSound;
|
bool _savingSound;
|
||||||
List<SoundSynthViewModel> _soundSynths;
|
List<SoundSynthViewModel> _soundSynths;
|
||||||
bool _unknownIntroduced;
|
bool _unknownIntroduced;
|
||||||
|
bool _unknownMemorySize;
|
||||||
|
bool _unknownMemorySpeed;
|
||||||
bool _unknownModel;
|
bool _unknownModel;
|
||||||
bool _unknownProcessorSpeed;
|
bool _unknownProcessorSpeed;
|
||||||
[Parameter]
|
[Parameter]
|
||||||
@@ -72,14 +84,15 @@ namespace Marechai.Pages.Admin.Details
|
|||||||
!_creating)
|
!_creating)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_companies = await CompaniesService.GetAsync();
|
_companies = await CompaniesService.GetAsync();
|
||||||
_families = await MachineFamiliesService.GetAsync();
|
_families = await MachineFamiliesService.GetAsync();
|
||||||
_model = _creating ? new MachineViewModel() : await Service.GetAsync(Id);
|
_model = _creating ? new MachineViewModel() : await Service.GetAsync(Id);
|
||||||
_machineGpus = await GpusByMachineService.GetByMachine(Id);
|
_machineGpus = await GpusByMachineService.GetByMachine(Id);
|
||||||
_machineCpus = await ProcessorsByMachineService.GetByMachine(Id);
|
_machineCpus = await ProcessorsByMachineService.GetByMachine(Id);
|
||||||
_gpus = await GpusService.GetAsync();
|
_gpus = await GpusService.GetAsync();
|
||||||
_cpus = await ProcessorsService.GetAsync();
|
_cpus = await ProcessorsService.GetAsync();
|
||||||
_soundSynths = await SoundSynthsService.GetAsync();
|
_soundSynths = await SoundSynthsService.GetAsync();
|
||||||
|
_machineMemories = await MemoriesByMachineService.GetByMachine(Id);
|
||||||
|
|
||||||
_editing = _creating || NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
|
_editing = _creating || NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
|
||||||
StartsWith("admin/machines/edit/",
|
StartsWith("admin/machines/edit/",
|
||||||
@@ -220,7 +233,7 @@ namespace Marechai.Pages.Admin.Details
|
|||||||
_currentCpuByMachine = null;
|
_currentCpuByMachine = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async Task OnAddGpuClick()
|
void OnAddGpuClick()
|
||||||
{
|
{
|
||||||
_addingGpu = true;
|
_addingGpu = true;
|
||||||
_savingGpu = false;
|
_savingGpu = false;
|
||||||
@@ -299,7 +312,7 @@ namespace Marechai.Pages.Admin.Details
|
|||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
async Task OnAddSoundClick()
|
void OnAddSoundClick()
|
||||||
{
|
{
|
||||||
_addingSound = true;
|
_addingSound = true;
|
||||||
_savingSound = false;
|
_savingSound = false;
|
||||||
@@ -383,7 +396,7 @@ namespace Marechai.Pages.Admin.Details
|
|||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
async Task OnAddCpuClick()
|
void OnAddCpuClick()
|
||||||
{
|
{
|
||||||
_addingCpu = true;
|
_addingCpu = true;
|
||||||
_savingCpu = false;
|
_savingCpu = false;
|
||||||
@@ -441,5 +454,107 @@ namespace Marechai.Pages.Admin.Details
|
|||||||
|
|
||||||
e.Status = item > 0 ? ValidationStatus.Success : ValidationStatus.Error;
|
e.Status = item > 0 ? ValidationStatus.Success : ValidationStatus.Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ShowMemoryDeleteModal(long itemId)
|
||||||
|
{
|
||||||
|
_currentMemoryByMachine = _machineMemories.FirstOrDefault(n => n.Id == itemId);
|
||||||
|
_deletingMemoryByMachine = true;
|
||||||
|
_deleteTitle = L["Delete memory from this machine"];
|
||||||
|
|
||||||
|
_deleteText =
|
||||||
|
string.Format(L["Are you sure you want to delete the memory type {0} with usage {1} from this machine?"],
|
||||||
|
_currentMemoryByMachine?.Type, _currentMemoryByMachine?.Usage);
|
||||||
|
|
||||||
|
_frmDelete.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task ConfirmDeleteMemoryByMachine()
|
||||||
|
{
|
||||||
|
if(_currentMemoryByMachine is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_deleteInProgress = true;
|
||||||
|
|
||||||
|
// Yield thread to let UI to update
|
||||||
|
await Task.Yield();
|
||||||
|
|
||||||
|
await MemoriesByMachineService.DeleteAsync(_currentMemoryByMachine.Id);
|
||||||
|
_machineMemories = await MemoriesByMachineService.GetByMachine(Id);
|
||||||
|
|
||||||
|
_deleteInProgress = false;
|
||||||
|
_frmDelete.Hide();
|
||||||
|
|
||||||
|
// Yield thread to let UI to update
|
||||||
|
await Task.Yield();
|
||||||
|
|
||||||
|
// Tell we finished loading
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnAddMemoryClick()
|
||||||
|
{
|
||||||
|
_addingMemory = true;
|
||||||
|
_savingMemory = false;
|
||||||
|
_addingMemorySpeed = 0;
|
||||||
|
_unknownMemorySpeed = true;
|
||||||
|
_addingMemorySize = 0;
|
||||||
|
_unknownMemorySize = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CancelAddMemory()
|
||||||
|
{
|
||||||
|
_addingMemory = false;
|
||||||
|
_savingMemory = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task ConfirmAddMemory()
|
||||||
|
{
|
||||||
|
// TODO: Validation
|
||||||
|
|
||||||
|
_savingMemory = true;
|
||||||
|
|
||||||
|
// Yield thread to let UI to update
|
||||||
|
await Task.Yield();
|
||||||
|
|
||||||
|
await MemoriesByMachineService.CreateAsync(Id, (MemoryType)_addingMemoryType,
|
||||||
|
(MemoryUsage)_addingMemoryUsage,
|
||||||
|
_unknownMemorySize ? null : _addingMemorySize,
|
||||||
|
_unknownMemorySpeed ? null : _addingMemorySpeed);
|
||||||
|
|
||||||
|
_machineMemories = await MemoriesByMachineService.GetByMachine(Id);
|
||||||
|
|
||||||
|
_addingMemory = false;
|
||||||
|
_savingMemory = false;
|
||||||
|
|
||||||
|
// Yield thread to let UI to update
|
||||||
|
await Task.Yield();
|
||||||
|
|
||||||
|
// Tell we finished loading
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ValidateMemorySpeed(ValidatorEventArgs e)
|
||||||
|
{
|
||||||
|
if(!(e.Value is double item))
|
||||||
|
{
|
||||||
|
e.Status = ValidationStatus.Error;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
e.Status = item > 0 ? ValidationStatus.Success : ValidationStatus.Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ValidateMemorySize(ValidatorEventArgs e)
|
||||||
|
{
|
||||||
|
if(!(e.Value is long item))
|
||||||
|
{
|
||||||
|
e.Status = ValidationStatus.Error;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
e.Status = item > 0 ? ValidationStatus.Success : ValidationStatus.Error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
51
Marechai/Services/MemoriesByMachineService.cs
Normal file
51
Marechai/Services/MemoriesByMachineService.cs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Marechai.Database;
|
||||||
|
using Marechai.Database.Models;
|
||||||
|
using Marechai.ViewModels;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Marechai.Services
|
||||||
|
{
|
||||||
|
public class MemoriesByMachineService
|
||||||
|
{
|
||||||
|
readonly MarechaiContext _context;
|
||||||
|
|
||||||
|
public MemoriesByMachineService(MarechaiContext context) => _context = context;
|
||||||
|
|
||||||
|
public async Task<List<MemoryByMachineViewModel>> GetByMachine(int machineId) =>
|
||||||
|
await _context.MemoryByMachine.Where(m => m.MachineId == machineId).Select(m => new MemoryByMachineViewModel
|
||||||
|
{
|
||||||
|
Id = m.Id, Type = m.Type, Usage = m.Usage, Size = m.Size,
|
||||||
|
Speed = m.Speed, MachineId = m.MachineId
|
||||||
|
}).OrderBy(m => m.Type).ThenBy(m => m.Usage).ThenBy(m => m.Size).ThenBy(m => m.Speed).ToListAsync();
|
||||||
|
|
||||||
|
public async Task DeleteAsync(long id)
|
||||||
|
{
|
||||||
|
MemoryByMachine item = await _context.MemoryByMachine.FindAsync(id);
|
||||||
|
|
||||||
|
if(item is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_context.MemoryByMachine.Remove(item);
|
||||||
|
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<long> CreateAsync(int machineId, MemoryType type, MemoryUsage usage, long? size,
|
||||||
|
double? speed)
|
||||||
|
{
|
||||||
|
var item = new MemoryByMachine
|
||||||
|
{
|
||||||
|
MachineId = machineId, Type = type, Usage = usage, Size = size,
|
||||||
|
Speed = speed
|
||||||
|
};
|
||||||
|
|
||||||
|
await _context.MemoryByMachine.AddAsync(item);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
return item.Id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -65,6 +65,7 @@ namespace Marechai.Services
|
|||||||
services.AddScoped<GpusByMachineService>();
|
services.AddScoped<GpusByMachineService>();
|
||||||
services.AddScoped<SoundSynthsByMachineService>();
|
services.AddScoped<SoundSynthsByMachineService>();
|
||||||
services.AddScoped<ProcessorsByMachineService>();
|
services.AddScoped<ProcessorsByMachineService>();
|
||||||
|
services.AddScoped<MemoriesByMachineService>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
13
Marechai/ViewModels/MemoryByMachineViewModel.cs
Normal file
13
Marechai/ViewModels/MemoryByMachineViewModel.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using Marechai.Database;
|
||||||
|
|
||||||
|
namespace Marechai.ViewModels
|
||||||
|
{
|
||||||
|
public class MemoryByMachineViewModel : BaseViewModel<long>
|
||||||
|
{
|
||||||
|
public int MachineId { get; set; }
|
||||||
|
public MemoryType Type { get; set; }
|
||||||
|
public MemoryUsage Usage { get; set; }
|
||||||
|
public long? Size { get; set; }
|
||||||
|
public double? Speed { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user