mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
171 lines
6.4 KiB
C#
171 lines
6.4 KiB
C#
/******************************************************************************
|
|
// Canary Islands Computer Museum Website
|
|
// ----------------------------------------------------------------------------
|
|
//
|
|
// Filename : MemoryByMachinesController.cs
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
//
|
|
// --[ Description ] ----------------------------------------------------------
|
|
//
|
|
// Memory by machines admin controller
|
|
//
|
|
// --[ License ] --------------------------------------------------------------
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
// License, or (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
//
|
|
// ----------------------------------------------------------------------------
|
|
// Copyright © 2003-2018 Natalia Portillo
|
|
*******************************************************************************/
|
|
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Cicm.Database.Models;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Query;
|
|
|
|
namespace cicm_web.Areas.Admin.Controllers
|
|
{
|
|
[Area("Admin")]
|
|
[Authorize]
|
|
public class MemoryByMachinesController : Controller
|
|
{
|
|
readonly cicmContext _context;
|
|
|
|
public MemoryByMachinesController(cicmContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
// GET: Admin/MemoryByMachines
|
|
public async Task<IActionResult> Index()
|
|
{
|
|
IIncludableQueryable<MemoryByMachine, Machine> cicmContext =
|
|
_context.MemoryByMachine.Include(m => m.Machine);
|
|
return View(await cicmContext.ToListAsync());
|
|
}
|
|
|
|
// GET: Admin/MemoryByMachines/Details/5
|
|
public async Task<IActionResult> Details(long? id)
|
|
{
|
|
if(id == null) return NotFound();
|
|
|
|
MemoryByMachine memoryByMachine =
|
|
await _context.MemoryByMachine.Include(m => m.Machine).FirstOrDefaultAsync(m => m.Id == id);
|
|
if(memoryByMachine == null) return NotFound();
|
|
|
|
return View(memoryByMachine);
|
|
}
|
|
|
|
// GET: Admin/MemoryByMachines/Create
|
|
public IActionResult Create()
|
|
{
|
|
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name");
|
|
return View();
|
|
}
|
|
|
|
// POST: Admin/MemoryByMachines/Create
|
|
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
|
|
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public async Task<IActionResult> Create([Bind("MachineId,Type,Usage,Size,Speed,Id")]
|
|
MemoryByMachine memoryByMachine)
|
|
{
|
|
if(ModelState.IsValid)
|
|
{
|
|
_context.Add(memoryByMachine);
|
|
await _context.SaveChangesAsync();
|
|
return RedirectToAction(nameof(Index));
|
|
}
|
|
|
|
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", memoryByMachine.MachineId);
|
|
return View(memoryByMachine);
|
|
}
|
|
|
|
// GET: Admin/MemoryByMachines/Edit/5
|
|
public async Task<IActionResult> Edit(long? id)
|
|
{
|
|
if(id == null) return NotFound();
|
|
|
|
MemoryByMachine memoryByMachine = await _context.MemoryByMachine.FindAsync(id);
|
|
if(memoryByMachine == null) return NotFound();
|
|
|
|
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", memoryByMachine.MachineId);
|
|
return View(memoryByMachine);
|
|
}
|
|
|
|
// POST: Admin/MemoryByMachines/Edit/5
|
|
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
|
|
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public async Task<IActionResult> Edit(long id, [Bind("MachineId,Type,Usage,Size,Speed,Id")]
|
|
MemoryByMachine memoryByMachine)
|
|
{
|
|
if(id != memoryByMachine.Id) return NotFound();
|
|
|
|
if(ModelState.IsValid)
|
|
{
|
|
try
|
|
{
|
|
_context.Update(memoryByMachine);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
catch(DbUpdateConcurrencyException)
|
|
{
|
|
if(!MemoryByMachineExists(memoryByMachine.Id)) return NotFound();
|
|
|
|
throw;
|
|
}
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
}
|
|
|
|
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", memoryByMachine.MachineId);
|
|
return View(memoryByMachine);
|
|
}
|
|
|
|
// GET: Admin/MemoryByMachines/Delete/5
|
|
public async Task<IActionResult> Delete(long? id)
|
|
{
|
|
if(id == null) return NotFound();
|
|
|
|
MemoryByMachine memoryByMachine =
|
|
await _context.MemoryByMachine.Include(m => m.Machine).FirstOrDefaultAsync(m => m.Id == id);
|
|
if(memoryByMachine == null) return NotFound();
|
|
|
|
return View(memoryByMachine);
|
|
}
|
|
|
|
// POST: Admin/MemoryByMachines/Delete/5
|
|
[HttpPost]
|
|
[ActionName("Delete")]
|
|
[ValidateAntiForgeryToken]
|
|
public async Task<IActionResult> DeleteConfirmed(long id)
|
|
{
|
|
MemoryByMachine memoryByMachine = await _context.MemoryByMachine.FindAsync(id);
|
|
_context.MemoryByMachine.Remove(memoryByMachine);
|
|
await _context.SaveChangesAsync();
|
|
return RedirectToAction(nameof(Index));
|
|
}
|
|
|
|
bool MemoryByMachineExists(long id)
|
|
{
|
|
return _context.MemoryByMachine.Any(e => e.Id == id);
|
|
}
|
|
}
|
|
} |