mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Allow to add and remove sound synthesizers from machine details in admin view.
This commit is contained in:
@@ -1,158 +0,0 @@
|
|||||||
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 SoundByMachineController : Controller
|
|
||||||
{
|
|
||||||
readonly MarechaiContext _context;
|
|
||||||
|
|
||||||
public SoundByMachineController(MarechaiContext context) => _context = context;
|
|
||||||
|
|
||||||
// GET: SoundByMachine
|
|
||||||
public async Task<IActionResult> Index()
|
|
||||||
{
|
|
||||||
IIncludableQueryable<SoundByMachine, SoundSynth> marechaiContext =
|
|
||||||
_context.SoundByMachine.Include(s => s.Machine).Include(s => s.SoundSynth);
|
|
||||||
|
|
||||||
return View(await marechaiContext.OrderBy(s => s.Machine.Name).ThenBy(s => s.SoundSynth.Name).
|
|
||||||
Select(s => new SoundByMachineViewModel
|
|
||||||
{
|
|
||||||
Id = s.Id, Machine = s.Machine.Name, SoundSynth = s.SoundSynth.Name
|
|
||||||
}).ToListAsync());
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET: SoundByMachine/Details/5
|
|
||||||
public async Task<IActionResult> Details(long? id)
|
|
||||||
{
|
|
||||||
if(id == null)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
SoundByMachine soundByMachine = await _context.
|
|
||||||
SoundByMachine.Include(s => s.Machine).Include(s => s.SoundSynth).
|
|
||||||
FirstOrDefaultAsync(m => m.Id == id);
|
|
||||||
|
|
||||||
if(soundByMachine == null)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
return View(soundByMachine);
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET: SoundByMachine/Create
|
|
||||||
public IActionResult Create()
|
|
||||||
{
|
|
||||||
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name");
|
|
||||||
ViewData["SoundSynthId"] = new SelectList(_context.SoundSynths, "Id", "Name");
|
|
||||||
|
|
||||||
return View();
|
|
||||||
}
|
|
||||||
|
|
||||||
// POST: SoundByMachine/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("SoundSynthId,MachineId,Id")] SoundByMachine soundByMachine)
|
|
||||||
{
|
|
||||||
if(ModelState.IsValid)
|
|
||||||
{
|
|
||||||
_context.Add(soundByMachine);
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
|
|
||||||
return RedirectToAction(nameof(Index));
|
|
||||||
}
|
|
||||||
|
|
||||||
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", soundByMachine.MachineId);
|
|
||||||
ViewData["SoundSynthId"] = new SelectList(_context.SoundSynths, "Id", "Name", soundByMachine.SoundSynthId);
|
|
||||||
|
|
||||||
return View(soundByMachine);
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET: SoundByMachine/Edit/5
|
|
||||||
public async Task<IActionResult> Edit(long? id)
|
|
||||||
{
|
|
||||||
if(id == null)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
SoundByMachine soundByMachine = await _context.SoundByMachine.FindAsync(id);
|
|
||||||
|
|
||||||
if(soundByMachine == null)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", soundByMachine.MachineId);
|
|
||||||
ViewData["SoundSynthId"] = new SelectList(_context.SoundSynths, "Id", "Name", soundByMachine.SoundSynthId);
|
|
||||||
|
|
||||||
return View(soundByMachine);
|
|
||||||
}
|
|
||||||
|
|
||||||
// POST: SoundByMachine/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("SoundSynthId,MachineId,Id")] SoundByMachine soundByMachine)
|
|
||||||
{
|
|
||||||
if(id != soundByMachine.Id)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
if(ModelState.IsValid)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_context.Update(soundByMachine);
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
catch(DbUpdateConcurrencyException)
|
|
||||||
{
|
|
||||||
if(!SoundByMachineExists(soundByMachine.Id))
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
return RedirectToAction(nameof(Index));
|
|
||||||
}
|
|
||||||
|
|
||||||
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", soundByMachine.MachineId);
|
|
||||||
ViewData["SoundSynthId"] = new SelectList(_context.SoundSynths, "Id", "Name", soundByMachine.SoundSynthId);
|
|
||||||
|
|
||||||
return View(soundByMachine);
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET: SoundByMachine/Delete/5
|
|
||||||
public async Task<IActionResult> Delete(long? id)
|
|
||||||
{
|
|
||||||
if(id == null)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
SoundByMachine soundByMachine = await _context.
|
|
||||||
SoundByMachine.Include(s => s.Machine).Include(s => s.SoundSynth).
|
|
||||||
FirstOrDefaultAsync(m => m.Id == id);
|
|
||||||
|
|
||||||
if(soundByMachine == null)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
return View(soundByMachine);
|
|
||||||
}
|
|
||||||
|
|
||||||
// POST: SoundByMachine/Delete/5
|
|
||||||
[HttpPost, ActionName("Delete"), ValidateAntiForgeryToken]
|
|
||||||
public async Task<IActionResult> DeleteConfirmed(long id)
|
|
||||||
{
|
|
||||||
SoundByMachine soundByMachine = await _context.SoundByMachine.FindAsync(id);
|
|
||||||
_context.SoundByMachine.Remove(soundByMachine);
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
|
|
||||||
return RedirectToAction(nameof(Index));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SoundByMachineExists(long id) => _context.SoundByMachine.Any(e => e.Id == id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
@model Marechai.Database.Models.SoundByMachine
|
|
||||||
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Create";
|
|
||||||
}
|
|
||||||
<h1>Create</h1>
|
|
||||||
<h4>Sound 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="SoundSynth" class="control-label"></label>
|
|
||||||
<select asp-for="SoundSynthId" class="form-control" asp-items="ViewBag.SoundSynthId"></select>
|
|
||||||
</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">
|
|
||||||
<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>
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
@model Marechai.Database.Models.SoundByMachine
|
|
||||||
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Delete";
|
|
||||||
}
|
|
||||||
<h1>Delete</h1>
|
|
||||||
<h3>Are you sure you want to delete this?</h3>
|
|
||||||
<div>
|
|
||||||
<h4>Sound by machine</h4>
|
|
||||||
<hr />
|
|
||||||
<dl class="row">
|
|
||||||
<dt class="col-sm-2">
|
|
||||||
@Html.DisplayNameFor(model => model.Machine)
|
|
||||||
</dt>
|
|
||||||
<dd class="col-sm-10">
|
|
||||||
@Html.DisplayFor(model => model.Machine.Name)
|
|
||||||
</dd>
|
|
||||||
<dt class="col-sm-2">
|
|
||||||
@Html.DisplayNameFor(model => model.SoundSynth)
|
|
||||||
</dt>
|
|
||||||
<dd class="col-sm-10">
|
|
||||||
@Html.DisplayFor(model => model.SoundSynth.Name)
|
|
||||||
</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,28 +0,0 @@
|
|||||||
@model Marechai.Database.Models.SoundByMachine
|
|
||||||
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Details";
|
|
||||||
}
|
|
||||||
<h1>Details</h1>
|
|
||||||
<div>
|
|
||||||
<h4>Sound by machine</h4>
|
|
||||||
<hr />
|
|
||||||
<dl class="row">
|
|
||||||
<dt class="col-sm-2">
|
|
||||||
@Html.DisplayNameFor(model => model.Machine)
|
|
||||||
</dt>
|
|
||||||
<dd class="col-sm-10">
|
|
||||||
@Html.DisplayFor(model => model.Machine.Name)
|
|
||||||
</dd>
|
|
||||||
<dt class="col-sm-2">
|
|
||||||
@Html.DisplayNameFor(model => model.SoundSynth)
|
|
||||||
</dt>
|
|
||||||
<dd class="col-sm-10">
|
|
||||||
@Html.DisplayFor(model => model.SoundSynth.Name)
|
|
||||||
</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,30 +0,0 @@
|
|||||||
@model Marechai.Database.Models.SoundByMachine
|
|
||||||
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Edit";
|
|
||||||
}
|
|
||||||
<h1>Edit</h1>
|
|
||||||
<h4>Sound 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="SoundSynth" class="control-label"></label>
|
|
||||||
<select asp-for="SoundSynthId" class="form-control" asp-items="ViewBag.SoundSynthId"></select>
|
|
||||||
<span asp-validation-for="SoundSynthId" class="text-danger"></span>
|
|
||||||
</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>
|
|
||||||
<span asp-validation-for="MachineId" 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>
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
@model IEnumerable<Marechai.Areas.Admin.Models.SoundByMachineViewModel>
|
|
||||||
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Index";
|
|
||||||
}
|
|
||||||
<h1>Sound synthesizers by machine</h1>
|
|
||||||
<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.SoundSynth)
|
|
||||||
</th>
|
|
||||||
<th></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
@foreach (var item in Model)
|
|
||||||
{
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
@Html.DisplayFor(modelItem => item.Machine)
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
@Html.DisplayFor(modelItem => item.SoundSynth)
|
|
||||||
</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.1373</Version>
|
<Version>3.0.99.1374</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>
|
||||||
@@ -149,5 +149,10 @@
|
|||||||
<_ContentIncludedByDefault Remove="Areas\Admin\Views\GpusByMachine\Details.cshtml" />
|
<_ContentIncludedByDefault Remove="Areas\Admin\Views\GpusByMachine\Details.cshtml" />
|
||||||
<_ContentIncludedByDefault Remove="Areas\Admin\Views\GpusByMachine\Edit.cshtml" />
|
<_ContentIncludedByDefault Remove="Areas\Admin\Views\GpusByMachine\Edit.cshtml" />
|
||||||
<_ContentIncludedByDefault Remove="Areas\Admin\Views\GpusByMachine\Index.cshtml" />
|
<_ContentIncludedByDefault Remove="Areas\Admin\Views\GpusByMachine\Index.cshtml" />
|
||||||
|
<_ContentIncludedByDefault Remove="Areas\Admin\Views\SoundByMachine\Create.cshtml" />
|
||||||
|
<_ContentIncludedByDefault Remove="Areas\Admin\Views\SoundByMachine\Delete.cshtml" />
|
||||||
|
<_ContentIncludedByDefault Remove="Areas\Admin\Views\SoundByMachine\Details.cshtml" />
|
||||||
|
<_ContentIncludedByDefault Remove="Areas\Admin\Views\SoundByMachine\Edit.cshtml" />
|
||||||
|
<_ContentIncludedByDefault Remove="Areas\Admin\Views\SoundByMachine\Index.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -41,6 +41,8 @@
|
|||||||
@inject NavigationManager NavigationManager
|
@inject NavigationManager NavigationManager
|
||||||
@inject GpuByMachineService GpuByMachineService
|
@inject GpuByMachineService GpuByMachineService
|
||||||
@inject GpusService GpusService
|
@inject GpusService GpusService
|
||||||
|
@inject SoundSynthsByMachineService SoundSynthsByMachineService
|
||||||
|
@inject SoundSynthsService SoundSynthsService
|
||||||
@attribute [Authorize(Roles = "UberAdmin, Admin")]
|
@attribute [Authorize(Roles = "UberAdmin, Admin")]
|
||||||
<h3>@L["Machine details"]</h3>
|
<h3>@L["Machine details"]</h3>
|
||||||
<hr />
|
<hr />
|
||||||
@@ -204,7 +206,61 @@
|
|||||||
@item.Name
|
@item.Name
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<Button Color="Color.Danger" Clicked="() => {ShowGpuDeleteModal(item.Id);}" Disabled="@_addingGpu">@L["Delete"]</Button>
|
<Button Color="Color.Danger" Clicked="() => {ShowSoundDeleteModal(item.Id);}" Disabled="@_addingGpu">@L["Delete"]</Button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
<hr />
|
||||||
|
<h3>@L["Sound synthesizers belonging to this machine"]</h3>
|
||||||
|
<Button Color="Color.Success" Clicked="OnAddSoundClick" Disabled="_addingSound">@L["Add new (sound by machine)"]</Button>
|
||||||
|
@if (_addingSound)
|
||||||
|
{
|
||||||
|
<div>
|
||||||
|
<Field>
|
||||||
|
<FieldLabel>@L["Sound synthesizers"]</FieldLabel>
|
||||||
|
<Select Disabled="_savingSound" TValue="int?" @bind-SelectedValue="@_addingSoundId">
|
||||||
|
@foreach (var soundSynth in _soundSynths)
|
||||||
|
{
|
||||||
|
<SelectItem TValue="int?" Value="@soundSynth.Id">@soundSynth.CompanyName - @soundSynth.Name</SelectItem>
|
||||||
|
}
|
||||||
|
</Select>
|
||||||
|
<Button Color="Color.Primary" Clicked="@CancelAddSound" Disabled="@_savingSound">@L["Cancel"]</Button>
|
||||||
|
<Button Color="Color.Success" Clicked="@ConfirmAddSound" Disabled="@_savingSound">@L["Add"]</Button>
|
||||||
|
</Field>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
@if (_machineSound?.Count > 0)
|
||||||
|
{
|
||||||
|
<div>
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
@L["Company"]
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
@L["Name"]
|
||||||
|
</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach (var item in _machineSound)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
@item.CompanyName
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@item.Name
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<Button Color="Color.Danger" Clicked="() => {ShowGpuDeleteModal(item.Id);}" Disabled="@_addingSound">@L["Delete"]</Button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,30 +12,34 @@ namespace Marechai.Pages.Admin.Details
|
|||||||
{
|
{
|
||||||
public partial class Machine
|
public partial class Machine
|
||||||
{
|
{
|
||||||
bool _addingGpu;
|
bool _addingGpu;
|
||||||
int? _addingGpuId;
|
int? _addingGpuId;
|
||||||
List<CompanyViewModel> _companies;
|
bool _addingSound;
|
||||||
bool _creating;
|
int? _addingSoundId;
|
||||||
GpuByMachineViewModel _currentGpuByMachine;
|
List<CompanyViewModel> _companies;
|
||||||
|
bool _creating;
|
||||||
bool _deleteInProgress;
|
GpuByMachineViewModel _currentGpuByMachine;
|
||||||
string _deleteText;
|
SoundSynthByMachineViewModel _currentSoundByMachine;
|
||||||
string _deleteTitle;
|
bool _deleteInProgress;
|
||||||
bool _deletingGpuByMachine;
|
string _deleteText;
|
||||||
bool _editing;
|
string _deleteTitle;
|
||||||
List<MachineFamilyViewModel> _families;
|
bool _deletingGpuByMachine;
|
||||||
Modal _frmDelete;
|
bool _deletingSoundByMachine;
|
||||||
|
bool _editing;
|
||||||
List<GpuViewModel> _gpus;
|
List<MachineFamilyViewModel> _families;
|
||||||
bool _loaded;
|
Modal _frmDelete;
|
||||||
List<GpuByMachineViewModel> _machineGpus;
|
List<GpuViewModel> _gpus;
|
||||||
MachineViewModel _model;
|
bool _loaded;
|
||||||
bool _noFamily;
|
List<GpuByMachineViewModel> _machineGpus;
|
||||||
bool _prototype;
|
List<SoundSynthByMachineViewModel> _machineSound;
|
||||||
|
MachineViewModel _model;
|
||||||
bool _savingGpu;
|
bool _noFamily;
|
||||||
bool _unknownIntroduced;
|
bool _prototype;
|
||||||
bool _unknownModel;
|
bool _savingGpu;
|
||||||
|
bool _savingSound;
|
||||||
|
List<SoundSynthViewModel> _soundSynths;
|
||||||
|
bool _unknownIntroduced;
|
||||||
|
bool _unknownModel;
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
@@ -64,6 +68,7 @@ namespace Marechai.Pages.Admin.Details
|
|||||||
_model = _creating ? new MachineViewModel() : await Service.GetAsync(Id);
|
_model = _creating ? new MachineViewModel() : await Service.GetAsync(Id);
|
||||||
_machineGpus = await GpuByMachineService.GetByMachine(Id);
|
_machineGpus = await GpuByMachineService.GetByMachine(Id);
|
||||||
_gpus = await GpusService.GetAsync();
|
_gpus = await GpusService.GetAsync();
|
||||||
|
_soundSynths = await SoundSynthsService.GetAsync();
|
||||||
|
|
||||||
_editing = _creating || NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
|
_editing = _creating || NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
|
||||||
StartsWith("admin/machines/edit/",
|
StartsWith("admin/machines/edit/",
|
||||||
@@ -164,6 +169,8 @@ namespace Marechai.Pages.Admin.Details
|
|||||||
{
|
{
|
||||||
if(_deletingGpuByMachine)
|
if(_deletingGpuByMachine)
|
||||||
await ConfirmDeleteGpuByMachine();
|
await ConfirmDeleteGpuByMachine();
|
||||||
|
else if(_deletingSoundByMachine)
|
||||||
|
await ConfirmDeleteSoundByMachine();
|
||||||
}
|
}
|
||||||
|
|
||||||
async Task ConfirmDeleteGpuByMachine()
|
async Task ConfirmDeleteGpuByMachine()
|
||||||
@@ -191,9 +198,10 @@ namespace Marechai.Pages.Admin.Details
|
|||||||
|
|
||||||
void ModalClosing(ModalClosingEventArgs obj)
|
void ModalClosing(ModalClosingEventArgs obj)
|
||||||
{
|
{
|
||||||
_deleteInProgress = false;
|
_deleteInProgress = false;
|
||||||
_deletingGpuByMachine = false;
|
_deletingGpuByMachine = false;
|
||||||
_currentGpuByMachine = null;
|
_currentGpuByMachine = null;
|
||||||
|
_deletingSoundByMachine = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async Task OnAddGpuClick()
|
async Task OnAddGpuClick()
|
||||||
@@ -237,5 +245,83 @@ namespace Marechai.Pages.Admin.Details
|
|||||||
// Tell we finished loading
|
// Tell we finished loading
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ShowSoundDeleteModal(long itemId)
|
||||||
|
{
|
||||||
|
_currentSoundByMachine = _machineSound.FirstOrDefault(n => n.Id == itemId);
|
||||||
|
_deletingSoundByMachine = true;
|
||||||
|
_deleteTitle = L["Delete sound synthesizer from this machine"];
|
||||||
|
|
||||||
|
_deleteText =
|
||||||
|
string.Format(L["Are you sure you want to delete the sound synthesizer {0} manufactured by {1} from this machine?"],
|
||||||
|
_currentSoundByMachine?.Name, _currentSoundByMachine?.CompanyName);
|
||||||
|
|
||||||
|
_frmDelete.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task ConfirmDeleteSoundByMachine()
|
||||||
|
{
|
||||||
|
if(_currentSoundByMachine is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_deleteInProgress = true;
|
||||||
|
|
||||||
|
// Yield thread to let UI to update
|
||||||
|
await Task.Yield();
|
||||||
|
|
||||||
|
await SoundSynthsByMachineService.DeleteAsync(_currentSoundByMachine.Id);
|
||||||
|
_machineSound = await SoundSynthsByMachineService.GetByMachine(Id);
|
||||||
|
|
||||||
|
_deleteInProgress = false;
|
||||||
|
_frmDelete.Hide();
|
||||||
|
|
||||||
|
// Yield thread to let UI to update
|
||||||
|
await Task.Yield();
|
||||||
|
|
||||||
|
// Tell we finished loading
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task OnAddSoundClick()
|
||||||
|
{
|
||||||
|
_addingSound = true;
|
||||||
|
_savingSound = false;
|
||||||
|
_addingSoundId = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CancelAddSound()
|
||||||
|
{
|
||||||
|
_addingSound = false;
|
||||||
|
_savingSound = false;
|
||||||
|
_addingSoundId = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task ConfirmAddSound()
|
||||||
|
{
|
||||||
|
if(_addingSoundId is null)
|
||||||
|
{
|
||||||
|
CancelAddSound();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_savingSound = true;
|
||||||
|
|
||||||
|
// Yield thread to let UI to update
|
||||||
|
await Task.Yield();
|
||||||
|
|
||||||
|
await SoundSynthsByMachineService.CreateAsync(_addingSoundId.Value, Id);
|
||||||
|
_machineSound = await SoundSynthsByMachineService.GetByMachine(Id);
|
||||||
|
|
||||||
|
_addingSound = false;
|
||||||
|
_savingSound = false;
|
||||||
|
_addingSoundId = null;
|
||||||
|
|
||||||
|
// Yield thread to let UI to update
|
||||||
|
await Task.Yield();
|
||||||
|
|
||||||
|
// Tell we finished loading
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,6 +63,7 @@ namespace Marechai.Services
|
|||||||
services.AddScoped<ResolutionsService>();
|
services.AddScoped<ResolutionsService>();
|
||||||
services.AddScoped<CompanyLogosService>();
|
services.AddScoped<CompanyLogosService>();
|
||||||
services.AddScoped<GpuByMachineService>();
|
services.AddScoped<GpuByMachineService>();
|
||||||
|
services.AddScoped<SoundSynthsByMachineService>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
49
Marechai/Services/SoundSynthsByMachineService.cs
Normal file
49
Marechai/Services/SoundSynthsByMachineService.cs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Marechai.Database.Models;
|
||||||
|
using Marechai.ViewModels;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Marechai.Services
|
||||||
|
{
|
||||||
|
public class SoundSynthsByMachineService
|
||||||
|
{
|
||||||
|
readonly MarechaiContext _context;
|
||||||
|
|
||||||
|
public SoundSynthsByMachineService(MarechaiContext context) => _context = context;
|
||||||
|
|
||||||
|
public async Task<List<SoundSynthByMachineViewModel>> GetByMachine(int machineId) =>
|
||||||
|
await _context.SoundByMachine.Where(g => g.MachineId == machineId).
|
||||||
|
Select(g => new SoundSynthByMachineViewModel
|
||||||
|
{
|
||||||
|
Id = g.Id, Name = g.SoundSynth.Name, CompanyName = g.SoundSynth.Company.Name,
|
||||||
|
SoundSynthId = g.SoundSynthId, MachineId = g.MachineId
|
||||||
|
}).OrderBy(g => g.CompanyName).ThenBy(g => g.Name).ToListAsync();
|
||||||
|
|
||||||
|
public async Task DeleteAsync(long id)
|
||||||
|
{
|
||||||
|
SoundByMachine item = await _context.SoundByMachine.FindAsync(id);
|
||||||
|
|
||||||
|
if(item is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_context.SoundByMachine.Remove(item);
|
||||||
|
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<long> CreateAsync(int soundSynthId, int machineId)
|
||||||
|
{
|
||||||
|
var item = new SoundByMachine
|
||||||
|
{
|
||||||
|
SoundSynthId = soundSynthId, MachineId = machineId
|
||||||
|
};
|
||||||
|
|
||||||
|
await _context.SoundByMachine.AddAsync(item);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
return item.Id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
10
Marechai/ViewModels/SoundSynthByMachineViewModel.cs
Normal file
10
Marechai/ViewModels/SoundSynthByMachineViewModel.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace Marechai.ViewModels
|
||||||
|
{
|
||||||
|
public class SoundSynthByMachineViewModel : BaseViewModel<long>
|
||||||
|
{
|
||||||
|
public int SoundSynthId { get; set; }
|
||||||
|
public int MachineId { get; set; }
|
||||||
|
public string CompanyName { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user