diff --git a/cicm_web/Controllers/ComputerController.cs b/cicm_web/Controllers/ComputerController.cs
index 39d8641c..5ea14579 100644
--- a/cicm_web/Controllers/ComputerController.cs
+++ b/cicm_web/Controllers/ComputerController.cs
@@ -1,7 +1,8 @@
using System.Collections.Generic;
using System.Linq;
-using Cicm.Database.Schemas;
+using cicm_web.Models;
using Microsoft.AspNetCore.Mvc;
+using Computer = Cicm.Database.Schemas.Computer;
namespace cicm_web.Controllers
{
@@ -18,5 +19,20 @@ namespace cicm_web.Controllers
return View();
}
+
+ public IActionResult ByLetter(char id)
+ {
+ // ToUpper()
+ if(id >= 'a' && id <= 'z') id -= (char)32;
+ // Check if not letter
+ if(id < 'A' || id > 'Z') id = '\0';
+
+ ViewBag.Letter = id;
+
+ ComputerMini[] computers =
+ id == '\0' ? ComputerMini.GetAllItems() : ComputerMini.GetItemsStartingWithLetter(id);
+
+ return View(computers);
+ }
}
}
\ No newline at end of file
diff --git a/cicm_web/Models/Computer.cs b/cicm_web/Models/Computer.cs
index a21d41ae..64069aeb 100644
--- a/cicm_web/Models/Computer.cs
+++ b/cicm_web/Models/Computer.cs
@@ -28,6 +28,7 @@
// Copyright © 2003-2018 Natalia Portillo
*******************************************************************************/
+using System;
using System.Collections.Generic;
using System.Linq;
@@ -69,7 +70,7 @@ namespace cicm_web.Models
bool? result = Program.Database?.Operations.GetComputers(out dbItems);
if(result == null || result.Value == false || dbItems == null) return null;
- return dbItems.OrderByDescending(i => i.Id).Select(TransformItem) as Computer[];
+ return dbItems.Select(TransformItem) as Computer[];
}
public static Computer[] GetItemsFromCompany(int id)
@@ -78,7 +79,7 @@ namespace cicm_web.Models
bool? result = Program.Database?.Operations.GetComputers(out dbItems, id);
if(result == null || result.Value == false || dbItems == null) return null;
- return dbItems.OrderByDescending(i => i.Id).Select(TransformItem) as Computer[];
+ return dbItems.Select(TransformItem) as Computer[];
}
public static Computer GetItem(int id)
@@ -147,4 +148,44 @@ namespace cicm_web.Models
return item;
}
}
+
+ public class ComputerMini
+ {
+ public Company Company;
+ public int Id;
+ public string Model;
+
+ public static ComputerMini[] GetAllItems()
+ {
+ List Search results:
+ @if(ViewBag.Letter != '\0')
+ {
+ @ViewBag.Letter @Model.Count() computers found in the database. There are no computers found in the database that start with this letter.
+ }
+
+ @if(Model.Any())
+ {
+
+ @foreach(ComputerMini computer in @Model)
+ {
+ @computer.Company.Name @computer.Model
+ }
+