diff --git a/cicm_web/Areas/Admin/Controllers/SoundByOwnedMachineController.cs b/cicm_web/Areas/Admin/Controllers/SoundByOwnedMachineController.cs new file mode 100644 index 00000000..0968ff7a --- /dev/null +++ b/cicm_web/Areas/Admin/Controllers/SoundByOwnedMachineController.cs @@ -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 Index() + { + IIncludableQueryable 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 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 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 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 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 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 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); + } + } +} \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/SoundByOwnedMachine/Create.cshtml b/cicm_web/Areas/Admin/Views/SoundByOwnedMachine/Create.cshtml new file mode 100644 index 00000000..00336061 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/SoundByOwnedMachine/Create.cshtml @@ -0,0 +1,46 @@ +@model Cicm.Database.Models.SoundByOwnedMachine + +@{ + ViewData["Title"] = "Create"; +} + +

Create

+ +

Sound by machine

+
+
+
+
+
+
+
+ + +
+
+ + +
+ +
+
+
\ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/SoundByOwnedMachine/Delete.cshtml b/cicm_web/Areas/Admin/Views/SoundByOwnedMachine/Delete.cshtml new file mode 100644 index 00000000..41fa0c34 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/SoundByOwnedMachine/Delete.cshtml @@ -0,0 +1,39 @@ +@model cicm_web.Areas.Admin.Models.SoundByMachineViewModel + +@{ + ViewData["Title"] = "Delete"; +} + +

Delete

+ +

Are you sure you want to delete this?

+
+

Sound by machine

+
+
+
+ @Html.DisplayNameFor(model => model.Machine) +
+
+ @Html.DisplayFor(model => model.Machine) +
+
+ @Html.DisplayNameFor(model => model.SoundSynth) +
+
+ @Html.DisplayFor(model => model.SoundSynth) +
+
+ +
+ + + + Back to List + +
+
\ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/SoundByOwnedMachine/Details.cshtml b/cicm_web/Areas/Admin/Views/SoundByOwnedMachine/Details.cshtml new file mode 100644 index 00000000..7a936f04 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/SoundByOwnedMachine/Details.cshtml @@ -0,0 +1,37 @@ +@model cicm_web.Areas.Admin.Models.SoundByMachineViewModel + +@{ + ViewData["Title"] = "Details"; +} + +

Details

+ +
+

Sound by machine

+
+
+
+ @Html.DisplayNameFor(model => model.Machine) +
+
+ @Html.DisplayFor(model => model.Machine) +
+
+ @Html.DisplayNameFor(model => model.SoundSynth) +
+
+ @Html.DisplayFor(model => model.SoundSynth) +
+
+
+ \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/SoundByOwnedMachine/Edit.cshtml b/cicm_web/Areas/Admin/Views/SoundByOwnedMachine/Edit.cshtml new file mode 100644 index 00000000..b5537f65 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/SoundByOwnedMachine/Edit.cshtml @@ -0,0 +1,54 @@ +@model Cicm.Database.Models.SoundByOwnedMachine + +@{ + ViewData["Title"] = "Edit"; +} + +

Edit

+ +

Sound by machine

+
+
+
+
+
+
+
+ + + + +
+
+ + + + +
+ + +
+
+
\ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/SoundByOwnedMachine/Index.cshtml b/cicm_web/Areas/Admin/Views/SoundByOwnedMachine/Index.cshtml new file mode 100644 index 00000000..67785590 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/SoundByOwnedMachine/Index.cshtml @@ -0,0 +1,58 @@ +@using cicm_web.Areas.Admin.Models +@model IEnumerable + +@{ + ViewData["Title"] = "Index"; +} + +

Sound synthetizers by machine

+ +

+ + Create New + +

+ + + + + + + + + + @foreach(SoundByMachineViewModel item in Model) + { + + + + + + } + +
+ @Html.DisplayNameFor(model => model.Machine) + + @Html.DisplayNameFor(model => model.SoundSynth) +
+ @Html.DisplayFor(modelItem => item.Machine) + + @Html.DisplayFor(modelItem => item.SoundSynth) + + + Details + + + Edit + + + Delete + +
\ No newline at end of file diff --git a/cicm_web/cicm_web.csproj b/cicm_web/cicm_web.csproj index b1c232d7..07114a9c 100644 --- a/cicm_web/cicm_web.csproj +++ b/cicm_web/cicm_web.csproj @@ -2,7 +2,7 @@ netcoreapp2.2 - 3.0.99.686 + 3.0.99.687 Canary Islands Computer Museum Copyright © 2003-2018 Natalia Portillo Canary Islands Computer Museum Website