mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Implement create owned machine admin page.
This commit is contained in:
@@ -1,20 +1,30 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
namespace Cicm.Database.Models
|
namespace Cicm.Database.Models
|
||||||
{
|
{
|
||||||
public class OwnedMachine : BaseModel<long>
|
public class OwnedMachine : BaseModel<long>
|
||||||
{
|
{
|
||||||
|
[DisplayName("Acquisition date")]
|
||||||
public DateTime AcquisitionDate { get; set; }
|
public DateTime AcquisitionDate { get; set; }
|
||||||
|
[DisplayName("Date when sold, traded, or otherwise lost")]
|
||||||
public DateTime? LostDate { get; set; }
|
public DateTime? LostDate { get; set; }
|
||||||
public StatusType Status { get; set; }
|
public StatusType Status { get; set; }
|
||||||
|
[DisplayName("Last status check date")]
|
||||||
public DateTime? LastStatusDate { get; set; }
|
public DateTime? LastStatusDate { get; set; }
|
||||||
|
[DisplayName("Available for trade or sale")]
|
||||||
public bool Trade { get; set; }
|
public bool Trade { get; set; }
|
||||||
|
[DisplayName("Has original boxes")]
|
||||||
public bool Boxed { get; set; }
|
public bool Boxed { get; set; }
|
||||||
|
[DisplayName("Has original manuals")]
|
||||||
public bool Manuals { get; set; }
|
public bool Manuals { get; set; }
|
||||||
|
[DisplayName("Serial number")]
|
||||||
public string SerialNumber { get; set; }
|
public string SerialNumber { get; set; }
|
||||||
|
[DisplayName("Serial number visible to other users")]
|
||||||
public bool SerialNumberVisible { get; set; }
|
public bool SerialNumberVisible { get; set; }
|
||||||
public int MachineId { get; set; }
|
public int MachineId { get; set; }
|
||||||
|
public string UserId { get; set; }
|
||||||
|
|
||||||
public virtual ICollection<GpusByOwnedMachine> Gpus { get; set; }
|
public virtual ICollection<GpusByOwnedMachine> Gpus { get; set; }
|
||||||
public virtual ICollection<MemoryByOwnedMachine> Memory { get; set; }
|
public virtual ICollection<MemoryByOwnedMachine> Memory { get; set; }
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace cicm_web.Areas.Admin.Controllers
|
|||||||
[Authorize]
|
[Authorize]
|
||||||
public class OwnedMachineController : Controller
|
public class OwnedMachineController : Controller
|
||||||
{
|
{
|
||||||
private readonly cicmContext _context;
|
readonly cicmContext _context;
|
||||||
|
|
||||||
public OwnedMachineController(cicmContext context)
|
public OwnedMachineController(cicmContext context)
|
||||||
{
|
{
|
||||||
@@ -23,11 +23,17 @@ namespace cicm_web.Areas.Admin.Controllers
|
|||||||
// GET: OwnedMachine
|
// GET: OwnedMachine
|
||||||
public async Task<IActionResult> Index()
|
public async Task<IActionResult> Index()
|
||||||
{
|
{
|
||||||
var cicmContext = _context.OwnedMachines.Include(o => o.Machine).OrderBy(o => o.Machine.Company.Name).ThenBy(o => o.Machine.Name).ThenBy(o => o.User.UserName).ThenBy(o => o.AcquisitionDate).Select(o => new OwnedMachineViewModel
|
IQueryable<OwnedMachineViewModel> cicmContext = _context
|
||||||
|
.OwnedMachines.Include(o => o.Machine)
|
||||||
|
.OrderBy(o => o.Machine.Company.Name)
|
||||||
|
.ThenBy(o => o.Machine.Name).ThenBy(o => o.User.UserName)
|
||||||
|
.ThenBy(o => o.AcquisitionDate)
|
||||||
|
.Select(o => new OwnedMachineViewModel
|
||||||
{
|
{
|
||||||
AcquisitionDate = o.AcquisitionDate,
|
AcquisitionDate = o.AcquisitionDate,
|
||||||
Id = o.Id,
|
Id = o.Id,
|
||||||
Machine = $"{o.Machine.Company.Name} {o.Machine.Name}",
|
Machine =
|
||||||
|
$"{o.Machine.Company.Name} {o.Machine.Name}",
|
||||||
Status = o.Status,
|
Status = o.Status,
|
||||||
User = o.User.UserName
|
User = o.User.UserName
|
||||||
});
|
});
|
||||||
@@ -38,18 +44,11 @@ namespace cicm_web.Areas.Admin.Controllers
|
|||||||
// GET: OwnedMachine/Details/5
|
// GET: OwnedMachine/Details/5
|
||||||
public async Task<IActionResult> Details(long? id)
|
public async Task<IActionResult> Details(long? id)
|
||||||
{
|
{
|
||||||
if (id == null)
|
if(id == null) return NotFound();
|
||||||
{
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
var ownedMachine = await _context.OwnedMachines
|
OwnedMachine ownedMachine = await _context.OwnedMachines
|
||||||
.Include(o => o.Machine)
|
.Include(o => o.Machine).FirstOrDefaultAsync(m => m.Id == id);
|
||||||
.FirstOrDefaultAsync(m => m.Id == id);
|
if(ownedMachine == null) return NotFound();
|
||||||
if (ownedMachine == null)
|
|
||||||
{
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
return View(ownedMachine);
|
return View(ownedMachine);
|
||||||
}
|
}
|
||||||
@@ -57,7 +56,13 @@ namespace cicm_web.Areas.Admin.Controllers
|
|||||||
// GET: OwnedMachine/Create
|
// GET: OwnedMachine/Create
|
||||||
public IActionResult Create()
|
public IActionResult Create()
|
||||||
{
|
{
|
||||||
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name");
|
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).Select(u => new {u.Id, u.UserName}), "Id",
|
||||||
|
"UserName");
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +71,10 @@ namespace cicm_web.Areas.Admin.Controllers
|
|||||||
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[ValidateAntiForgeryToken]
|
[ValidateAntiForgeryToken]
|
||||||
public async Task<IActionResult> Create([Bind("AcquisitionDate,LostDate,Status,LastStatusDate,Trade,Boxed,Manuals,SerialNumber,SerialNumberVisible,MachineId,Id")] OwnedMachine ownedMachine)
|
public async Task<IActionResult> Create(
|
||||||
|
[Bind(
|
||||||
|
"AcquisitionDate,LostDate,Status,LastStatusDate,Trade,Boxed,Manuals,SerialNumber,SerialNumberVisible,MachineId,UserId,Id")]
|
||||||
|
OwnedMachine ownedMachine)
|
||||||
{
|
{
|
||||||
if(ModelState.IsValid)
|
if(ModelState.IsValid)
|
||||||
{
|
{
|
||||||
@@ -74,23 +82,25 @@ namespace cicm_web.Areas.Admin.Controllers
|
|||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
return RedirectToAction(nameof(Index));
|
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).Select(u => new {u.Id, u.UserName}), "Id",
|
||||||
|
"UserName");
|
||||||
return View(ownedMachine);
|
return View(ownedMachine);
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET: OwnedMachine/Edit/5
|
// GET: OwnedMachine/Edit/5
|
||||||
public async Task<IActionResult> Edit(long? id)
|
public async Task<IActionResult> Edit(long? id)
|
||||||
{
|
{
|
||||||
if (id == null)
|
if(id == null) return NotFound();
|
||||||
{
|
|
||||||
return NotFound();
|
OwnedMachine ownedMachine = await _context.OwnedMachines.FindAsync(id);
|
||||||
}
|
if(ownedMachine == null) return NotFound();
|
||||||
|
|
||||||
var 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, "Id", "Name", ownedMachine.MachineId);
|
||||||
return View(ownedMachine);
|
return View(ownedMachine);
|
||||||
}
|
}
|
||||||
@@ -100,12 +110,12 @@ namespace cicm_web.Areas.Admin.Controllers
|
|||||||
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[ValidateAntiForgeryToken]
|
[ValidateAntiForgeryToken]
|
||||||
public async Task<IActionResult> Edit(long id, [Bind("AcquisitionDate,LostDate,Status,LastStatusDate,Trade,Boxed,Manuals,SerialNumber,SerialNumberVisible,MachineId,Id")] OwnedMachine ownedMachine)
|
public async Task<IActionResult> Edit(
|
||||||
|
long id, [Bind(
|
||||||
|
"AcquisitionDate,LostDate,Status,LastStatusDate,Trade,Boxed,Manuals,SerialNumber,SerialNumberVisible,MachineId,Id")]
|
||||||
|
OwnedMachine ownedMachine)
|
||||||
{
|
{
|
||||||
if (id != ownedMachine.Id)
|
if(id != ownedMachine.Id) return NotFound();
|
||||||
{
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ModelState.IsValid)
|
if(ModelState.IsValid)
|
||||||
{
|
{
|
||||||
@@ -116,17 +126,14 @@ namespace cicm_web.Areas.Admin.Controllers
|
|||||||
}
|
}
|
||||||
catch(DbUpdateConcurrencyException)
|
catch(DbUpdateConcurrencyException)
|
||||||
{
|
{
|
||||||
if (!OwnedMachineExists(ownedMachine.Id))
|
if(!OwnedMachineExists(ownedMachine.Id)) return NotFound();
|
||||||
{
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return RedirectToAction(nameof(Index));
|
return RedirectToAction(nameof(Index));
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", ownedMachine.MachineId);
|
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", ownedMachine.MachineId);
|
||||||
return View(ownedMachine);
|
return View(ownedMachine);
|
||||||
}
|
}
|
||||||
@@ -134,34 +141,28 @@ namespace cicm_web.Areas.Admin.Controllers
|
|||||||
// GET: OwnedMachine/Delete/5
|
// GET: OwnedMachine/Delete/5
|
||||||
public async Task<IActionResult> Delete(long? id)
|
public async Task<IActionResult> Delete(long? id)
|
||||||
{
|
{
|
||||||
if (id == null)
|
if(id == null) return NotFound();
|
||||||
{
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
var ownedMachine = await _context.OwnedMachines
|
OwnedMachine ownedMachine = await _context.OwnedMachines
|
||||||
.Include(o => o.Machine)
|
.Include(o => o.Machine).FirstOrDefaultAsync(m => m.Id == id);
|
||||||
.FirstOrDefaultAsync(m => m.Id == id);
|
if(ownedMachine == null) return NotFound();
|
||||||
if (ownedMachine == null)
|
|
||||||
{
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
return View(ownedMachine);
|
return View(ownedMachine);
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST: OwnedMachine/Delete/5
|
// POST: OwnedMachine/Delete/5
|
||||||
[HttpPost, ActionName("Delete")]
|
[HttpPost]
|
||||||
|
[ActionName("Delete")]
|
||||||
[ValidateAntiForgeryToken]
|
[ValidateAntiForgeryToken]
|
||||||
public async Task<IActionResult> DeleteConfirmed(long id)
|
public async Task<IActionResult> DeleteConfirmed(long id)
|
||||||
{
|
{
|
||||||
var ownedMachine = await _context.OwnedMachines.FindAsync(id);
|
OwnedMachine ownedMachine = await _context.OwnedMachines.FindAsync(id);
|
||||||
_context.OwnedMachines.Remove(ownedMachine);
|
_context.OwnedMachines.Remove(ownedMachine);
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
return RedirectToAction(nameof(Index));
|
return RedirectToAction(nameof(Index));
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool OwnedMachineExists(long id)
|
bool OwnedMachineExists(long id)
|
||||||
{
|
{
|
||||||
return _context.OwnedMachines.Any(e => e.Id == id);
|
return _context.OwnedMachines.Any(e => e.Id == id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
@using Cicm.Database
|
||||||
@model Cicm.Database.Models.OwnedMachine
|
@model Cicm.Database.Models.OwnedMachine
|
||||||
|
|
||||||
@{
|
@{
|
||||||
@@ -6,64 +7,122 @@
|
|||||||
|
|
||||||
<h1>Create</h1>
|
<h1>Create</h1>
|
||||||
|
|
||||||
<h4>OwnedMachine</h4>
|
<h4>Owned machine</h4>
|
||||||
<hr />
|
<hr />
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<form asp-action="Create">
|
<form asp-action="Create">
|
||||||
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
<div asp-validation-summary="ModelOnly"
|
||||||
<div class="form-group">
|
class="text-danger">
|
||||||
<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>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label asp-for="LostDate" class="control-label"></label>
|
<label asp-for="AcquisitionDate"
|
||||||
<input asp-for="LostDate" class="form-control" />
|
class="control-label">
|
||||||
<span asp-validation-for="LostDate" class="text-danger"></span>
|
</label>
|
||||||
|
<input asp-for="AcquisitionDate"
|
||||||
|
class="form-control" />
|
||||||
|
<span asp-validation-for="AcquisitionDate"
|
||||||
|
class="text-danger">
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label asp-for="Status" class="control-label"></label>
|
<label asp-for="LostDate"
|
||||||
<select asp-for="Status" class="form-control"></select>
|
class="control-label">
|
||||||
<span asp-validation-for="Status" class="text-danger"></span>
|
</label>
|
||||||
|
<input asp-for="LostDate"
|
||||||
|
class="form-control" />
|
||||||
|
<span asp-validation-for="LostDate"
|
||||||
|
class="text-danger">
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label asp-for="LastStatusDate" class="control-label"></label>
|
<label asp-for="Status"
|
||||||
<input asp-for="LastStatusDate" class="form-control" />
|
class="control-label">
|
||||||
<span asp-validation-for="LastStatusDate" class="text-danger"></span>
|
</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>
|
||||||
<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">
|
<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>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group form-check">
|
<div class="form-check form-group">
|
||||||
<label class="form-check-label">
|
<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>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group form-check">
|
<div class="form-check form-group">
|
||||||
<label class="form-check-label">
|
<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>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label asp-for="SerialNumber" class="control-label"></label>
|
<label asp-for="SerialNumber"
|
||||||
<input asp-for="SerialNumber" class="form-control" />
|
class="control-label">
|
||||||
<span asp-validation-for="SerialNumber" class="text-danger"></span>
|
</label>
|
||||||
|
<input asp-for="SerialNumber"
|
||||||
|
class="form-control" />
|
||||||
|
<span asp-validation-for="SerialNumber"
|
||||||
|
class="text-danger">
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="form-check form-group">
|
||||||
|
<label class="form-check-label">
|
||||||
|
<input class="form-check-input"
|
||||||
|
asp-for="SerialNumberVisible"
|
||||||
|
checked /> @Html.DisplayNameFor(model => model.SerialNumberVisible)
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label asp-for="MachineId" class="control-label"></label>
|
<label asp-for="Machine"
|
||||||
<select asp-for="MachineId" class ="form-control" asp-items="ViewBag.MachineId"></select>
|
class="control-label">
|
||||||
|
</label>
|
||||||
|
<select asp-for="MachineId"
|
||||||
|
class="form-control"
|
||||||
|
asp-items="ViewBag.MachineId">
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<input type="submit" value="Create" class="btn btn-primary" />
|
<label asp-for="User"
|
||||||
|
class="control-label">
|
||||||
|
</label>
|
||||||
|
<select asp-for="UserId"
|
||||||
|
class="form-control"
|
||||||
|
asp-items="ViewBag.UserId">
|
||||||
|
</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>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
@section Scripts {
|
||||||
<a asp-action="Index">Back to List</a>
|
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
||||||
</div>
|
}
|
||||||
|
|
||||||
@@ -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.679</Version>
|
<Version>3.0.99.681</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