2019-06-01 22:59:18 +01:00
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-02-10 02:10:18 +00:00
|
|
|
using Marechai.Database.Models;
|
2019-06-01 22:59:18 +01:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2019-06-02 00:35:41 +01:00
|
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
2019-06-01 22:59:18 +01:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
2020-02-10 02:20:48 +00:00
|
|
|
namespace Marechai.Areas.Admin.Controllers
|
2019-06-01 22:59:18 +01:00
|
|
|
{
|
2020-02-10 22:44:18 +00:00
|
|
|
[Area("Admin"), Authorize]
|
2019-06-01 22:59:18 +01:00
|
|
|
public class ScreensController : Controller
|
|
|
|
|
{
|
2020-02-10 02:47:39 +00:00
|
|
|
readonly MarechaiContext _context;
|
2019-06-01 22:59:18 +01:00
|
|
|
|
2020-02-10 22:44:18 +00:00
|
|
|
public ScreensController(MarechaiContext context) => _context = context;
|
2019-06-01 22:59:18 +01:00
|
|
|
|
|
|
|
|
// GET: Screens
|
2019-06-01 23:48:54 +01:00
|
|
|
public async Task<IActionResult> Index() =>
|
2020-02-10 22:44:18 +00:00
|
|
|
View(await _context.Screens.OrderBy(s => s.Diagonal).ThenBy(s => s.EffectiveColors).
|
|
|
|
|
ThenBy(s => s.NativeResolution.ToString()).ThenBy(s => s.Type).ThenBy(s => s.Size).
|
|
|
|
|
ToListAsync());
|
2019-06-01 22:59:18 +01:00
|
|
|
|
|
|
|
|
// GET: Screens/Details/5
|
|
|
|
|
public async Task<IActionResult> Details(int? id)
|
|
|
|
|
{
|
2020-02-10 22:44:18 +00:00
|
|
|
if(id == null)
|
|
|
|
|
return NotFound();
|
2019-06-01 22:59:18 +01:00
|
|
|
|
|
|
|
|
Screen screen = await _context.Screens.FirstOrDefaultAsync(m => m.Id == id);
|
2020-02-10 22:44:18 +00:00
|
|
|
|
|
|
|
|
if(screen == null)
|
|
|
|
|
return NotFound();
|
2019-06-01 22:59:18 +01:00
|
|
|
|
|
|
|
|
return View(screen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: Screens/Create
|
2019-06-02 00:35:41 +01:00
|
|
|
public IActionResult Create()
|
|
|
|
|
{
|
2020-02-10 22:44:18 +00:00
|
|
|
ViewData["NativeResolutionId"] = 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-06-02 00:35:41 +01:00
|
|
|
|
|
|
|
|
return View();
|
|
|
|
|
}
|
2019-06-01 22:59:18 +01:00
|
|
|
|
|
|
|
|
// POST: Screens/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.
|
2020-02-10 22:44:18 +00:00
|
|
|
[HttpPost, ValidateAntiForgeryToken]
|
2019-06-02 00:35:41 +01:00
|
|
|
public async Task<IActionResult> Create(
|
|
|
|
|
[Bind("Width,Height,Diagonal,EffectiveColors,Type,NativeResolutionId,Id")]
|
|
|
|
|
Screen screen)
|
2019-06-01 22:59:18 +01:00
|
|
|
{
|
|
|
|
|
if(ModelState.IsValid)
|
|
|
|
|
{
|
|
|
|
|
_context.Add(screen);
|
|
|
|
|
await _context.SaveChangesAsync();
|
2020-02-10 22:44:18 +00:00
|
|
|
|
2019-06-01 22:59:18 +01:00
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 22:44:18 +00:00
|
|
|
ViewData["NativeResolutionId"] = 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-06-02 00:35:41 +01:00
|
|
|
|
2019-06-01 22:59:18 +01:00
|
|
|
return View(screen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: Screens/Edit/5
|
|
|
|
|
public async Task<IActionResult> Edit(int? id)
|
|
|
|
|
{
|
2020-02-10 22:44:18 +00:00
|
|
|
if(id == null)
|
|
|
|
|
return NotFound();
|
2019-06-01 22:59:18 +01:00
|
|
|
|
|
|
|
|
Screen screen = await _context.Screens.FindAsync(id);
|
|
|
|
|
|
2020-02-10 22:44:18 +00:00
|
|
|
if(screen == null)
|
|
|
|
|
return NotFound();
|
|
|
|
|
|
|
|
|
|
ViewData["NativeResolutionId"] = 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-06-02 00:51:59 +01:00
|
|
|
|
2019-06-01 22:59:18 +01:00
|
|
|
return View(screen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: Screens/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.
|
2020-02-10 22:44:18 +00:00
|
|
|
[HttpPost, ValidateAntiForgeryToken]
|
2019-06-02 00:51:59 +01:00
|
|
|
public async Task<IActionResult> Edit(
|
|
|
|
|
int id, [Bind("Width,Height,Diagonal,EffectiveColors,NativeResolutionId,Type,Id")]
|
|
|
|
|
Screen screen)
|
2019-06-01 22:59:18 +01:00
|
|
|
{
|
2020-02-10 22:44:18 +00:00
|
|
|
if(id != screen.Id)
|
|
|
|
|
return NotFound();
|
2019-06-01 22:59:18 +01:00
|
|
|
|
|
|
|
|
if(ModelState.IsValid)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_context.Update(screen);
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
}
|
|
|
|
|
catch(DbUpdateConcurrencyException)
|
|
|
|
|
{
|
2020-02-10 22:44:18 +00:00
|
|
|
if(!ScreenExists(screen.Id))
|
|
|
|
|
return NotFound();
|
2019-06-01 22:59:18 +01:00
|
|
|
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 22:44:18 +00:00
|
|
|
ViewData["NativeResolutionId"] = 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-06-02 00:51:59 +01:00
|
|
|
|
2019-06-01 22:59:18 +01:00
|
|
|
return View(screen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: Screens/Delete/5
|
|
|
|
|
public async Task<IActionResult> Delete(int? id)
|
|
|
|
|
{
|
2020-02-10 22:44:18 +00:00
|
|
|
if(id == null)
|
|
|
|
|
return NotFound();
|
2019-06-01 22:59:18 +01:00
|
|
|
|
|
|
|
|
Screen screen = await _context.Screens.FirstOrDefaultAsync(m => m.Id == id);
|
2020-02-10 22:44:18 +00:00
|
|
|
|
|
|
|
|
if(screen == null)
|
|
|
|
|
return NotFound();
|
2019-06-01 22:59:18 +01:00
|
|
|
|
|
|
|
|
return View(screen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: Screens/Delete/5
|
2020-02-10 22:44:18 +00:00
|
|
|
[HttpPost, ActionName("Delete"), ValidateAntiForgeryToken]
|
2019-06-01 22:59:18 +01:00
|
|
|
public async Task<IActionResult> DeleteConfirmed(int id)
|
|
|
|
|
{
|
|
|
|
|
Screen screen = await _context.Screens.FindAsync(id);
|
|
|
|
|
_context.Screens.Remove(screen);
|
|
|
|
|
await _context.SaveChangesAsync();
|
2020-02-10 22:44:18 +00:00
|
|
|
|
2019-06-01 22:59:18 +01:00
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 22:44:18 +00:00
|
|
|
bool ScreenExists(int id) => _context.Screens.Any(e => e.Id == id);
|
2019-06-01 22:59:18 +01:00
|
|
|
}
|
|
|
|
|
}
|