diff --git a/Cicm.Database/Models/OwnedMachine.cs b/Cicm.Database/Models/OwnedMachine.cs index 8686455c..fa1a07f7 100644 --- a/Cicm.Database/Models/OwnedMachine.cs +++ b/Cicm.Database/Models/OwnedMachine.cs @@ -1,20 +1,30 @@ using System; using System.Collections.Generic; +using System.ComponentModel; namespace Cicm.Database.Models { public class OwnedMachine : BaseModel { - public DateTime AcquisitionDate { get; set; } - public DateTime? LostDate { get; set; } - public StatusType Status { get; set; } - public DateTime? LastStatusDate { get; set; } - public bool Trade { get; set; } - public bool Boxed { get; set; } - public bool Manuals { get; set; } - public string SerialNumber { get; set; } - public bool SerialNumberVisible { get; set; } - public int MachineId { get; set; } + [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 Gpus { get; set; } public virtual ICollection Memory { get; set; } diff --git a/cicm_web/Areas/Admin/Controllers/OwnedMachineController.cs b/cicm_web/Areas/Admin/Controllers/OwnedMachineController.cs index 15295ef3..020afee5 100644 --- a/cicm_web/Areas/Admin/Controllers/OwnedMachineController.cs +++ b/cicm_web/Areas/Admin/Controllers/OwnedMachineController.cs @@ -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,14 +23,20 @@ namespace cicm_web.Areas.Admin.Controllers // GET: OwnedMachine public async Task 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 - { - AcquisitionDate = o.AcquisitionDate, - Id = o.Id, - Machine = $"{o.Machine.Company.Name} {o.Machine.Name}", - Status = o.Status, - User = o.User.UserName - }); + IQueryable 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}", + Status = o.Status, + User = o.User.UserName + }); return View(await cicmContext.ToListAsync()); } @@ -38,18 +44,11 @@ namespace cicm_web.Areas.Admin.Controllers // GET: OwnedMachine/Details/5 public async Task 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 Create([Bind("AcquisitionDate,LostDate,Status,LastStatusDate,Trade,Boxed,Manuals,SerialNumber,SerialNumberVisible,MachineId,Id")] OwnedMachine ownedMachine) + public async Task 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 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 Edit(long id, [Bind("AcquisitionDate,LostDate,Status,LastStatusDate,Trade,Boxed,Manuals,SerialNumber,SerialNumberVisible,MachineId,Id")] OwnedMachine ownedMachine) + public async Task 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) + catch(DbUpdateConcurrencyException) { - if (!OwnedMachineExists(ownedMachine.Id)) - { - return NotFound(); - } - else - { - throw; - } + 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,36 +141,30 @@ namespace cicm_web.Areas.Admin.Controllers // GET: OwnedMachine/Delete/5 public async Task 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 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); } } -} +} \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/OwnedMachine/Create.cshtml b/cicm_web/Areas/Admin/Views/OwnedMachine/Create.cshtml index 52b96e24..3ff5d435 100644 --- a/cicm_web/Areas/Admin/Views/OwnedMachine/Create.cshtml +++ b/cicm_web/Areas/Admin/Views/OwnedMachine/Create.cshtml @@ -1,3 +1,4 @@ +@using Cicm.Database @model Cicm.Database.Models.OwnedMachine @{ @@ -6,64 +7,122 @@

Create

-

OwnedMachine

+

Owned machine


-
-
- - - +
- - - + + + +
- - - + + + +
- - - + + + +
-
+
+ + + + +
+
-
+
-
+
- - - + + + + +
+
+
- - + +
- + + +
+
- - +@section Scripts { + @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } +} \ No newline at end of file diff --git a/cicm_web/cicm_web.csproj b/cicm_web/cicm_web.csproj index 3259a786..9c268ae6 100644 --- a/cicm_web/cicm_web.csproj +++ b/cicm_web/cicm_web.csproj @@ -2,7 +2,7 @@ netcoreapp2.2 - 3.0.99.679 + 3.0.99.681 Canary Islands Computer Museum Copyright © 2003-2018 Natalia Portillo Canary Islands Computer Museum Website