mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Implement sound by owned machine admin pages.
This commit is contained in:
@@ -0,0 +1,194 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Cicm.Database.Models;
|
||||||
|
using cicm_web.Areas.Admin.Models;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Query;
|
||||||
|
|
||||||
|
namespace cicm_web.Areas.Admin.Controllers
|
||||||
|
{
|
||||||
|
[Area("Admin")]
|
||||||
|
[Authorize]
|
||||||
|
public class SoundByOwnedMachineController : Controller
|
||||||
|
{
|
||||||
|
readonly cicmContext _context;
|
||||||
|
|
||||||
|
public SoundByOwnedMachineController(cicmContext context)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: SoundByOwnedMachine
|
||||||
|
public async Task<IActionResult> Index()
|
||||||
|
{
|
||||||
|
IIncludableQueryable<SoundByOwnedMachine, SoundSynth> cicmContext =
|
||||||
|
_context.SoundByOwnedMachine.Include(s => s.OwnedMachine).Include(s => s.SoundSynth);
|
||||||
|
return View(await cicmContext.OrderBy(s => s.OwnedMachine.Machine.Company.Name)
|
||||||
|
.ThenBy(s => s.OwnedMachine.Machine.Name)
|
||||||
|
.ThenBy(s => s.OwnedMachine.User.UserName).ThenBy(s => s.SoundSynth.Name)
|
||||||
|
.Select(s => new SoundByMachineViewModel
|
||||||
|
{
|
||||||
|
Id = s.Id,
|
||||||
|
Machine =
|
||||||
|
$"{s.OwnedMachine.Machine.Company.Name} {s.OwnedMachine.Machine.Name} <{s.OwnedMachine.User.UserName}>",
|
||||||
|
SoundSynth = s.SoundSynth.Name
|
||||||
|
}).ToListAsync());
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: SoundByOwnedMachine/Details/5
|
||||||
|
public async Task<IActionResult> Details(long? id)
|
||||||
|
{
|
||||||
|
if(id == null) return NotFound();
|
||||||
|
|
||||||
|
SoundByMachineViewModel soundByOwnedMachine = await _context.SoundByOwnedMachine
|
||||||
|
.OrderBy(s => s.OwnedMachine.Machine.Company
|
||||||
|
.Name)
|
||||||
|
.ThenBy(s => s.OwnedMachine.Machine.Name)
|
||||||
|
.ThenBy(s => s.OwnedMachine.User.UserName)
|
||||||
|
.ThenBy(s => s.SoundSynth.Name)
|
||||||
|
.Select(s => new SoundByMachineViewModel
|
||||||
|
{
|
||||||
|
Id = s.Id,
|
||||||
|
Machine =
|
||||||
|
$"{s.OwnedMachine.Machine.Company.Name} {s.OwnedMachine.Machine.Name} <{s.OwnedMachine.User.UserName}>",
|
||||||
|
SoundSynth = s.SoundSynth.Name
|
||||||
|
}).FirstOrDefaultAsync(m => m.Id ==
|
||||||
|
id);
|
||||||
|
if(soundByOwnedMachine == null) return NotFound();
|
||||||
|
|
||||||
|
return View(soundByOwnedMachine);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: SoundByOwnedMachine/Create
|
||||||
|
public IActionResult Create()
|
||||||
|
{
|
||||||
|
ViewData["OwnedMachineId"] =
|
||||||
|
new
|
||||||
|
SelectList(_context.OwnedMachines.OrderBy(m => m.Machine.Company.Name).ThenBy(m => m.Machine.Name).ThenBy(m => m.User.UserName).Select(m => new {m.Id, Name = $"{m.Machine.Company.Name} {m.Machine.Name} <{m.User.UserName}>"}),
|
||||||
|
"Id", "Name");
|
||||||
|
ViewData["SoundSynthId"] = new SelectList(_context.SoundSynths, "Id", "Name");
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: SoundByOwnedMachine/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,OwnedMachineId,Id")]
|
||||||
|
SoundByOwnedMachine soundByOwnedMachine)
|
||||||
|
{
|
||||||
|
if(ModelState.IsValid)
|
||||||
|
{
|
||||||
|
_context.Add(soundByOwnedMachine);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
return RedirectToAction(nameof(Index));
|
||||||
|
}
|
||||||
|
|
||||||
|
ViewData["OwnedMachineId"] =
|
||||||
|
new
|
||||||
|
SelectList(_context.OwnedMachines.OrderBy(m => m.Machine.Company.Name).ThenBy(m => m.Machine.Name).ThenBy(m => m.User.UserName).Select(m => new {m.Id, Name = $"{m.Machine.Company.Name} {m.Machine.Name} <{m.User.UserName}>"}),
|
||||||
|
"Id", "Name", soundByOwnedMachine.OwnedMachineId);
|
||||||
|
ViewData["SoundSynthId"] =
|
||||||
|
new SelectList(_context.SoundSynths, "Id", "Name", soundByOwnedMachine.SoundSynthId);
|
||||||
|
return View(soundByOwnedMachine);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: SoundByOwnedMachine/Edit/5
|
||||||
|
public async Task<IActionResult> Edit(long? id)
|
||||||
|
{
|
||||||
|
if(id == null) return NotFound();
|
||||||
|
|
||||||
|
SoundByOwnedMachine soundByOwnedMachine = await _context.SoundByOwnedMachine.FindAsync(id);
|
||||||
|
if(soundByOwnedMachine == null) return NotFound();
|
||||||
|
|
||||||
|
ViewData["OwnedMachineId"] =
|
||||||
|
new
|
||||||
|
SelectList(_context.OwnedMachines.OrderBy(m => m.Machine.Company.Name).ThenBy(m => m.Machine.Name).ThenBy(m => m.User.UserName).Select(m => new {m.Id, Name = $"{m.Machine.Company.Name} {m.Machine.Name} <{m.User.UserName}>"}),
|
||||||
|
"Id", "Name", soundByOwnedMachine.OwnedMachineId);
|
||||||
|
ViewData["SoundSynthId"] =
|
||||||
|
new SelectList(_context.SoundSynths, "Id", "Name", soundByOwnedMachine.SoundSynthId);
|
||||||
|
return View(soundByOwnedMachine);
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: SoundByOwnedMachine/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,OwnedMachineId,Id")]
|
||||||
|
SoundByOwnedMachine soundByOwnedMachine)
|
||||||
|
{
|
||||||
|
if(id != soundByOwnedMachine.Id) return NotFound();
|
||||||
|
|
||||||
|
if(ModelState.IsValid)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_context.Update(soundByOwnedMachine);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
catch(DbUpdateConcurrencyException)
|
||||||
|
{
|
||||||
|
if(!SoundByOwnedMachineExists(soundByOwnedMachine.Id)) return NotFound();
|
||||||
|
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
return RedirectToAction(nameof(Index));
|
||||||
|
}
|
||||||
|
|
||||||
|
ViewData["OwnedMachineId"] =
|
||||||
|
new
|
||||||
|
SelectList(_context.OwnedMachines.OrderBy(m => m.Machine.Company.Name).ThenBy(m => m.Machine.Name).ThenBy(m => m.User.UserName).Select(m => new {m.Id, Name = $"{m.Machine.Company.Name} {m.Machine.Name} <{m.User.UserName}>"}),
|
||||||
|
"Id", "Name", soundByOwnedMachine.OwnedMachineId);
|
||||||
|
ViewData["SoundSynthId"] =
|
||||||
|
new SelectList(_context.SoundSynths, "Id", "Name", soundByOwnedMachine.SoundSynthId);
|
||||||
|
return View(soundByOwnedMachine);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: SoundByOwnedMachine/Delete/5
|
||||||
|
public async Task<IActionResult> Delete(long? id)
|
||||||
|
{
|
||||||
|
if(id == null) return NotFound();
|
||||||
|
|
||||||
|
SoundByMachineViewModel soundByOwnedMachine = await _context.SoundByOwnedMachine
|
||||||
|
.OrderBy(s => s.OwnedMachine.Machine.Company
|
||||||
|
.Name)
|
||||||
|
.ThenBy(s => s.OwnedMachine.Machine.Name)
|
||||||
|
.ThenBy(s => s.OwnedMachine.User.UserName)
|
||||||
|
.ThenBy(s => s.SoundSynth.Name)
|
||||||
|
.Select(s => new SoundByMachineViewModel
|
||||||
|
{
|
||||||
|
Id = s.Id,
|
||||||
|
Machine =
|
||||||
|
$"{s.OwnedMachine.Machine.Company.Name} {s.OwnedMachine.Machine.Name} <{s.OwnedMachine.User.UserName}>",
|
||||||
|
SoundSynth = s.SoundSynth.Name
|
||||||
|
}).FirstOrDefaultAsync(m => m.Id ==
|
||||||
|
id);
|
||||||
|
if(soundByOwnedMachine == null) return NotFound();
|
||||||
|
|
||||||
|
return View(soundByOwnedMachine);
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: SoundByOwnedMachine/Delete/5
|
||||||
|
[HttpPost]
|
||||||
|
[ActionName("Delete")]
|
||||||
|
[ValidateAntiForgeryToken]
|
||||||
|
public async Task<IActionResult> DeleteConfirmed(long id)
|
||||||
|
{
|
||||||
|
SoundByOwnedMachine soundByOwnedMachine = await _context.SoundByOwnedMachine.FindAsync(id);
|
||||||
|
_context.SoundByOwnedMachine.Remove(soundByOwnedMachine);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
return RedirectToAction(nameof(Index));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SoundByOwnedMachineExists(long id)
|
||||||
|
{
|
||||||
|
return _context.SoundByOwnedMachine.Any(e => e.Id == id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
46
cicm_web/Areas/Admin/Views/SoundByOwnedMachine/Create.cshtml
Normal file
46
cicm_web/Areas/Admin/Views/SoundByOwnedMachine/Create.cshtml
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
@model Cicm.Database.Models.SoundByOwnedMachine
|
||||||
|
|
||||||
|
@{
|
||||||
|
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="OwnedMachine"
|
||||||
|
class="control-label">
|
||||||
|
</label>
|
||||||
|
<select asp-for="OwnedMachineId"
|
||||||
|
class="form-control"
|
||||||
|
asp-items="ViewBag.OwnedMachineId">
|
||||||
|
</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>
|
||||||
39
cicm_web/Areas/Admin/Views/SoundByOwnedMachine/Delete.cshtml
Normal file
39
cicm_web/Areas/Admin/Views/SoundByOwnedMachine/Delete.cshtml
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
@model cicm_web.Areas.Admin.Models.SoundByMachineViewModel
|
||||||
|
|
||||||
|
@{
|
||||||
|
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)
|
||||||
|
</dd>
|
||||||
|
<dt class="col-sm-2">
|
||||||
|
@Html.DisplayNameFor(model => model.SoundSynth)
|
||||||
|
</dt>
|
||||||
|
<dd class="col-sm-10">
|
||||||
|
@Html.DisplayFor(model => model.SoundSynth)
|
||||||
|
</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>
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
@model cicm_web.Areas.Admin.Models.SoundByMachineViewModel
|
||||||
|
|
||||||
|
@{
|
||||||
|
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)
|
||||||
|
</dd>
|
||||||
|
<dt class="col-sm-2">
|
||||||
|
@Html.DisplayNameFor(model => model.SoundSynth)
|
||||||
|
</dt>
|
||||||
|
<dd class="col-sm-10">
|
||||||
|
@Html.DisplayFor(model => model.SoundSynth)
|
||||||
|
</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>
|
||||||
54
cicm_web/Areas/Admin/Views/SoundByOwnedMachine/Edit.cshtml
Normal file
54
cicm_web/Areas/Admin/Views/SoundByOwnedMachine/Edit.cshtml
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
@model Cicm.Database.Models.SoundByOwnedMachine
|
||||||
|
|
||||||
|
@{
|
||||||
|
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="OwnedMachine"
|
||||||
|
class="control-label">
|
||||||
|
</label>
|
||||||
|
<select asp-for="OwnedMachineId"
|
||||||
|
class="form-control"
|
||||||
|
asp-items="ViewBag.OwnedMachineId">
|
||||||
|
</select>
|
||||||
|
<span asp-validation-for="OwnedMachineId"
|
||||||
|
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>
|
||||||
58
cicm_web/Areas/Admin/Views/SoundByOwnedMachine/Index.cshtml
Normal file
58
cicm_web/Areas/Admin/Views/SoundByOwnedMachine/Index.cshtml
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
@using cicm_web.Areas.Admin.Models
|
||||||
|
@model IEnumerable<cicm_web.Areas.Admin.Models.SoundByMachineViewModel>
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Index";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h1>Sound synthetizers 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(SoundByMachineViewModel 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>netcoreapp2.2</TargetFramework>
|
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||||
<Version>3.0.99.686</Version>
|
<Version>3.0.99.687</Version>
|
||||||
<Company>Canary Islands Computer Museum</Company>
|
<Company>Canary Islands Computer Museum</Company>
|
||||||
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
|
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
|
||||||
<Product>Canary Islands Computer Museum Website</Product>
|
<Product>Canary Islands Computer Museum Website</Product>
|
||||||
|
|||||||
Reference in New Issue
Block a user