Implement edit owned machine admin page.

This commit is contained in:
2019-05-30 00:47:01 +01:00
parent 576643f72e
commit 9447da14c3
3 changed files with 107 additions and 38 deletions

View File

@@ -117,7 +117,14 @@ namespace cicm_web.Areas.Admin.Controllers
OwnedMachine ownedMachine = await _context.OwnedMachines.FindAsync(id);
if(ownedMachine == null) return NotFound();
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", ownedMachine.MachineId);
ViewData["MachineId"] =
new
SelectList(_context.Machines.OrderBy(m => m.Company.Name).ThenBy(m => m.Name).Select(m => new {m.Id, Name = $"{m.Company.Name} {m.Name}"}),
"Id", "Name");
ViewData["UserId"] =
new
SelectList(_context.Users.OrderBy(u => u.UserName).Where(u => u.Id == ownedMachine.UserId).Select(u => new {u.Id, u.UserName}),
"Id", "UserName");
return View(ownedMachine);
}
@@ -150,7 +157,14 @@ namespace cicm_web.Areas.Admin.Controllers
return RedirectToAction(nameof(Index));
}
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", ownedMachine.MachineId);
ViewData["MachineId"] =
new
SelectList(_context.Machines.OrderBy(m => m.Company.Name).ThenBy(m => m.Name).Select(m => new {m.Id, Name = $"{m.Company.Name} {m.Name}"}),
"Id", "Name");
ViewData["UserId"] =
new
SelectList(_context.Users.OrderBy(u => u.UserName).Where(u => u.Id == ownedMachine.UserId).Select(u => new {u.Id, u.UserName}),
"Id", "UserName");
return View(ownedMachine);
}

View File

@@ -1,3 +1,4 @@
@using Cicm.Database
@model Cicm.Database.Models.OwnedMachine
@{
@@ -6,71 +7,125 @@
<h1>Edit</h1>
<h4>OwnedMachine</h4>
<h4>Owned 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="AcquisitionDate" class="control-label"></label>
<input asp-for="AcquisitionDate" class="form-control" />
<span asp-validation-for="AcquisitionDate" class="text-danger"></span>
<div asp-validation-summary="ModelOnly"
class="text-danger">
</div>
<div class="form-group">
<label asp-for="LostDate" class="control-label"></label>
<input asp-for="LostDate" class="form-control" />
<span asp-validation-for="LostDate" class="text-danger"></span>
<label asp-for="AcquisitionDate"
class="control-label">
</label>
<input asp-for="AcquisitionDate"
class="form-control" />
<span asp-validation-for="AcquisitionDate"
class="text-danger">
</span>
</div>
<div class="form-group">
<label asp-for="Status" class="control-label"></label>
<select asp-for="Status" class="form-control"></select>
<span asp-validation-for="Status" class="text-danger"></span>
<label asp-for="LostDate"
class="control-label">
</label>
<input asp-for="LostDate"
class="form-control" />
<span asp-validation-for="LostDate"
class="text-danger">
</span>
</div>
<div class="form-group">
<label asp-for="LastStatusDate" class="control-label"></label>
<input asp-for="LastStatusDate" class="form-control" />
<span asp-validation-for="LastStatusDate" class="text-danger"></span>
<label asp-for="Status"
class="control-label">
</label>
<select asp-for="Status"
class="form-control"
asp-items="Html.GetEnumSelectList<StatusType>().OrderBy(s => s.Text)">
</select>
<span asp-validation-for="Status"
class="text-danger">
</span>
</div>
<div class="form-group form-check">
<div class="form-group">
<label asp-for="LastStatusDate"
class="control-label">
</label>
<input asp-for="LastStatusDate"
class="form-control" />
<span asp-validation-for="LastStatusDate"
class="text-danger">
</span>
</div>
<div class="form-check form-group">
<label class="form-check-label">
<input class="form-check-input" asp-for="Trade" /> @Html.DisplayNameFor(model => model.Trade)
<input class="form-check-input"
asp-for="Trade" /> @Html.DisplayNameFor(model => model.Trade)
</label>
</div>
<div class="form-group form-check">
<div class="form-check form-group">
<label class="form-check-label">
<input class="form-check-input" asp-for="Boxed" /> @Html.DisplayNameFor(model => model.Boxed)
<input class="form-check-input"
asp-for="Boxed" /> @Html.DisplayNameFor(model => model.Boxed)
</label>
</div>
<div class="form-group form-check">
<div class="form-check form-group">
<label class="form-check-label">
<input class="form-check-input" asp-for="Manuals" /> @Html.DisplayNameFor(model => model.Manuals)
<input class="form-check-input"
asp-for="Manuals" /> @Html.DisplayNameFor(model => model.Manuals)
</label>
</div>
<div class="form-group">
<label asp-for="SerialNumber" class="control-label"></label>
<input asp-for="SerialNumber" class="form-control" />
<span asp-validation-for="SerialNumber" class="text-danger"></span>
<label asp-for="SerialNumber"
class="control-label">
</label>
<input asp-for="SerialNumber"
class="form-control" />
<span asp-validation-for="SerialNumber"
class="text-danger">
</span>
</div>
<div class="form-group form-check">
<div class="form-check form-group">
<label class="form-check-label">
<input class="form-check-input" asp-for="SerialNumberVisible" /> @Html.DisplayNameFor(model => model.SerialNumberVisible)
<input class="form-check-input"
asp-for="SerialNumberVisible"
checked /> @Html.DisplayNameFor(model => model.SerialNumberVisible)
</label>
</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>
<span asp-validation-for="MachineId" class="text-danger"></span>
<label asp-for="Machine"
class="control-label">
</label>
<select asp-for="MachineId"
class="form-control"
asp-items="ViewBag.MachineId">
</select>
</div>
<input type="hidden" asp-for="Id" />
<div class="form-group">
<input type="submit" value="Save" class="btn btn-primary" />
<label asp-for="User"
class="control-label">
</label>
<select asp-for="UserId"
class="form-control"
asp-items="ViewBag.UserId"
readonly>
</select>
</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>
<div>
<a asp-action="Index">Back to List</a>
</div>
@section Scripts {
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
}

View File

@@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<Version>3.0.99.684</Version>
<Version>3.0.99.685</Version>
<Company>Canary Islands Computer Museum</Company>
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
<Product>Canary Islands Computer Museum Website</Product>