Show products in USB vendor details.

This commit is contained in:
2019-11-17 22:47:41 +00:00
parent 85c34c640a
commit 9a06a00600
3 changed files with 71 additions and 5 deletions

View File

@@ -15,7 +15,8 @@ namespace DiscImageChef.Server.Areas.Admin.Controllers
public UsbVendorsController(DicServerContext context) => _context = context;
// GET: Admin/UsbVendors
public async Task<IActionResult> Index() => View(await _context.UsbVendors.OrderBy(v => v.Vendor).ThenBy(v => v.VendorId).ToListAsync());
public async Task<IActionResult> Index() =>
View(await _context.UsbVendors.OrderBy(v => v.Vendor).ThenBy(v => v.VendorId).ToListAsync());
// GET: Admin/UsbVendors/Details/5
public async Task<IActionResult> Details(int? id)
@@ -32,7 +33,20 @@ namespace DiscImageChef.Server.Areas.Admin.Controllers
return NotFound();
}
return View(usbVendor);
return View(new UsbVendorModel
{
Vendor = usbVendor.Vendor, VendorId = usbVendor.VendorId, Products = _context.
UsbProducts.
Where(p => p.VendorId ==
usbVendor.Id).
OrderBy(p => p.Product).
ThenBy(p => p.ProductId).
Select(p => new UsbProductModel
{
ProductId = p.ProductId,
ProductName = p.Product
}).ToList()
});
}
}
}

View File

@@ -1,4 +1,4 @@
@model UsbVendor
@model UsbVendorModel
@{
Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
@@ -34,7 +34,7 @@
// ****************************************************************************/
}
<div>
<h4>UsbVendor</h4>
<h4>USB vendor</h4>
<hr />
<dl class="row">
<dt class="col-sm-2">
@@ -51,6 +51,43 @@
</dd>
</dl>
</div>
<div>
<h4>Products:</h4>
<table class="table" id="tblProducts">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Products[0].ProductName)
</th>
<th>
@Html.DisplayNameFor(model => model.Products[0].ProductId)
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.Products)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.ProductName)
</td>
<td>
@Html.DisplayFor(modelItem => item.ProductId)
</td>
</tr>
}
</tbody>
</table>
</div>
<div>
<a asp-action="Index" class="btn btn-secondary">Back to List</a>
</div>
</div>
@section scripts{
<script crossorigin="anonymous" integrity="sha256-L4cf7m/cgC51e7BFPxQcKZcXryzSju7VYBKJLOKPHvQ=" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
<script language="javascript">
$(document).ready(function() {
$('#tblProducts').DataTable();
} );
</script>
}

View File

@@ -0,0 +1,15 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace DiscImageChef.Server.Models
{
public class UsbVendorModel
{
[DisplayName("Manufacturer")]
public string Vendor { get; set; }
[DisplayName("Vendor ID"), DisplayFormat(DataFormatString = "0x{0:X4}")]
public ushort VendorId { get; set; }
public List<UsbProductModel> Products { get; set; }
}
}