2018-04-13 17:53:12 +01:00
|
|
|
|
/******************************************************************************
|
|
|
|
|
|
// Canary Islands Computer Museum Website
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : Console.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Videogame console model
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
|
// it under the terms of the GNU General Public License as
|
|
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
|
//
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
//
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
// Copyright © 2003-2018 Natalia Portillo
|
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
2018-04-15 02:31:23 +01:00
|
|
|
|
using System;
|
2018-04-13 17:53:12 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
|
|
namespace cicm_web.Models
|
|
|
|
|
|
{
|
2018-04-28 02:10:03 +01:00
|
|
|
|
public static class Console
|
2018-04-13 17:53:12 +01:00
|
|
|
|
{
|
2018-04-28 02:10:03 +01:00
|
|
|
|
public static Machine[] GetAllItems()
|
2018-04-13 17:53:12 +01:00
|
|
|
|
{
|
2018-04-28 02:10:03 +01:00
|
|
|
|
List<Cicm.Database.Schemas.Machine> dbItems = null;
|
2018-04-13 17:53:12 +01:00
|
|
|
|
bool? result = Program.Database?.Operations.GetConsoles(out dbItems);
|
|
|
|
|
|
if(result == null || result.Value == false || dbItems == null) return null;
|
|
|
|
|
|
|
2018-04-28 02:10:03 +01:00
|
|
|
|
return dbItems.OrderByDescending(i => i.Id).Select(Machine.TransformItem) as Machine[];
|
2018-04-13 17:53:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-28 02:10:03 +01:00
|
|
|
|
public static Machine[] GetItemsFromCompany(int id)
|
2018-04-13 17:53:12 +01:00
|
|
|
|
{
|
2018-04-28 02:10:03 +01:00
|
|
|
|
List<Cicm.Database.Schemas.Machine> dbItems = null;
|
2018-04-15 17:51:07 +01:00
|
|
|
|
bool? result = Program.Database?.Operations.GetConsoles(out dbItems);
|
2018-04-13 17:53:12 +01:00
|
|
|
|
if(result == null || result.Value == false || dbItems == null) return null;
|
|
|
|
|
|
|
2018-04-15 02:31:23 +01:00
|
|
|
|
// TODO: Company chosen by DB
|
2018-04-29 02:02:33 +01:00
|
|
|
|
return dbItems.Where(t => t.Company == id).Select(Machine.TransformItem).OrderBy(t => t.Name).ToArray();
|
2018-04-13 17:53:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-28 02:10:03 +01:00
|
|
|
|
public static Machine GetItem(int id)
|
2018-04-13 17:53:12 +01:00
|
|
|
|
{
|
2018-04-28 02:10:03 +01:00
|
|
|
|
Cicm.Database.Schemas.Machine dbItem = Program.Database?.Operations.GetConsole(id);
|
|
|
|
|
|
return dbItem == null ? null : Machine.TransformItem(dbItem);
|
2018-04-13 17:53:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-04-15 02:31:23 +01:00
|
|
|
|
|
2018-04-28 02:10:03 +01:00
|
|
|
|
public static class ConsoleMini
|
2018-04-15 02:31:23 +01:00
|
|
|
|
{
|
2018-04-28 02:10:03 +01:00
|
|
|
|
public static MachineMini[] GetAllItems()
|
2018-04-15 02:31:23 +01:00
|
|
|
|
{
|
2018-04-28 02:10:03 +01:00
|
|
|
|
List<Cicm.Database.Schemas.Machine> dbItems = null;
|
2018-04-15 17:51:07 +01:00
|
|
|
|
bool? result = Program.Database?.Operations.GetConsoles(out dbItems);
|
2018-04-15 02:31:23 +01:00
|
|
|
|
|
|
|
|
|
|
if(result == null || result.Value == false || dbItems == null) return null;
|
|
|
|
|
|
|
2018-04-28 02:10:03 +01:00
|
|
|
|
List<MachineMini> items = new List<MachineMini>();
|
|
|
|
|
|
foreach(Cicm.Database.Schemas.Machine dbItem in dbItems) items.Add(MachineMini.TransformItem(dbItem));
|
2018-04-15 02:31:23 +01:00
|
|
|
|
|
2018-04-29 02:02:33 +01:00
|
|
|
|
return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Name).ToArray();
|
2018-04-15 02:31:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-28 02:10:03 +01:00
|
|
|
|
public static MachineMini[] GetItemsStartingWithLetter(char letter)
|
2018-04-15 02:31:23 +01:00
|
|
|
|
{
|
2018-04-28 02:10:03 +01:00
|
|
|
|
List<Cicm.Database.Schemas.Machine> dbItems = null;
|
2018-04-15 17:51:07 +01:00
|
|
|
|
bool? result = Program.Database?.Operations.GetConsoles(out dbItems);
|
2018-04-15 02:31:23 +01:00
|
|
|
|
if(result == null || result.Value == false || dbItems == null) return null;
|
|
|
|
|
|
|
2018-04-28 02:10:03 +01:00
|
|
|
|
List<MachineMini> items = new List<MachineMini>();
|
|
|
|
|
|
foreach(Cicm.Database.Schemas.Machine dbItem in dbItems)
|
2018-04-29 02:02:33 +01:00
|
|
|
|
if(dbItem.Name.StartsWith(new string(letter, 1), StringComparison.InvariantCultureIgnoreCase))
|
2018-04-28 02:10:03 +01:00
|
|
|
|
items.Add(MachineMini.TransformItem(dbItem));
|
2018-04-15 02:31:23 +01:00
|
|
|
|
|
2018-04-29 02:02:33 +01:00
|
|
|
|
return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Name).ToArray();
|
2018-04-15 02:31:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-28 02:10:03 +01:00
|
|
|
|
public static MachineMini[] GetItemsFromYear(int year)
|
2018-04-15 02:31:23 +01:00
|
|
|
|
{
|
2018-04-28 02:10:03 +01:00
|
|
|
|
List<Cicm.Database.Schemas.Machine> dbItems = null;
|
2018-04-15 17:51:07 +01:00
|
|
|
|
bool? result = Program.Database?.Operations.GetConsoles(out dbItems);
|
2018-04-15 02:31:23 +01:00
|
|
|
|
if(result == null || result.Value == false || dbItems == null) return null;
|
|
|
|
|
|
|
2018-04-28 02:10:03 +01:00
|
|
|
|
List<MachineMini> items = new List<MachineMini>();
|
|
|
|
|
|
foreach(Cicm.Database.Schemas.Machine dbItem in dbItems)
|
2018-04-28 21:29:01 +01:00
|
|
|
|
if(dbItem.Introduced.Year == year)
|
2018-04-28 02:10:03 +01:00
|
|
|
|
items.Add(MachineMini.TransformItem(dbItem));
|
2018-04-15 02:31:23 +01:00
|
|
|
|
|
2018-04-29 02:02:33 +01:00
|
|
|
|
return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Name).ToArray();
|
2018-04-15 17:51:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-28 02:10:03 +01:00
|
|
|
|
public static MachineMini[] GetItemsWithCompany(int id, string companyName)
|
2018-04-15 17:51:07 +01:00
|
|
|
|
{
|
2018-04-28 02:10:03 +01:00
|
|
|
|
List<Cicm.Database.Schemas.Machine> dbItems = null;
|
2018-04-15 17:51:07 +01:00
|
|
|
|
bool? result = Program.Database?.Operations.GetConsoles(out dbItems);
|
|
|
|
|
|
if(result == null || result.Value == false || dbItems == null) return null;
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Company chosen by DB
|
|
|
|
|
|
return dbItems.Where(t => t.Company == id)
|
2018-04-28 02:10:03 +01:00
|
|
|
|
.Select(t => new MachineMini
|
2018-04-15 17:51:07 +01:00
|
|
|
|
{
|
|
|
|
|
|
Company = new Company {Id = id, Name = companyName},
|
|
|
|
|
|
Id = t.Id,
|
2018-04-29 02:02:33 +01:00
|
|
|
|
Name = t.Name
|
|
|
|
|
|
}).OrderBy(t => t.Name).ToArray();
|
2018-04-15 17:51:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-28 02:10:03 +01:00
|
|
|
|
public static MachineMini[] GetItemsFromCompany(int id)
|
2018-04-15 17:51:07 +01:00
|
|
|
|
{
|
2018-04-28 02:10:03 +01:00
|
|
|
|
List<Cicm.Database.Schemas.Machine> dbItems = null;
|
2018-04-15 17:51:07 +01:00
|
|
|
|
bool? result = Program.Database?.Operations.GetConsoles(out dbItems);
|
|
|
|
|
|
if(result == null || result.Value == false || dbItems == null) return null;
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Company chosen by DB
|
2018-04-29 02:02:33 +01:00
|
|
|
|
return dbItems.Where(t => t.Company == id).Select(MachineMini.TransformItem).OrderBy(t => t.Name).ToArray();
|
2018-04-15 02:31:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-04-13 17:53:12 +01:00
|
|
|
|
}
|