2020-05-24 02:12:37 +01:00
|
|
|
|
using System.Linq;
|
2019-05-19 15:26:59 +01:00
|
|
|
|
using System.Threading.Tasks;
|
2020-02-10 02:20:48 +00:00
|
|
|
|
using Marechai.Areas.Admin.Models;
|
2020-02-10 22:44:18 +00:00
|
|
|
|
using Marechai.Database.Models;
|
2019-05-19 15:26:59 +01:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore.Query;
|
|
|
|
|
|
|
2020-02-10 02:20:48 +00:00
|
|
|
|
namespace Marechai.Areas.Admin.Controllers
|
2019-05-19 15:26:59 +01:00
|
|
|
|
{
|
2020-02-10 22:44:18 +00:00
|
|
|
|
[Area("Admin"), Authorize]
|
2019-05-19 15:26:59 +01:00
|
|
|
|
public class ResolutionsByGpuController : Controller
|
|
|
|
|
|
{
|
2020-02-10 02:47:39 +00:00
|
|
|
|
readonly MarechaiContext _context;
|
2019-05-19 15:26:59 +01:00
|
|
|
|
|
2020-02-10 22:44:18 +00:00
|
|
|
|
public ResolutionsByGpuController(MarechaiContext context) => _context = context;
|
2019-05-19 15:26:59 +01:00
|
|
|
|
|
|
|
|
|
|
// GET: ResolutionsByGpu
|
|
|
|
|
|
public async Task<IActionResult> Index()
|
|
|
|
|
|
{
|
2020-02-10 02:47:39 +00:00
|
|
|
|
IIncludableQueryable<ResolutionsByGpu, Resolution> marechaiContext =
|
2019-05-19 15:26:59 +01:00
|
|
|
|
_context.ResolutionsByGpu.Include(r => r.Gpu).Include(r => r.Resolution);
|
2020-02-10 22:44:18 +00:00
|
|
|
|
|
|
|
|
|
|
return View(await marechaiContext.OrderBy(r => r.Gpu.Company.Name).ThenBy(r => r.Gpu.Name).
|
|
|
|
|
|
ThenBy(r => r.Resolution.Chars).ThenBy(r => r.Resolution.Width).
|
|
|
|
|
|
ThenBy(r => r.Resolution.Height).ThenBy(r => r.Resolution.Colors).
|
|
|
|
|
|
Select(r => new ResolutionsByGpuViewModel
|
|
|
|
|
|
{
|
|
|
|
|
|
Gpu = r.Gpu.Name, GpuCompany = r.Gpu.Company.Name, Id = r.Id,
|
|
|
|
|
|
Resolution = r.Resolution
|
|
|
|
|
|
}).ToListAsync());
|
2019-05-19 15:26:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GET: ResolutionsByGpu/Details/5
|
|
|
|
|
|
public async Task<IActionResult> Details(long? id)
|
|
|
|
|
|
{
|
2020-02-10 22:44:18 +00:00
|
|
|
|
if(id == null)
|
|
|
|
|
|
return NotFound();
|
|
|
|
|
|
|
|
|
|
|
|
ResolutionsByGpu resolutionsByGpu = await _context.
|
|
|
|
|
|
ResolutionsByGpu.Include(r => r.Gpu).Include(r => r.Resolution).
|
|
|
|
|
|
FirstOrDefaultAsync(m => m.Id == id);
|
2019-05-19 15:26:59 +01:00
|
|
|
|
|
2020-02-10 22:44:18 +00:00
|
|
|
|
if(resolutionsByGpu == null)
|
|
|
|
|
|
return NotFound();
|
2019-05-19 15:26:59 +01:00
|
|
|
|
|
|
|
|
|
|
return View(resolutionsByGpu);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GET: ResolutionsByGpu/Create
|
|
|
|
|
|
public IActionResult Create()
|
|
|
|
|
|
{
|
2020-02-10 22:44:18 +00:00
|
|
|
|
ViewData["GpuId"] = new SelectList(_context.Gpus.OrderBy(r => r.Company.Name).ThenBy(r => r.Name).
|
|
|
|
|
|
Select(g => new
|
|
|
|
|
|
{
|
|
|
|
|
|
g.Id, Name = $"{g.Company.Name} {g.Name}"
|
|
|
|
|
|
}), "Id", "Name");
|
|
|
|
|
|
|
|
|
|
|
|
ViewData["ResolutionId"] = new SelectList(_context.Resolutions.OrderBy(r => r.Chars).ThenBy(r => r.Width).
|
|
|
|
|
|
ThenBy(r => r.Height).ThenBy(r => r.Colors).
|
|
|
|
|
|
Select(r => new
|
|
|
|
|
|
{
|
|
|
|
|
|
r.Id, Name = r.ToString()
|
|
|
|
|
|
}), "Id", "Name");
|
|
|
|
|
|
|
2019-05-19 15:26:59 +01:00
|
|
|
|
return View();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// POST: ResolutionsByGpu/Create
|
2020-02-10 22:44:18 +00:00
|
|
|
|
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
|
2019-05-19 15:26:59 +01:00
|
|
|
|
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
2020-02-10 22:44:18 +00:00
|
|
|
|
[HttpPost, ValidateAntiForgeryToken]
|
2019-05-19 15:26:59 +01:00
|
|
|
|
public async Task<IActionResult> Create([Bind("GpuId,ResolutionId,Id")] ResolutionsByGpu resolutionsByGpu)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(ModelState.IsValid)
|
|
|
|
|
|
{
|
|
|
|
|
|
_context.Add(resolutionsByGpu);
|
|
|
|
|
|
await _context.SaveChangesAsync();
|
2020-02-10 22:44:18 +00:00
|
|
|
|
|
2019-05-19 15:26:59 +01:00
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-10 22:44:18 +00:00
|
|
|
|
ViewData["GpuId"] = new SelectList(_context.Gpus.OrderBy(r => r.Company.Name).ThenBy(r => r.Name).
|
|
|
|
|
|
Select(g => new
|
|
|
|
|
|
{
|
|
|
|
|
|
g.Id, Name = $"{g.Company.Name} {g.Name}"
|
|
|
|
|
|
}), "Id", "Name", resolutionsByGpu.GpuId);
|
|
|
|
|
|
|
|
|
|
|
|
ViewData["ResolutionId"] = new SelectList(_context.Resolutions.OrderBy(r => r.Chars).ThenBy(r => r.Width).
|
|
|
|
|
|
ThenBy(r => r.Height).ThenBy(r => r.Colors).
|
|
|
|
|
|
Select(r => new
|
|
|
|
|
|
{
|
|
|
|
|
|
r.Id, Name = r.ToString()
|
|
|
|
|
|
}), "Id", "Name", resolutionsByGpu.ResolutionId);
|
|
|
|
|
|
|
2019-05-19 15:26:59 +01:00
|
|
|
|
return View(resolutionsByGpu);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GET: ResolutionsByGpu/Edit/5
|
|
|
|
|
|
public async Task<IActionResult> Edit(long? id)
|
|
|
|
|
|
{
|
2020-02-10 22:44:18 +00:00
|
|
|
|
if(id == null)
|
|
|
|
|
|
return NotFound();
|
2019-05-19 15:26:59 +01:00
|
|
|
|
|
|
|
|
|
|
ResolutionsByGpu resolutionsByGpu = await _context.ResolutionsByGpu.FindAsync(id);
|
2020-02-10 22:44:18 +00:00
|
|
|
|
|
|
|
|
|
|
if(resolutionsByGpu == null)
|
|
|
|
|
|
return NotFound();
|
|
|
|
|
|
|
|
|
|
|
|
ViewData["GpuId"] = new SelectList(_context.Gpus.OrderBy(r => r.Company.Name).ThenBy(r => r.Name).
|
|
|
|
|
|
Select(g => new
|
|
|
|
|
|
{
|
|
|
|
|
|
g.Id, Name = $"{g.Company.Name} {g.Name}"
|
|
|
|
|
|
}), "Id", "Name", resolutionsByGpu.GpuId);
|
|
|
|
|
|
|
|
|
|
|
|
ViewData["ResolutionId"] = new SelectList(_context.Resolutions.OrderBy(r => r.Chars).ThenBy(r => r.Width).
|
|
|
|
|
|
ThenBy(r => r.Height).ThenBy(r => r.Colors).
|
|
|
|
|
|
Select(r => new
|
|
|
|
|
|
{
|
|
|
|
|
|
r.Id, Name = r.ToString()
|
|
|
|
|
|
}), "Id", "Name", resolutionsByGpu.ResolutionId);
|
|
|
|
|
|
|
2019-05-19 15:26:59 +01:00
|
|
|
|
return View(resolutionsByGpu);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// POST: ResolutionsByGpu/Edit/5
|
2020-02-10 22:44:18 +00:00
|
|
|
|
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
|
2019-05-19 15:26:59 +01:00
|
|
|
|
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
2020-02-10 22:44:18 +00:00
|
|
|
|
[HttpPost, ValidateAntiForgeryToken]
|
2019-05-19 15:26:59 +01:00
|
|
|
|
public async Task<IActionResult> Edit(
|
|
|
|
|
|
long id, [Bind("GpuId,ResolutionId,Id")] ResolutionsByGpu resolutionsByGpu)
|
|
|
|
|
|
{
|
2020-02-10 22:44:18 +00:00
|
|
|
|
if(id != resolutionsByGpu.Id)
|
|
|
|
|
|
return NotFound();
|
2019-05-19 15:26:59 +01:00
|
|
|
|
|
|
|
|
|
|
if(ModelState.IsValid)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
_context.Update(resolutionsByGpu);
|
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch(DbUpdateConcurrencyException)
|
|
|
|
|
|
{
|
2020-02-10 22:44:18 +00:00
|
|
|
|
if(!ResolutionsByGpuExists(resolutionsByGpu.Id))
|
|
|
|
|
|
return NotFound();
|
2019-05-19 15:26:59 +01:00
|
|
|
|
|
|
|
|
|
|
throw;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-10 22:44:18 +00:00
|
|
|
|
ViewData["GpuId"] = new SelectList(_context.Gpus.OrderBy(r => r.Company.Name).ThenBy(r => r.Name).
|
|
|
|
|
|
Select(g => new
|
|
|
|
|
|
{
|
|
|
|
|
|
g.Id, Name = $"{g.Company.Name} {g.Name}"
|
|
|
|
|
|
}), "Id", "Name", resolutionsByGpu.GpuId);
|
|
|
|
|
|
|
|
|
|
|
|
ViewData["ResolutionId"] = new SelectList(_context.Resolutions.OrderBy(r => r.Chars).ThenBy(r => r.Width).
|
|
|
|
|
|
ThenBy(r => r.Height).ThenBy(r => r.Colors).
|
|
|
|
|
|
Select(r => new
|
|
|
|
|
|
{
|
|
|
|
|
|
r.Id, Name = r.ToString()
|
|
|
|
|
|
}), "Id", "Name", resolutionsByGpu.ResolutionId);
|
|
|
|
|
|
|
2019-05-19 15:26:59 +01:00
|
|
|
|
return View(resolutionsByGpu);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GET: ResolutionsByGpu/Delete/5
|
|
|
|
|
|
public async Task<IActionResult> Delete(long? id)
|
|
|
|
|
|
{
|
2020-02-10 22:44:18 +00:00
|
|
|
|
if(id == null)
|
|
|
|
|
|
return NotFound();
|
|
|
|
|
|
|
|
|
|
|
|
ResolutionsByGpu resolutionsByGpu = await _context.
|
|
|
|
|
|
ResolutionsByGpu.Include(r => r.Gpu).Include(r => r.Resolution).
|
|
|
|
|
|
FirstOrDefaultAsync(m => m.Id == id);
|
2019-05-19 15:26:59 +01:00
|
|
|
|
|
2020-02-10 22:44:18 +00:00
|
|
|
|
if(resolutionsByGpu == null)
|
|
|
|
|
|
return NotFound();
|
2019-05-19 15:26:59 +01:00
|
|
|
|
|
|
|
|
|
|
return View(resolutionsByGpu);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// POST: ResolutionsByGpu/Delete/5
|
2020-02-10 22:44:18 +00:00
|
|
|
|
[HttpPost, ActionName("Delete"), ValidateAntiForgeryToken]
|
2019-05-19 15:26:59 +01:00
|
|
|
|
public async Task<IActionResult> DeleteConfirmed(long id)
|
|
|
|
|
|
{
|
|
|
|
|
|
ResolutionsByGpu resolutionsByGpu = await _context.ResolutionsByGpu.FindAsync(id);
|
|
|
|
|
|
_context.ResolutionsByGpu.Remove(resolutionsByGpu);
|
|
|
|
|
|
await _context.SaveChangesAsync();
|
2020-02-10 22:44:18 +00:00
|
|
|
|
|
2019-05-19 15:26:59 +01:00
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-10 22:44:18 +00:00
|
|
|
|
bool ResolutionsByGpuExists(long id) => _context.ResolutionsByGpu.Any(e => e.Id == id);
|
2019-05-19 20:09:51 +01:00
|
|
|
|
|
|
|
|
|
|
[AcceptVerbs("Get", "Post")]
|
2020-02-10 22:44:18 +00:00
|
|
|
|
public async Task<IActionResult> VerifyUnique(int gpuId, int resolutionId) =>
|
|
|
|
|
|
await _context.ResolutionsByGpu.FirstOrDefaultAsync(i => i.GpuId == gpuId && i.ResolutionId == resolutionId)
|
|
|
|
|
|
is null ? Json(true) : Json("The selected GPU already has the selected resolution.");
|
2019-05-19 15:26:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|