Implement create admin page for resolutions by screen.

This commit is contained in:
2019-06-02 01:31:22 +01:00
parent 598a2dff19
commit fdf1787146
4 changed files with 51 additions and 18 deletions

View File

@@ -42,8 +42,5 @@ namespace Cicm.Database.Models
public virtual ICollection<ScreensByMachine> ScreensByMachines { get; set; } public virtual ICollection<ScreensByMachine> ScreensByMachines { get; set; }
[Required] [Required]
public int NativeResolutionId { get; set; } public int NativeResolutionId { get; set; }
public override string ToString() =>
NativeResolution != null ? $"{Diagonal}\" {Type} at {NativeResolution}" : $"{Diagonal}\" {Type}";
} }
} }

View File

@@ -45,8 +45,13 @@ namespace cicm_web.Areas.Admin.Controllers
// GET: ResolutionsByScreen/Create // GET: ResolutionsByScreen/Create
public IActionResult Create() public IActionResult Create()
{ {
ViewData["ResolutionId"] = new SelectList(_context.Resolutions, "Id", "Id"); ViewData["ResolutionId"] =
ViewData["ScreenId"] = new SelectList(_context.Screens, "Id", "Type"); new SelectList(_context.Resolutions.Select(r => new {r.Id, Name = r.ToString()}).OrderBy(r => r.Name),
"Id", "Name");
ViewData["ScreenId"] =
new
SelectList(_context.Screens.Select(s => new {s.Id, Name = s.NativeResolution != null ? $"{s.Diagonal}\" {s.Type} at {s.NativeResolution}" : $"{s.Diagonal}\" {s.Type}"}).OrderBy(s => s.Name),
"Id", "Name");
return View(); return View();
} }
@@ -66,8 +71,12 @@ namespace cicm_web.Areas.Admin.Controllers
} }
ViewData["ResolutionId"] = ViewData["ResolutionId"] =
new SelectList(_context.Resolutions, "Id", "Id", resolutionsByScreen.ResolutionId); new SelectList(_context.Resolutions.Select(r => new {r.Id, Name = r.ToString()}).OrderBy(r => r.Name),
ViewData["ScreenId"] = new SelectList(_context.Screens, "Id", "Type", resolutionsByScreen.ScreenId); "Id", "Name", resolutionsByScreen.ResolutionId);
ViewData["ScreenId"] =
new
SelectList(_context.Screens.Select(s => new {s.Id, Name = s.NativeResolution != null ? $"{s.Diagonal}\" {s.Type} at {s.NativeResolution}" : $"{s.Diagonal}\" {s.Type}"}).OrderBy(s => s.Name),
"Id", "Name", resolutionsByScreen.ScreenId);
return View(resolutionsByScreen); return View(resolutionsByScreen);
} }
@@ -80,8 +89,12 @@ namespace cicm_web.Areas.Admin.Controllers
if(resolutionsByScreen == null) return NotFound(); if(resolutionsByScreen == null) return NotFound();
ViewData["ResolutionId"] = ViewData["ResolutionId"] =
new SelectList(_context.Resolutions, "Id", "Id", resolutionsByScreen.ResolutionId); new SelectList(_context.Resolutions.Select(r => new {r.Id, Name = r.ToString()}).OrderBy(r => r.Name),
ViewData["ScreenId"] = new SelectList(_context.Screens, "Id", "Type", resolutionsByScreen.ScreenId); "Id", "Name", resolutionsByScreen.ResolutionId);
ViewData["ScreenId"] =
new
SelectList(_context.Screens.Select(s => new {s.Id, Name = s.NativeResolution != null ? $"{s.Diagonal}\" {s.Type} at {s.NativeResolution}" : $"{s.Diagonal}\" {s.Type}"}).OrderBy(s => s.Name),
"Id", "Name", resolutionsByScreen.ScreenId);
return View(resolutionsByScreen); return View(resolutionsByScreen);
} }
@@ -113,8 +126,12 @@ namespace cicm_web.Areas.Admin.Controllers
} }
ViewData["ResolutionId"] = ViewData["ResolutionId"] =
new SelectList(_context.Resolutions, "Id", "Id", resolutionsByScreen.ResolutionId); new SelectList(_context.Resolutions.Select(r => new {r.Id, Name = r.ToString()}).OrderBy(r => r.Name),
ViewData["ScreenId"] = new SelectList(_context.Screens, "Id", "Type", resolutionsByScreen.ScreenId); "Id", "Name", resolutionsByScreen.ResolutionId);
ViewData["ScreenId"] =
new
SelectList(_context.Screens.Select(s => new {s.Id, Name = s.NativeResolution != null ? $"{s.Diagonal}\" {s.Type} at {s.NativeResolution}" : $"{s.Diagonal}\" {s.Type}"}).OrderBy(s => s.Name),
"Id", "Name", resolutionsByScreen.ScreenId);
return View(resolutionsByScreen); return View(resolutionsByScreen);
} }
@@ -147,5 +164,14 @@ namespace cicm_web.Areas.Admin.Controllers
{ {
return _context.ResolutionsByScreen.Any(e => e.Id == id); return _context.ResolutionsByScreen.Any(e => e.Id == id);
} }
[AcceptVerbs("Get", "Post")]
public async Task<IActionResult> VerifyUnique(int screenId, int resolutionId)
{
return await _context.ResolutionsByScreen.FirstOrDefaultAsync(i => i.ScreenId == screenId &&
i.ResolutionId == resolutionId) is null
? Json(true)
: Json("The selected screen already has the selected resolution.");
}
} }
} }

View File

@@ -6,7 +6,7 @@
<h1>Create</h1> <h1>Create</h1>
<h4>ResolutionsByScreen</h4> <h4>Resolutions by screen</h4>
<hr /> <hr />
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">
@@ -15,32 +15,42 @@
class="text-danger"> class="text-danger">
</div> </div>
<div class="form-group"> <div class="form-group">
<label asp-for="ScreenId" <label asp-for="Screen"
class="control-label"> class="control-label">
</label> </label>
<select asp-for="ScreenId" <select asp-for="ScreenId"
class="form-control" class="form-control"
asp-items="ViewBag.ScreenId"> asp-items="ViewBag.ScreenId">
</select> </select>
<span asp-validation-for="ScreenId"
class="text-danger">
</span>
</div> </div>
<div class="form-group"> <div class="form-group">
<label asp-for="ResolutionId" <label asp-for="Resolution"
class="control-label"> class="control-label">
</label> </label>
<select asp-for="ResolutionId" <select asp-for="ResolutionId"
class="form-control" class="form-control"
asp-items="ViewBag.ResolutionId"> asp-items="ViewBag.ResolutionId">
</select> </select>
<span asp-validation-for="ResolutionId"
class="text-danger">
</span>
</div> </div>
<div class="form-group"> <div class="form-group">
<input class="btn btn-primary" <input class="btn btn-primary"
type="submit" type="submit"
value="Create" /> value="Create" />
<a asp-action="Index"
class="btn btn-secondary">
Back to List
</a>
</div> </div>
</form> </form>
</div> </div>
</div> </div>
<div> @section Scripts {
<a asp-action="Index">Back to List</a> @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
</div> }

View File

@@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework> <TargetFramework>netcoreapp2.2</TargetFramework>
<Version>3.0.99.732</Version> <Version>3.0.99.740</Version>
<Company>Canary Islands Computer Museum</Company> <Company>Canary Islands Computer Museum</Company>
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright> <Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
<Product>Canary Islands Computer Museum Website</Product> <Product>Canary Islands Computer Museum Website</Product>