mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Add admin page for company logos.
This commit is contained in:
139
cicm_web/Areas/Admin/Controllers/CompanyLogosController.cs
Normal file
139
cicm_web/Areas/Admin/Controllers/CompanyLogosController.cs
Normal file
@@ -0,0 +1,139 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Cicm.Database.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Query;
|
||||
|
||||
namespace cicm_web.Areas.Admin.Controllers
|
||||
{
|
||||
[Area("Admin")]
|
||||
[Authorize]
|
||||
public class CompanyLogosController : Controller
|
||||
{
|
||||
readonly cicmContext _context;
|
||||
|
||||
public CompanyLogosController(cicmContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// GET: CompanyLogos
|
||||
public async Task<IActionResult> Index()
|
||||
{
|
||||
IIncludableQueryable<CompanyLogo, Company> cicmContext = _context.CompanyLogos.Include(c => c.Company);
|
||||
return View(await cicmContext.OrderBy(l => l.Company.Name).ThenBy(l => l.Year).ToListAsync());
|
||||
}
|
||||
|
||||
// GET: CompanyLogos/Details/5
|
||||
public async Task<IActionResult> Details(int? id)
|
||||
{
|
||||
if(id == null) return NotFound();
|
||||
|
||||
CompanyLogo companyLogo = await _context.CompanyLogos
|
||||
.Include(c => c.Company).FirstOrDefaultAsync(m => m.Id == id);
|
||||
if(companyLogo == null) return NotFound();
|
||||
|
||||
return View(companyLogo);
|
||||
}
|
||||
|
||||
// GET: CompanyLogos/Create
|
||||
// TODO: Upload
|
||||
// public IActionResult Create()
|
||||
// {
|
||||
// ViewData["CompanyId"] = new SelectList(_context.Companies, "Id", "Name");
|
||||
// return View();
|
||||
// }
|
||||
|
||||
// POST: CompanyLogos/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.
|
||||
// TODO: Upload
|
||||
// [HttpPost]
|
||||
// [ValidateAntiForgeryToken]
|
||||
// public async Task<IActionResult> Create([Bind("Id,CompanyId,Year,Guid")] CompanyLogo companyLogo)
|
||||
// {
|
||||
// if (ModelState.IsValid)
|
||||
// {
|
||||
// _context.Add(companyLogo);
|
||||
// await _context.SaveChangesAsync();
|
||||
// return RedirectToAction(nameof(Index));
|
||||
// }
|
||||
// ViewData["CompanyId"] = new SelectList(_context.Companies, "Id", "Name", companyLogo.CompanyId);
|
||||
// return View(companyLogo);
|
||||
// }
|
||||
|
||||
// GET: CompanyLogos/Edit/5
|
||||
public async Task<IActionResult> Edit(int? id)
|
||||
{
|
||||
if(id == null) return NotFound();
|
||||
|
||||
CompanyLogo companyLogo = await _context.CompanyLogos.FirstOrDefaultAsync(c => c.Id == id);
|
||||
if(companyLogo == null) return NotFound();
|
||||
|
||||
ViewData["CompanyId"] = new SelectList(_context.Companies, "Id", "Name", companyLogo.CompanyId);
|
||||
return View(companyLogo);
|
||||
}
|
||||
|
||||
// POST: CompanyLogos/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]
|
||||
public async Task<IActionResult> Edit(int id, [Bind("Id,CompanyId,Year,Guid")] CompanyLogo companyLogo)
|
||||
{
|
||||
if(id != companyLogo.Id) return NotFound();
|
||||
|
||||
if(ModelState.IsValid)
|
||||
{
|
||||
try
|
||||
{
|
||||
_context.Update(companyLogo);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch(DbUpdateConcurrencyException)
|
||||
{
|
||||
if(!CompanyLogoExists(companyLogo.Id)) return NotFound();
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
|
||||
ViewData["CompanyId"] = new SelectList(_context.Companies, "Id", "Name", companyLogo.CompanyId);
|
||||
return View(companyLogo);
|
||||
}
|
||||
|
||||
// GET: CompanyLogos/Delete/5
|
||||
public async Task<IActionResult> Delete(int? id)
|
||||
{
|
||||
if(id == null) return NotFound();
|
||||
|
||||
CompanyLogo companyLogo = await _context.CompanyLogos
|
||||
.Include(c => c.Company).FirstOrDefaultAsync(m => m.Id == id);
|
||||
if(companyLogo == null) return NotFound();
|
||||
|
||||
return View(companyLogo);
|
||||
}
|
||||
|
||||
// POST: CompanyLogos/Delete/5
|
||||
[HttpPost]
|
||||
[ActionName("Delete")]
|
||||
[ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> DeleteConfirmed(int id)
|
||||
{
|
||||
CompanyLogo companyLogo = await _context.CompanyLogos.FindAsync(id);
|
||||
_context.CompanyLogos.Remove(companyLogo);
|
||||
await _context.SaveChangesAsync();
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
|
||||
bool CompanyLogoExists(int id)
|
||||
{
|
||||
return _context.CompanyLogos.Any(e => e.Id == id);
|
||||
}
|
||||
}
|
||||
}
|
||||
41
cicm_web/Areas/Admin/Views/CompanyLogos/Create.cshtml
Normal file
41
cicm_web/Areas/Admin/Views/CompanyLogos/Create.cshtml
Normal file
@@ -0,0 +1,41 @@
|
||||
@* @model Cicm.Database.Models.CompanyLogo *@
|
||||
@* *@
|
||||
@* @{ *@
|
||||
@* ViewData["Title"] = "Create"; *@
|
||||
@* } *@
|
||||
@* *@
|
||||
@* <h1>Create</h1> *@
|
||||
@* *@
|
||||
@* <h4>Company logo</h4> *@
|
||||
@* <hr /> *@
|
||||
@* <div class="row"> *@
|
||||
@* <div class="col-md-4"> *@
|
||||
@* <form asp-action="Create"> *@
|
||||
@* <div asp-validation-summary="ModelOnly" class="text-danger"></div> *@
|
||||
@* <div class="form-group"> *@
|
||||
@* <label asp-for="CompanyId" class="control-label"></label> *@
|
||||
@* <select asp-for="CompanyId" class ="form-control" asp-items="ViewBag.CompanyId"></select> *@
|
||||
@* </div> *@
|
||||
@* <div class="form-group"> *@
|
||||
@* <label asp-for="Year" class="control-label"></label> *@
|
||||
@* <input asp-for="Year" class="form-control" /> *@
|
||||
@* <span asp-validation-for="Year" class="text-danger"></span> *@
|
||||
@* </div> *@
|
||||
@* <div class="form-group"> *@
|
||||
@* <label asp-for="Guid" class="control-label"></label> *@
|
||||
@* <input asp-for="Guid" class="form-control" /> *@
|
||||
@* <span asp-validation-for="Guid" 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> *@
|
||||
@* *@
|
||||
43
cicm_web/Areas/Admin/Views/CompanyLogos/Delete.cshtml
Normal file
43
cicm_web/Areas/Admin/Views/CompanyLogos/Delete.cshtml
Normal file
@@ -0,0 +1,43 @@
|
||||
@model Cicm.Database.Models.CompanyLogo
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Delete";
|
||||
}
|
||||
|
||||
<h1>Delete</h1>
|
||||
|
||||
<h3>Are you sure you want to delete this?</h3>
|
||||
<div>
|
||||
<h4>Company logo</h4>
|
||||
<hr />
|
||||
<dl class="row">
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.Company)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.Company.Name)
|
||||
</dd>
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.Year)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.Year)
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<form asp-action="Delete">
|
||||
<input type="hidden"
|
||||
asp-for="Id" />
|
||||
<input type="hidden"
|
||||
asp-for="CompanyId" />
|
||||
<input type="hidden"
|
||||
asp-for="Guid" />
|
||||
<input class="btn btn-danger"
|
||||
type="submit"
|
||||
value="Delete" />
|
||||
<a asp-action="Index"
|
||||
class="btn btn-secondary">
|
||||
Back to List
|
||||
</a>
|
||||
</form>
|
||||
</div>
|
||||
37
cicm_web/Areas/Admin/Views/CompanyLogos/Details.cshtml
Normal file
37
cicm_web/Areas/Admin/Views/CompanyLogos/Details.cshtml
Normal file
@@ -0,0 +1,37 @@
|
||||
@model Cicm.Database.Models.CompanyLogo
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Details";
|
||||
}
|
||||
|
||||
<h1>Details</h1>
|
||||
|
||||
<div>
|
||||
<h4>Company logo</h4>
|
||||
<hr />
|
||||
<dl class="row">
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.Company)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.Company.Name)
|
||||
</dd>
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.Year)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.Year)
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<a asp-action="Edit"
|
||||
asp-route-id="@Model.Id"
|
||||
class="btn btn-primary">
|
||||
Edit
|
||||
</a>
|
||||
<a asp-action="Index"
|
||||
class="btn btn-secondary">
|
||||
Back to List
|
||||
</a>
|
||||
</div>
|
||||
60
cicm_web/Areas/Admin/Views/CompanyLogos/Edit.cshtml
Normal file
60
cicm_web/Areas/Admin/Views/CompanyLogos/Edit.cshtml
Normal file
@@ -0,0 +1,60 @@
|
||||
@model Cicm.Database.Models.CompanyLogo
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Edit";
|
||||
}
|
||||
|
||||
<h1>Edit</h1>
|
||||
|
||||
<h4>Company logo</h4>
|
||||
<hr />
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<form asp-action="Edit">
|
||||
<div asp-validation-summary="ModelOnly"
|
||||
class="text-danger">
|
||||
</div>
|
||||
<input type="hidden"
|
||||
asp-for="Id" />
|
||||
<div class="form-group">
|
||||
<label asp-for="Company"
|
||||
class="control-label">
|
||||
</label>
|
||||
<select asp-for="CompanyId"
|
||||
class="form-control"
|
||||
asp-items="ViewBag.CompanyId">
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Year"
|
||||
class="control-label">
|
||||
</label>
|
||||
<input asp-for="Year"
|
||||
class="form-control" />
|
||||
<span asp-validation-for="Year"
|
||||
class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Guid"
|
||||
class="control-label">
|
||||
</label>
|
||||
<input asp-for="Guid"
|
||||
class="form-control"
|
||||
readonly />
|
||||
<span asp-validation-for="Guid"
|
||||
class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input class="btn btn-primary"
|
||||
type="submit"
|
||||
value="Save" />
|
||||
<a asp-action="Index"
|
||||
class="btn btn-secondary">
|
||||
Back to List
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
59
cicm_web/Areas/Admin/Views/CompanyLogos/Index.cshtml
Normal file
59
cicm_web/Areas/Admin/Views/CompanyLogos/Index.cshtml
Normal file
@@ -0,0 +1,59 @@
|
||||
@using Cicm.Database.Models
|
||||
@model IEnumerable<Cicm.Database.Models.CompanyLogo>
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Index";
|
||||
}
|
||||
|
||||
<h1>Company logos</h1>
|
||||
|
||||
<p>
|
||||
<a aria-disabled="True"
|
||||
asp-action="Create"
|
||||
class="btn btn-primary disabled">
|
||||
Create New
|
||||
</a>
|
||||
</p>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Company)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Year)
|
||||
</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach(CompanyLogo item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Company.Name)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Year)
|
||||
</td>
|
||||
<td>
|
||||
<a asp-action="Details"
|
||||
asp-route-id="@item.Id"
|
||||
class="btn btn-primary">
|
||||
Details
|
||||
</a>
|
||||
<a asp-action="Edit"
|
||||
asp-route-id="@item.Id"
|
||||
class="btn btn-secondary">
|
||||
Edit
|
||||
</a>
|
||||
<a asp-action="Delete"
|
||||
asp-route-id="@item.Id"
|
||||
class="btn btn-danger">
|
||||
Delete
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -39,6 +39,7 @@
|
||||
<a asp-controller="BrowserTests">Browser tests</a><br />
|
||||
<a asp-controller="Companies">Companies</a><br />
|
||||
<a asp-controller="CompanyDescriptions">Company descriptions</a><br />
|
||||
<a asp-controller="CompanyLogos">Company logos</a><br />
|
||||
<a asp-controller="Gpus">GPUs</a><br />
|
||||
<a asp-controller="GpusByMachine">GPUs by machine</a><br />
|
||||
<a asp-controller="InstructionSets">Instruction sets</a><br />
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<Version>3.0.99.458</Version>
|
||||
<Version>3.0.99.462</Version>
|
||||
<Company>Canary Islands Computer Museum</Company>
|
||||
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
|
||||
<Product>Canary Islands Computer Museum Website</Product>
|
||||
|
||||
Reference in New Issue
Block a user