diff --git a/cicm_web/Controllers/CompanyController.cs b/cicm_web/Controllers/CompanyController.cs index b696933d..99aedd8a 100644 --- a/cicm_web/Controllers/CompanyController.cs +++ b/cicm_web/Controllers/CompanyController.cs @@ -28,21 +28,23 @@ // Copyright © 2003-2018 Natalia Portillo *******************************************************************************/ -using cicm_web.Models; -using Cicm.Database.Schemas; +using System.Linq; +using Cicm.Database.Models; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; -using Company = cicm_web.Models.Company; +using Microsoft.EntityFrameworkCore; namespace cicm_web.Controllers { public class CompanyController : Controller { + readonly cicmContext _context; readonly IHostingEnvironment hostingEnvironment; - public CompanyController(IHostingEnvironment env) + public CompanyController(IHostingEnvironment env, cicmContext context) { hostingEnvironment = env; + _context = context; } public IActionResult ByLetter(char id) @@ -54,36 +56,40 @@ namespace cicm_web.Controllers ViewBag.Letter = id; - Company[] companies = id == '\0' ? Company.GetAllItems() : Company.GetItemsStartingWithLetter(id); - ViewBag.WebRootPath = hostingEnvironment.WebRootPath; - return View(companies); + return View(id == '\0' + ? _context.Companies.ToArray() + : _context.Companies.Where(c => c.Name.StartsWith(id)).ToArray()); } public IActionResult View(int id) { - CompanyWithItems company = CompanyWithItems.GetItem(id); - ViewBag.WebRootPath = hostingEnvironment.WebRootPath; + Companies company = _context.Companies.Where(c => c.Id == id).Include(c => c.Description) + .Include(c => c.Machines).Include(c => c.Country).FirstOrDefault(); + + if(company == null) return Index(); + + ViewBag.LastLogo = company.CompanyLogos.OrderByDescending(l => l.Year).FirstOrDefault(); + ViewBag.CompanyLogos = company.CompanyLogos.OrderByDescending(l => l.Year).ToList(); + return View(company); } public IActionResult ByCountry(short id) { - Iso3166 iso3166 = Program.Database.Operations.GetIso3166(id); - - ViewBag.Iso3166 = iso3166; - - Company[] companies = iso3166 == null ? Company.GetAllItems() : Company.GetItemsByCountry(id); + ViewBag.Iso3166 = _context.Iso31661Numeric.FirstOrDefault(i => i.Id == id); ViewBag.WebRootPath = hostingEnvironment.WebRootPath; - return View(companies); + return View(ViewBag.Iso3166 == null + ? _context.Companies.ToArray() + : _context.Companies.Where(c => c.CountryId == id).ToArray()); } public IActionResult Index() { ViewBag.WebRootPath = hostingEnvironment.WebRootPath; - return View(Company.GetAllItems()); + return View(_context.Companies.ToArray()); } } } \ No newline at end of file diff --git a/cicm_web/Models/Company.cs b/cicm_web/Models/Company.cs index b2b36636..df016596 100644 --- a/cicm_web/Models/Company.cs +++ b/cicm_web/Models/Company.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Cicm.Database; using Cicm.Database.Schemas; using Markdig; diff --git a/cicm_web/Models/Machine.cs b/cicm_web/Models/Machine.cs index 144b3a94..144e7b1d 100644 --- a/cicm_web/Models/Machine.cs +++ b/cicm_web/Models/Machine.cs @@ -31,7 +31,7 @@ using System; using System.Collections.Generic; using System.Linq; -using Cicm.Database.Schemas; +using Cicm.Database; namespace cicm_web.Models { diff --git a/cicm_web/Models/MemoryByMachine.cs b/cicm_web/Models/MemoryByMachine.cs index de2d87b7..747e7dc1 100644 --- a/cicm_web/Models/MemoryByMachine.cs +++ b/cicm_web/Models/MemoryByMachine.cs @@ -29,16 +29,16 @@ *******************************************************************************/ using System.Collections.Generic; -using Cicm.Database.Schemas; +using Cicm.Database; namespace cicm_web.Models { public class MemoryByMachine { - public MemoryType Type; + public long Size; + public double Speed; + public MemoryType Type; public MemoryUsage Usage; - public long Size; - public double Speed; public static MemoryByMachine[] GetAllItems(int machineId) { @@ -52,10 +52,10 @@ namespace cicm_web.Models foreach(Cicm.Database.Schemas.MemoryByMachine dbItem in dbItems) items.Add(new MemoryByMachine { - Type =dbItem.Type, - Usage =dbItem.Usage, - Size =dbItem.Size, - Speed =dbItem.Speed + Type = dbItem.Type, + Usage = dbItem.Usage, + Size = dbItem.Size, + Speed = dbItem.Speed }); return items.ToArray(); diff --git a/cicm_web/Models/News.cs b/cicm_web/Models/News.cs index 55ca828b..398f3d9d 100644 --- a/cicm_web/Models/News.cs +++ b/cicm_web/Models/News.cs @@ -32,7 +32,7 @@ using System; using System.Collections.Generic; using System.Globalization; using System.Linq; -using Cicm.Database.Schemas; +using Cicm.Database; namespace cicm_web.Models { diff --git a/cicm_web/Models/OwnedComputer.cs b/cicm_web/Models/OwnedComputer.cs index 7ed7d008..fbaf520d 100644 --- a/cicm_web/Models/OwnedComputer.cs +++ b/cicm_web/Models/OwnedComputer.cs @@ -32,7 +32,7 @@ using System; using System.Collections.Generic; using System.Globalization; using System.Linq; -using Cicm.Database.Schemas; +using Cicm.Database; namespace cicm_web.Models { diff --git a/cicm_web/Models/OwnedConsole.cs b/cicm_web/Models/OwnedConsole.cs index 3b281437..20eea90f 100644 --- a/cicm_web/Models/OwnedConsole.cs +++ b/cicm_web/Models/OwnedConsole.cs @@ -32,7 +32,7 @@ using System; using System.Collections.Generic; using System.Globalization; using System.Linq; -using Cicm.Database.Schemas; +using Cicm.Database; namespace cicm_web.Models { diff --git a/cicm_web/Models/StorageByMachine.cs b/cicm_web/Models/StorageByMachine.cs index 39070459..9a5e9924 100644 --- a/cicm_web/Models/StorageByMachine.cs +++ b/cicm_web/Models/StorageByMachine.cs @@ -29,7 +29,7 @@ *******************************************************************************/ using System.Collections.Generic; -using Cicm.Database.Schemas; +using Cicm.Database; namespace cicm_web.Models { diff --git a/cicm_web/Views/Company/ByCountry.cshtml b/cicm_web/Views/Company/ByCountry.cshtml index dacee866..9c6a0341 100644 --- a/cicm_web/Views/Company/ByCountry.cshtml +++ b/cicm_web/Views/Company/ByCountry.cshtml @@ -32,9 +32,10 @@ ViewData["Title"] = "Companies"; } @using System.IO -@model IEnumerable +@using Cicm.Database.Models +@model Cicm.Database.Models.Companies[] -

