2019-06-01 22:59:18 +01:00
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Cicm.Database.Models;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
namespace cicm_web.Areas.Admin.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Area("Admin")]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class ScreensController : Controller
|
|
|
|
|
{
|
|
|
|
|
readonly cicmContext _context;
|
|
|
|
|
|
|
|
|
|
public ScreensController(cicmContext context)
|
|
|
|
|
{
|
|
|
|
|
_context = context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: Screens
|
2019-06-01 23:48:54 +01:00
|
|
|
public async Task<IActionResult> Index() =>
|
2019-06-01 23:55:06 +01: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)
|
|
|
|
|
{
|
|
|
|
|
if(id == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
Screen screen = await _context.Screens.FirstOrDefaultAsync(m => m.Id == id);
|
|
|
|
|
if(screen == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
return View(screen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: Screens/Create
|
2019-06-02 00:35:41 +01:00
|
|
|
public IActionResult Create()
|
|
|
|
|
{
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
[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();
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-02 00:35:41 +01: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-01 22:59:18 +01:00
|
|
|
return View(screen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: Screens/Edit/5
|
|
|
|
|
public async Task<IActionResult> Edit(int? id)
|
|
|
|
|
{
|
|
|
|
|
if(id == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
Screen screen = await _context.Screens.FindAsync(id);
|
|
|
|
|
if(screen == null) return NotFound();
|
|
|
|
|
|
2019-06-02 00:51:59 +01: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-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.
|
|
|
|
|
[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
|
|
|
{
|
|
|
|
|
if(id != screen.Id) return NotFound();
|
|
|
|
|
|
|
|
|
|
if(ModelState.IsValid)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_context.Update(screen);
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
}
|
|
|
|
|
catch(DbUpdateConcurrencyException)
|
|
|
|
|
{
|
|
|
|
|
if(!ScreenExists(screen.Id)) return NotFound();
|
|
|
|
|
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-02 00:51:59 +01: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-01 22:59:18 +01:00
|
|
|
return View(screen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: Screens/Delete/5
|
|
|
|
|
public async Task<IActionResult> Delete(int? id)
|
|
|
|
|
{
|
|
|
|
|
if(id == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
Screen screen = await _context.Screens.FirstOrDefaultAsync(m => m.Id == id);
|
|
|
|
|
if(screen == null) return NotFound();
|
|
|
|
|
|
|
|
|
|
return View(screen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: Screens/Delete/5
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ActionName("Delete")]
|
|
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
public async Task<IActionResult> DeleteConfirmed(int id)
|
|
|
|
|
{
|
|
|
|
|
Screen screen = await _context.Screens.FindAsync(id);
|
|
|
|
|
_context.Screens.Remove(screen);
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ScreenExists(int id)
|
|
|
|
|
{
|
|
|
|
|
return _context.Screens.Any(e => e.Id == id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|