Refactor and reorganize code.

This commit is contained in:
2020-02-10 22:44:18 +00:00
parent ed5aacd34e
commit da352de481
345 changed files with 15117 additions and 20198 deletions

View File

@@ -30,8 +30,8 @@
using System.Linq;
using System.Threading.Tasks;
using Marechai.Database.Models;
using Marechai.Areas.Admin.Models;
using Marechai.Database.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
@@ -40,42 +40,40 @@ using Microsoft.EntityFrameworkCore.Query;
namespace Marechai.Areas.Admin.Controllers
{
[Area("Admin")]
[Authorize]
[Area("Admin"), Authorize]
public class StorageByMachinesController : Controller
{
readonly MarechaiContext _context;
public StorageByMachinesController(MarechaiContext context)
{
_context = context;
}
public StorageByMachinesController(MarechaiContext context) => _context = context;
// GET: Admin/StorageByMachines
public async Task<IActionResult> Index()
{
IIncludableQueryable<StorageByMachine, Machine> marechaiContext =
_context.StorageByMachine.Include(s => s.Machine);
return View(await marechaiContext.OrderBy(s => s.Machine.Company.Name).ThenBy(s => s.Machine.Name)
.Select(s => new StorageByMachineViewModel
{
Id = s.Id,
Company = s.Machine.Company.Name,
Machine = s.Machine.Name,
Type = s.Type,
Interface = s.Interface,
Capacity = s.Capacity
}).ToListAsync());
return View(await marechaiContext.OrderBy(s => s.Machine.Company.Name).ThenBy(s => s.Machine.Name).
Select(s => new StorageByMachineViewModel
{
Id = s.Id, Company = s.Machine.Company.Name,
Machine = s.Machine.Name,
Type = s.Type, Interface = s.Interface,
Capacity = s.Capacity
}).ToListAsync());
}
// GET: Admin/StorageByMachines/Details/5
public async Task<IActionResult> Details(long? id)
{
if(id == null) return NotFound();
if(id == null)
return NotFound();
StorageByMachine storageByMachine =
await _context.StorageByMachine.Include(s => s.Machine).FirstOrDefaultAsync(m => m.Id == id);
if(storageByMachine == null) return NotFound();
if(storageByMachine == null)
return NotFound();
return View(storageByMachine);
}
@@ -84,14 +82,14 @@ namespace Marechai.Areas.Admin.Controllers
public IActionResult Create()
{
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name");
return View();
}
// POST: Admin/StorageByMachines/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]
[HttpPost, ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("MachineId,Type,Interface,Capacity,Id")]
StorageByMachine storageByMachine)
{
@@ -99,34 +97,40 @@ namespace Marechai.Areas.Admin.Controllers
{
_context.Add(storageByMachine);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", storageByMachine.MachineId);
return View(storageByMachine);
}
// GET: Admin/StorageByMachines/Edit/5
public async Task<IActionResult> Edit(long? id)
{
if(id == null) return NotFound();
if(id == null)
return NotFound();
StorageByMachine storageByMachine = await _context.StorageByMachine.FindAsync(id);
if(storageByMachine == null) return NotFound();
if(storageByMachine == null)
return NotFound();
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", storageByMachine.MachineId);
return View(storageByMachine);
}
// POST: Admin/StorageByMachines/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]
[HttpPost, ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(long id, [Bind("MachineId,Type,Interface,Capacity,Id")]
StorageByMachine storageByMachine)
{
if(id != storageByMachine.Id) return NotFound();
if(id != storageByMachine.Id)
return NotFound();
if(ModelState.IsValid)
{
@@ -137,7 +141,8 @@ namespace Marechai.Areas.Admin.Controllers
}
catch(DbUpdateConcurrencyException)
{
if(!StorageByMachineExists(storageByMachine.Id)) return NotFound();
if(!StorageByMachineExists(storageByMachine.Id))
return NotFound();
throw;
}
@@ -146,36 +151,36 @@ namespace Marechai.Areas.Admin.Controllers
}
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", storageByMachine.MachineId);
return View(storageByMachine);
}
// GET: Admin/StorageByMachines/Delete/5
public async Task<IActionResult> Delete(long? id)
{
if(id == null) return NotFound();
if(id == null)
return NotFound();
StorageByMachine storageByMachine =
await _context.StorageByMachine.Include(s => s.Machine).FirstOrDefaultAsync(m => m.Id == id);
if(storageByMachine == null) return NotFound();
if(storageByMachine == null)
return NotFound();
return View(storageByMachine);
}
// POST: Admin/StorageByMachines/Delete/5
[HttpPost]
[ActionName("Delete")]
[ValidateAntiForgeryToken]
[HttpPost, ActionName("Delete"), ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(long id)
{
StorageByMachine storageByMachine = await _context.StorageByMachine.FindAsync(id);
_context.StorageByMachine.Remove(storageByMachine);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
bool StorageByMachineExists(long id)
{
return _context.StorageByMachine.Any(e => e.Id == id);
}
bool StorageByMachineExists(long id) => _context.StorageByMachine.Any(e => e.Id == id);
}
}