+

@if(ViewBag.Iso3166 != null) { Companies founded in @ViewBag.Iso3166.Name @@ -62,11 +63,12 @@ {

@Model.Count() companies found in the database.
- @foreach(Company company in Model) + @foreach(Companies company in Model) { + @* TODO @if(company.LastLogo != null && File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/logos", company.LastLogo.Guid + ".svg"))) { @@ -86,6 +88,7 @@ style="max-height: 32px; max-width: 128px" /> } + *@ @company.Name
diff --git a/cicm_web/Views/Company/ByLetter.cshtml b/cicm_web/Views/Company/ByLetter.cshtml index 4f88035a..b8c696ec 100644 --- a/cicm_web/Views/Company/ByLetter.cshtml +++ b/cicm_web/Views/Company/ByLetter.cshtml @@ -31,11 +31,11 @@ ViewData["Title"] = "Companies"; } -@using System.IO -@model IEnumerable +@using Cicm.Database.Models +@model Cicm.Database.Models.Companies[]

Search results:

-

+

@if(ViewBag.Letter != '\0') { @ViewBag.Letter @@ -46,11 +46,12 @@ {

@Model.Count() companies found in the database.
- @foreach(Company company in Model) + @foreach(Companies company in Model) { + @* @if(company.LastLogo != null && File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/logos", company.LastLogo.Guid + ".svg"))) { @@ -70,6 +71,7 @@ style="max-height: 32px; max-width: 128px" /> } + *@ @company.Name
diff --git a/cicm_web/Views/Company/Index.cshtml b/cicm_web/Views/Company/Index.cshtml index 56d5c0c7..f0f2745b 100644 --- a/cicm_web/Views/Company/Index.cshtml +++ b/cicm_web/Views/Company/Index.cshtml @@ -31,19 +31,20 @@ ViewData["Title"] = "Companies"; } -@using System.IO -@model IEnumerable +@using Cicm.Database.Models +@model Cicm.Database.Models.Companies[] -

+

@if(Model.Any()) {

@Model.Count() companies found in the database.
- @foreach(Company company in Model) + @foreach(Companies company in Model) { + @* TODO @if(company.LastLogo != null && File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/logos", company.LastLogo.Guid + ".svg"))) { @@ -58,10 +59,13 @@ /assets/logos/thumbs/png/1x/@(company.LastLogo.Guid).webp 3x" src="/assets/logos/thumbs/png/1x@(company.LastLogo.Guid).png") alt="" - height="auto" width="auto" style="max-height: 32px; max-width: 128px "/> + height="auto" + width="auto" + style="max-height: 32px; max-width: 128px" /> } + *@ @company.Name
diff --git a/cicm_web/Views/Company/View.cshtml b/cicm_web/Views/Company/View.cshtml index f1476e06..f7afba33 100644 --- a/cicm_web/Views/Company/View.cshtml +++ b/cicm_web/Views/Company/View.cshtml @@ -32,26 +32,27 @@ ViewData["Title"] = "Companies"; } @using System.IO -@using Cicm.Database.Schemas -@model CompanyWithItems +@using Cicm.Database +@using Cicm.Database.Models +@model Cicm.Database.Models.Companies @if(Model != null) {

- @if(Model.LastLogo != null && File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/logos", Model.LastLogo.Guid + ".svg"))) + @if(ViewBag.LastLogo != null && File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/logos", ViewBag.LastLogo.Guid + ".svg"))) { + srcset="/assets/logos/@(ViewBag.LastLogo.Guid).svg"> - + 1) + @if(ViewBag.Logos != null && ViewBag.Logos.Length > 1) {