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.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Cicm.Database.Models
|
||||
{
|
||||
public class OwnedMachine : BaseModel<long>
|
||||
{
|
||||
[DisplayName("Acquisition date")]
|
||||
public DateTime AcquisitionDate { get; set; }
|
||||
[DisplayName("Date when sold, traded, or otherwise lost")]
|
||||
public DateTime? LostDate { get; set; }
|
||||
public StatusType Status { get; set; }
|
||||
[DisplayName("Last status check date")]
|
||||
public DateTime? LastStatusDate { get; set; }
|
||||
[DisplayName("Available for trade or sale")]
|
||||
public bool Trade { get; set; }
|
||||
[DisplayName("Has original boxes")]
|
||||
public bool Boxed { get; set; }
|
||||
[DisplayName("Has original manuals")]
|
||||
public bool Manuals { get; set; }
|
||||
[DisplayName("Serial number")]
|
||||
public string SerialNumber { get; set; }
|
||||
[DisplayName("Serial number visible to other users")]
|
||||
public bool SerialNumberVisible { get; set; }
|
||||
public int MachineId { get; set; }
|
||||
public string UserId { get; set; }
|
||||
|
||||
public virtual ICollection<GpusByOwnedMachine> Gpus { get; set; }
|
||||
public virtual ICollection<MemoryByOwnedMachine> Memory { get; set; }
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace cicm_web.Areas.Admin.Controllers
|
||||
[Authorize]
|
||||
public class OwnedMachineController : Controller
|
||||
{
|
||||
private readonly cicmContext _context;
|
||||
readonly cicmContext _context;
|
||||
|
||||
public OwnedMachineController(cicmContext context)
|
||||
{
|
||||
@@ -23,11 +23,17 @@ namespace cicm_web.Areas.Admin.Controllers
|
||||
// GET: OwnedMachine
|
||||
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,
|
||||
Id = o.Id,
|
||||
Machine = $"{o.Machine.Company.Name} {o.Machine.Name}",
|
||||
Machine =
|
||||
$"{o.Machine.Company.Name} {o.Machine.Name}",
|
||||
Status = o.Status,
|
||||
User = o.User.UserName
|
||||
});
|
||||
@@ -38,18 +44,11 @@ namespace cicm_web.Areas.Admin.Controllers
|
||||
// GET: OwnedMachine/Details/5
|
||||
public async Task<IActionResult> Details(long? id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
if(id == null) return NotFound();
|
||||
|
||||
var ownedMachine = await _context.OwnedMachines
|
||||
.Include(o => o.Machine)
|
||||
.FirstOrDefaultAsync(m => m.Id == id);
|
||||
if (ownedMachine == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
OwnedMachine ownedMachine = await _context.OwnedMachines
|
||||
.Include(o => o.Machine).FirstOrDefaultAsync(m => m.Id == id);
|
||||
if(ownedMachine == null) return NotFound();
|
||||
|
||||
return View(ownedMachine);
|
||||
}
|
||||
@@ -57,7 +56,13 @@ namespace cicm_web.Areas.Admin.Controllers
|
||||
// GET: OwnedMachine/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();
|
||||
}
|
||||
|
||||
@@ -66,31 +71,36 @@ namespace cicm_web.Areas.Admin.Controllers
|
||||
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
||||
[HttpPost]
|
||||
[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)
|
||||
{
|
||||
_context.Add(ownedMachine);
|
||||
await _context.SaveChangesAsync();
|
||||
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);
|
||||
}
|
||||
|
||||
// GET: OwnedMachine/Edit/5
|
||||
public async Task<IActionResult> Edit(long? id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
if(id == null) 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);
|
||||
return View(ownedMachine);
|
||||
}
|
||||
@@ -100,33 +110,30 @@ namespace cicm_web.Areas.Admin.Controllers
|
||||
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
||||
[HttpPost]
|
||||
[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)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
if(id != ownedMachine.Id) return NotFound();
|
||||
|
||||
if (ModelState.IsValid)
|
||||
if(ModelState.IsValid)
|
||||
{
|
||||
try
|
||||
{
|
||||
_context.Update(ownedMachine);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!OwnedMachineExists(ownedMachine.Id))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
else
|
||||
catch(DbUpdateConcurrencyException)
|
||||
{
|
||||
if(!OwnedMachineExists(ownedMachine.Id)) return NotFound();
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
|
||||
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", ownedMachine.MachineId);
|
||||
return View(ownedMachine);
|
||||
}
|
||||
@@ -134,34 +141,28 @@ namespace cicm_web.Areas.Admin.Controllers
|
||||
// GET: OwnedMachine/Delete/5
|
||||
public async Task<IActionResult> Delete(long? id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
if(id == null) return NotFound();
|
||||
|
||||
var ownedMachine = await _context.OwnedMachines
|
||||
.Include(o => o.Machine)
|
||||
.FirstOrDefaultAsync(m => m.Id == id);
|
||||
if (ownedMachine == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
OwnedMachine ownedMachine = await _context.OwnedMachines
|
||||
.Include(o => o.Machine).FirstOrDefaultAsync(m => m.Id == id);
|
||||
if(ownedMachine == null) return NotFound();
|
||||
|
||||
return View(ownedMachine);
|
||||
}
|
||||
|
||||
// POST: OwnedMachine/Delete/5
|
||||
[HttpPost, ActionName("Delete")]
|
||||
[HttpPost]
|
||||
[ActionName("Delete")]
|
||||
[ValidateAntiForgeryToken]
|
||||
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);
|
||||
await _context.SaveChangesAsync();
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
|
||||
private bool OwnedMachineExists(long id)
|
||||
bool OwnedMachineExists(long id)
|
||||
{
|
||||
return _context.OwnedMachines.Any(e => e.Id == id);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
@using Cicm.Database
|
||||
@model Cicm.Database.Models.OwnedMachine
|
||||
|
||||
@{
|
||||
@@ -6,64 +7,122 @@
|
||||
|
||||
<h1>Create</h1>
|
||||
|
||||
<h4>OwnedMachine</h4>
|
||||
<h4>Owned 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="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-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 class="form-group">
|
||||
<label asp-for="MachineId" class="control-label"></label>
|
||||
<select asp-for="MachineId" class ="form-control" asp-items="ViewBag.MachineId"></select>
|
||||
<label asp-for="Machine"
|
||||
class="control-label">
|
||||
</label>
|
||||
<select asp-for="MachineId"
|
||||
class="form-control"
|
||||
asp-items="ViewBag.MachineId">
|
||||
</select>
|
||||
</div>
|
||||
<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>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<a asp-action="Index">Back to List</a>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<Version>3.0.99.679</Version>
|
||||
<Version>3.0.99.681</Version>
|
||||
<Company>Canary Islands Computer Museum</Company>
|
||||
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
|
||||
<Product>Canary Islands Computer Museum Website</Product>
|
||||
|
||||
Reference in New Issue
Block a user