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; }
[Required]
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
public IActionResult Create()
{
ViewData["ResolutionId"] = new SelectList(_context.Resolutions, "Id", "Id");
ViewData["ScreenId"] = new SelectList(_context.Screens, "Id", "Type");
ViewData["ResolutionId"] =
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();
}
@@ -66,8 +71,12 @@ namespace cicm_web.Areas.Admin.Controllers
}
ViewData["ResolutionId"] =
new SelectList(_context.Resolutions, "Id", "Id", resolutionsByScreen.ResolutionId);
ViewData["ScreenId"] = new SelectList(_context.Screens, "Id", "Type", resolutionsByScreen.ScreenId);
new SelectList(_context.Resolutions.Select(r => new {r.Id, Name = r.ToString()}).OrderBy(r => r.Name),
"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);
}
@@ -80,8 +89,12 @@ namespace cicm_web.Areas.Admin.Controllers
if(resolutionsByScreen == null) return NotFound();
ViewData["ResolutionId"] =
new SelectList(_context.Resolutions, "Id", "Id", resolutionsByScreen.ResolutionId);
ViewData["ScreenId"] = new SelectList(_context.Screens, "Id", "Type", resolutionsByScreen.ScreenId);
new SelectList(_context.Resolutions.Select(r => new {r.Id, Name = r.ToString()}).OrderBy(r => r.Name),
"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);
}
@@ -113,8 +126,12 @@ namespace cicm_web.Areas.Admin.Controllers
}
ViewData["ResolutionId"] =
new SelectList(_context.Resolutions, "Id", "Id", resolutionsByScreen.ResolutionId);
ViewData["ScreenId"] = new SelectList(_context.Screens, "Id", "Type", resolutionsByScreen.ScreenId);
new SelectList(_context.Resolutions.Select(r => new {r.Id, Name = r.ToString()}).OrderBy(r => r.Name),
"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);
}
@@ -147,5 +164,14 @@ namespace cicm_web.Areas.Admin.Controllers
{
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>
<h4>ResolutionsByScreen</h4>
<h4>Resolutions by screen</h4>
<hr />
<div class="row">
<div class="col-md-4">
@@ -15,32 +15,42 @@
class="text-danger">
</div>
<div class="form-group">
<label asp-for="ScreenId"
<label asp-for="Screen"
class="control-label">
</label>
<select asp-for="ScreenId"
class="form-control"
asp-items="ViewBag.ScreenId">
</select>
<span asp-validation-for="ScreenId"
class="text-danger">
</span>
</div>
<div class="form-group">
<label asp-for="ResolutionId"
<label asp-for="Resolution"
class="control-label">
</label>
<select asp-for="ResolutionId"
class="form-control"
asp-items="ViewBag.ResolutionId">
</select>
<span asp-validation-for="ResolutionId"
class="text-danger">
</span>
</div>
<div class="form-group">
<input class="btn btn-primary"
type="submit"
value="Create" />
<a asp-action="Index"
class="btn btn-secondary">
Back to List
</a>
</div>
</form>
</div>
</div>
<div>
<a asp-action="Index">Back to List</a>
</div>
@section Scripts {
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
}

View File

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