diff --git a/cicm_web/Areas/Admin/Controllers/CompanyLogosController.cs b/cicm_web/Areas/Admin/Controllers/CompanyLogosController.cs new file mode 100644 index 00000000..18bfdc01 --- /dev/null +++ b/cicm_web/Areas/Admin/Controllers/CompanyLogosController.cs @@ -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 Index() + { + IIncludableQueryable 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 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 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 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 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 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 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); + } + } +} \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/CompanyLogos/Create.cshtml b/cicm_web/Areas/Admin/Views/CompanyLogos/Create.cshtml new file mode 100644 index 00000000..984c342e --- /dev/null +++ b/cicm_web/Areas/Admin/Views/CompanyLogos/Create.cshtml @@ -0,0 +1,41 @@ +@* @model Cicm.Database.Models.CompanyLogo *@ +@* *@ +@* @{ *@ +@* ViewData["Title"] = "Create"; *@ +@* } *@ +@* *@ +@*

Create

*@ +@* *@ +@*

Company logo

*@ +@*
*@ +@*
*@ +@*
*@ +@*
*@ +@*
*@ +@*
*@ +@* *@ +@* *@ +@*
*@ +@*
*@ +@* *@ +@* *@ +@* *@ +@*
*@ +@*
*@ +@* *@ +@* *@ +@* *@ +@*
*@ +@*
*@ +@* *@ +@* *@ +@* Back to List *@ +@* *@ +@*
*@ +@*
*@ +@*
*@ +@*
*@ +@* *@ \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/CompanyLogos/Delete.cshtml b/cicm_web/Areas/Admin/Views/CompanyLogos/Delete.cshtml new file mode 100644 index 00000000..7c8afe53 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/CompanyLogos/Delete.cshtml @@ -0,0 +1,43 @@ +@model Cicm.Database.Models.CompanyLogo + +@{ + ViewData["Title"] = "Delete"; +} + +

Delete

+ +

Are you sure you want to delete this?

+
+

Company logo

+
+
+
+ @Html.DisplayNameFor(model => model.Company) +
+
+ @Html.DisplayFor(model => model.Company.Name) +
+
+ @Html.DisplayNameFor(model => model.Year) +
+
+ @Html.DisplayFor(model => model.Year) +
+
+ +
+ + + + + + Back to List + +
+
\ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/CompanyLogos/Details.cshtml b/cicm_web/Areas/Admin/Views/CompanyLogos/Details.cshtml new file mode 100644 index 00000000..9ac299b8 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/CompanyLogos/Details.cshtml @@ -0,0 +1,37 @@ +@model Cicm.Database.Models.CompanyLogo + +@{ + ViewData["Title"] = "Details"; +} + +

Details

+ +
+

Company logo

+
+
+
+ @Html.DisplayNameFor(model => model.Company) +
+
+ @Html.DisplayFor(model => model.Company.Name) +
+
+ @Html.DisplayNameFor(model => model.Year) +
+
+ @Html.DisplayFor(model => model.Year) +
+
+
+ \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/CompanyLogos/Edit.cshtml b/cicm_web/Areas/Admin/Views/CompanyLogos/Edit.cshtml new file mode 100644 index 00000000..8c11c577 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/CompanyLogos/Edit.cshtml @@ -0,0 +1,60 @@ +@model Cicm.Database.Models.CompanyLogo + +@{ + ViewData["Title"] = "Edit"; +} + +

Edit

+ +

Company logo

+
+
+
+
+
+
+ +
+ + +
+
+ + + + +
+
+ + + + +
+ +
+
+
\ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/CompanyLogos/Index.cshtml b/cicm_web/Areas/Admin/Views/CompanyLogos/Index.cshtml new file mode 100644 index 00000000..d14ca030 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/CompanyLogos/Index.cshtml @@ -0,0 +1,59 @@ +@using Cicm.Database.Models +@model IEnumerable + +@{ + ViewData["Title"] = "Index"; +} + +

Company logos

+ +

+ + Create New + +

+ + + + + + + + + + @foreach(CompanyLogo item in Model) + { + + + + + + } + +
+ @Html.DisplayNameFor(model => model.Company) + + @Html.DisplayNameFor(model => model.Year) +
+ @Html.DisplayFor(modelItem => item.Company.Name) + + @Html.DisplayFor(modelItem => item.Year) + + + Details + + + Edit + + + Delete + +
\ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/Home/Index.cshtml b/cicm_web/Areas/Admin/Views/Home/Index.cshtml index 16311d15..9406e859 100644 --- a/cicm_web/Areas/Admin/Views/Home/Index.cshtml +++ b/cicm_web/Areas/Admin/Views/Home/Index.cshtml @@ -39,6 +39,7 @@ Browser tests
Companies
Company descriptions
+ Company logos
GPUs
GPUs by machine
Instruction sets
diff --git a/cicm_web/cicm_web.csproj b/cicm_web/cicm_web.csproj index 4c63d968..2402e898 100644 --- a/cicm_web/cicm_web.csproj +++ b/cicm_web/cicm_web.csproj @@ -2,7 +2,7 @@ netcoreapp2.2 - 3.0.99.458 + 3.0.99.462 Canary Islands Computer Museum Copyright © 2003-2018 Natalia Portillo Canary Islands Computer Museum Website