Update DB to version 13: Add fields to sound_synths and drop music_synths.

This commit is contained in:
2018-04-27 17:55:04 +01:00
parent 56f54288eb
commit 53e924055a
8 changed files with 305 additions and 343 deletions

View File

@@ -1,276 +0,0 @@
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : MusicSynth.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Contains operations to manage music synthetizer.
//
// --[ 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
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Data;
using Cicm.Database.Schemas;
using Console = System.Console;
namespace Cicm.Database
{
public partial class Operations
{
/// <summary>
/// Gets all music synthetizers
/// </summary>
/// <param name="entries">All music synthetizers</param>
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
public bool GetMusicSynths(out List<MusicSynth> entries)
{
#if DEBUG
Console.WriteLine("Getting all music synthetizers...");
#endif
try
{
const string SQL = "SELECT * from music_synths";
IDbCommand dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = SQL;
DataSet dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
entries = MusicSynthFromDataTable(dataSet.Tables[0]);
return true;
}
catch(Exception ex)
{
Console.WriteLine("Error getting music synthetizers.");
Console.WriteLine(ex);
entries = null;
return false;
}
}
/// <summary>
/// Gets the specified number of music synthetizers since the specified start
/// </summary>
/// <param name="entries">List of music synthetizers</param>
/// <param name="start">Start of query</param>
/// <param name="count">How many entries to retrieve</param>
/// <returns><c>true</c> if <see cref="entries" /> is correct, <c>false</c> otherwise</returns>
public bool GetMusicSynths(out List<MusicSynth> entries, ulong start, ulong count)
{
#if DEBUG
Console.WriteLine("Getting {0} music synthetizers from {1}...", count, start);
#endif
try
{
string sql = $"SELECT * FROM music_synths LIMIT {start}, {count}";
IDbCommand dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = sql;
DataSet dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
entries = MusicSynthFromDataTable(dataSet.Tables[0]);
return true;
}
catch(Exception ex)
{
Console.WriteLine("Error getting music synthetizers.");
Console.WriteLine(ex);
entries = null;
return false;
}
}
/// <summary>
/// Gets music synthetizer by specified id
/// </summary>
/// <param name="id">Id</param>
/// <returns>music synthetizer with specified id, <c>null</c> if not found or error</returns>
public MusicSynth GetMusicSynth(int id)
{
#if DEBUG
Console.WriteLine("Getting music synthetizer with id {0}...", id);
#endif
try
{
string sql = $"SELECT * from music_synths WHERE id = '{id}'";
IDbCommand dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = sql;
DataSet dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
List<MusicSynth> entries = MusicSynthFromDataTable(dataSet.Tables[0]);
return entries == null || entries.Count == 0 ? null : entries[0];
}
catch(Exception ex)
{
Console.WriteLine("Error getting music synthetizer.");
Console.WriteLine(ex);
return null;
}
}
/// <summary>
/// Counts the number of music synthetizers in the database
/// </summary>
/// <returns>Entries in database</returns>
public long CountMusicSynths()
{
#if DEBUG
Console.WriteLine("Counting mpus...");
#endif
IDbCommand dbcmd = dbCon.CreateCommand();
dbcmd.CommandText = "SELECT COUNT(*) FROM music_synths";
object count = dbcmd.ExecuteScalar();
dbcmd.Dispose();
try { return Convert.ToInt64(count); }
catch { return 0; }
}
/// <summary>
/// Adds a new music synthetizer to the database
/// </summary>
/// <param name="entry">Entry to add</param>
/// <param name="id">ID of added entry</param>
/// <returns><c>true</c> if added correctly, <c>false</c> otherwise</returns>
public bool AddMusicSynth(MusicSynth entry, out long id)
{
#if DEBUG
Console.Write("Adding music synthetizer `{0}`...", entry.Name);
#endif
IDbCommand dbcmd = GetCommandMusicSynth(entry);
IDbTransaction trans = dbCon.BeginTransaction();
dbcmd.Transaction = trans;
const string SQL = "INSERT INTO music_synths (name)" + " VALUES (@name)";
dbcmd.CommandText = SQL;
dbcmd.ExecuteNonQuery();
trans.Commit();
dbcmd.Dispose();
id = dbCore.LastInsertRowId;
#if DEBUG
Console.WriteLine(" id {0}", id);
#endif
return true;
}
/// <summary>
/// Updated an music synthetizer in the database
/// </summary>
/// <param name="entry">Updated entry</param>
/// <returns><c>true</c> if updated correctly, <c>false</c> otherwise</returns>
public bool UpdateMusicSynth(MusicSynth entry)
{
#if DEBUG
Console.WriteLine("Updating music synthetizer `{0}`...", entry.Name);
#endif
IDbCommand dbcmd = GetCommandMusicSynth(entry);
IDbTransaction trans = dbCon.BeginTransaction();
dbcmd.Transaction = trans;
string sql = "UPDATE music_synths SET name = @name " + $"WHERE id = {entry.Id}";
dbcmd.CommandText = sql;
dbcmd.ExecuteNonQuery();
trans.Commit();
dbcmd.Dispose();
return true;
}
public bool RemoveMusicSynth(long id)
{
#if DEBUG
Console.WriteLine("Removing music synthetizer widh id `{0}`...", id);
#endif
IDbCommand dbcmd = dbCon.CreateCommand();
IDbTransaction trans = dbCon.BeginTransaction();
dbcmd.Transaction = trans;
string sql = $"DELETE FROM music_synths WHERE id = '{id}';";
dbcmd.CommandText = sql;
dbcmd.ExecuteNonQuery();
trans.Commit();
dbcmd.Dispose();
return true;
}
IDbCommand GetCommandMusicSynth(MusicSynth entry)
{
IDbCommand dbcmd = dbCon.CreateCommand();
IDbDataParameter param1 = dbcmd.CreateParameter();
param1.ParameterName = "@name";
param1.DbType = DbType.String;
param1.Value = entry.Name;
dbcmd.Parameters.Add(param1);
return dbcmd;
}
static List<MusicSynth> MusicSynthFromDataTable(DataTable dataTable)
{
List<MusicSynth> entries = new List<MusicSynth>();
foreach(DataRow dataRow in dataTable.Rows)
{
MusicSynth entry = new MusicSynth {Id = (int)dataRow["id"], Name = (string)dataRow["name"]};
entries.Add(entry);
}
return entries;
}
}
}

View File

@@ -35,7 +35,7 @@ namespace Cicm.Database
public partial class Operations
{
/// <summary>Last known database version</summary>
const int DB_VERSION = 12;
const int DB_VERSION = 13;
/// <summary>The column with this value indicates there is no item of this type.</summary>
public const int DB_NONE = -1;
/// <summary>This value indicates there's no GPU, but a direct memory->display connection (a framebuffer).</summary>

View File

@@ -128,6 +128,11 @@ namespace Cicm.Database
UpdateDatabaseToV12();
break;
}
case 12:
{
UpdateDatabaseToV13();
break;
}
}
OptimizeDatabase();
@@ -999,7 +1004,7 @@ namespace Cicm.Database
trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText =
"ALTER TABLE `gpus` ADD FOREIGN KEY `fk_gpus_company` (company) REFERENCES `companies` (`id`) ON UPDATE CASCADE;;";
"ALTER TABLE `gpus` ADD FOREIGN KEY `fk_gpus_company` (company) REFERENCES `companies` (`id`) ON UPDATE CASCADE;";
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
@@ -1086,6 +1091,205 @@ namespace Cicm.Database
dbCmd.Dispose();
}
void UpdateDatabaseToV13()
{
Console.WriteLine("Updating database to version 13");
Console.WriteLine("Adding new columns to table `sound_synths`");
IDbCommand dbCmd = dbCon.CreateCommand();
IDbTransaction trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText = "ALTER TABLE `sound_synths` ADD COLUMN `company` INT NULL;\n" +
"ALTER TABLE `sound_synths` ADD COLUMN `model_code` VARCHAR(45) NULL;\n" +
"ALTER TABLE `sound_synths` ADD COLUMN `introduced` DATETIME NULL;\n" +
"ALTER TABLE `sound_synths` ADD COLUMN `voices` INT NULL;\n" +
"ALTER TABLE `sound_synths` ADD COLUMN `frequency` DOUBLE NULL;\n" +
"ALTER TABLE `sound_synths` ADD COLUMN `depth` INT NULL;\n" +
"ALTER TABLE `sound_synths` ADD COLUMN `square_wave` INT NULL;\n" +
"ALTER TABLE `sound_synths` ADD COLUMN `white_noise` INT NULL;\n" +
"ALTER TABLE `sound_synths` ADD COLUMN `type` INT NULL;";
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Creating new indexes in table `sound_synths`");
dbCmd = dbCon.CreateCommand();
trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText = "CREATE INDEX `idx_sound_synths_company` ON `sound_synths` (`company`);\n" +
"CREATE INDEX `idx_sound_synths_model_code` ON `sound_synths` (`model_code`);\n" +
"CREATE INDEX `idx_sound_synths_introduced` ON `sound_synths` (`introduced`);\n" +
"CREATE INDEX `idx_sound_synths_voices` ON `sound_synths` (`voices`);\n" +
"CREATE INDEX `idx_sound_synths_frequency` ON `sound_synths` (`frequency`);\n" +
"CREATE INDEX `idx_sound_synths_depth` ON `sound_synths` (`depth`);\n" +
"CREATE INDEX `idx_sound_synths_square_wave` ON `sound_synths` (`square_wave`);\n" +
"CREATE INDEX `idx_sound_synths_white_noise` ON `sound_synths` (`white_noise`);\n" +
"CREATE INDEX `idx_sound_synths_type` ON `sound_synths` (`type`);";
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Creating foreign keys in table `sound_synths`");
dbCmd = dbCon.CreateCommand();
trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText =
"ALTER TABLE `sound_synths` ADD FOREIGN KEY `fk_sound_synths_company` (company) REFERENCES `companies` (`id`) ON UPDATE CASCADE;";
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Dropping foreign keys from tables `computers` and `consoles`");
dbCmd = dbCon.CreateCommand();
trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText = "ALTER TABLE `computers` DROP FOREIGN KEY `fk_computers_music_synth`;\n" +
"ALTER TABLE `consoles` DROP FOREIGN KEY `fk_consoles_music_synth`;";
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Getting all items from `music_synths`");
Dictionary<int, string> musicSynths = new Dictionary<int, string>();
dbCmd = dbCon.CreateCommand();
IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = "SELECT * from music_synths";
DataSet dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
foreach(DataRow dataRow in dataSet.Tables[0].Rows)
musicSynths.Add(int.Parse(dataRow["id"].ToString()), dataRow["name"].ToString());
Dictionary<int, int> conversionEquivalents = new Dictionary<int, int>();
Console.WriteLine("Converting all items from `music_synths` to `sound_synths`");
foreach(KeyValuePair<int, string> musicSynth in musicSynths)
{
dbCmd = dbCon.CreateCommand();
dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = $"SELECT * from sound_synths WHERE name LIKE '{musicSynth.Value}'";
dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
if(dataSet.Tables[0].Rows.Count == 1)
{
Console.WriteLine("Converting music synth `{0}` to sound synth `{1}`", musicSynth.Value,
dataSet.Tables[0].Rows[0]["name"]);
conversionEquivalents.Add(musicSynth.Key, int.Parse(dataSet.Tables[0].Rows[0]["id"].ToString()));
}
else
{
Console.Write("Adding new sound synth `{0}`... ", musicSynth.Value);
dbCmd = dbCon.CreateCommand();
trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText = $"INSERT INTO sound_synths (name) VALUES ('{musicSynth.Value}')";
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
long id = dbCore.LastInsertRowId;
Console.WriteLine("got id {0}", id);
conversionEquivalents.Add(musicSynth.Key, (int)id);
}
}
Console.WriteLine("Getting all items from `consoles`");
Dictionary<int, int> consoleIdAndMusicSynthId = new Dictionary<int, int>();
dbCmd = dbCon.CreateCommand();
dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = "SELECT id,music_synth from consoles";
dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
foreach(DataRow dataRow in dataSet.Tables[0].Rows)
consoleIdAndMusicSynthId.Add(int.Parse(dataRow["id"].ToString()),
int.Parse(dataRow["music_synth"].ToString()));
trans = dbCon.BeginTransaction();
foreach(KeyValuePair<int, int> keyValuePair in consoleIdAndMusicSynthId)
{
conversionEquivalents.TryGetValue(keyValuePair.Value, out int newId);
Console.WriteLine("Converting music synth {0} to sound synth {1} for console {2}... ",
keyValuePair.Value, newId, keyValuePair.Key);
dbCmd = dbCon.CreateCommand();
dbCmd.Transaction = trans;
dbCmd.CommandText = $"UPDATE consoles SET music_synth = {newId} WHERE id = {keyValuePair.Key}";
dbCmd.ExecuteNonQuery();
dbCmd.Dispose();
}
Console.WriteLine("Comitting changes...");
trans.Commit();
Console.WriteLine("Getting all items from `computers`");
Dictionary<int, int> computerIdAndMusicSynthId = new Dictionary<int, int>();
dbCmd = dbCon.CreateCommand();
dataAdapter = dbCore.GetNewDataAdapter();
dbCmd.CommandText = "SELECT id,music_synth from computers";
dataSet = new DataSet();
dataAdapter.SelectCommand = dbCmd;
dataAdapter.Fill(dataSet);
foreach(DataRow dataRow in dataSet.Tables[0].Rows)
computerIdAndMusicSynthId.Add(int.Parse(dataRow["id"].ToString()),
int.Parse(dataRow["music_synth"].ToString()));
trans = dbCon.BeginTransaction();
foreach(KeyValuePair<int, int> keyValuePair in computerIdAndMusicSynthId)
{
conversionEquivalents.TryGetValue(keyValuePair.Value, out int newId);
Console.WriteLine("Converting music synth {0} to sound synth {1} for computer {2}... ",
keyValuePair.Value, newId, keyValuePair.Key);
dbCmd = dbCon.CreateCommand();
dbCmd.Transaction = trans;
dbCmd.CommandText = $"UPDATE computers SET music_synth = {newId} WHERE id = {keyValuePair.Key}";
dbCmd.ExecuteNonQuery();
dbCmd.Dispose();
}
Console.WriteLine("Comitting changes...");
trans.Commit();
Console.WriteLine("Adding new foreign keys to table `computers`");
dbCmd = dbCon.CreateCommand();
trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText =
"ALTER TABLE `computers` ADD FOREIGN KEY `fk_computers_music_synth` (music_synth) REFERENCES `sound_synths` (`id`) ON UPDATE CASCADE;";
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Adding new foreign keys to table `consoles`");
dbCmd = dbCon.CreateCommand();
trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText =
"ALTER TABLE `consoles` ADD FOREIGN KEY `fk_consoles_music_synth` (music_synth) REFERENCES `sound_synths` (`id`) ON UPDATE CASCADE;";
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Dropping table `music_synths`");
dbCmd = dbCon.CreateCommand();
trans = dbCon.BeginTransaction();
dbCmd.Transaction = trans;
dbCmd.CommandText = "DROP TABLE `music_synths`;";
dbCmd.ExecuteNonQuery();
trans.Commit();
dbCmd.Dispose();
Console.WriteLine("Setting new database version to 13...");
dbCmd = dbCon.CreateCommand();
dbCmd.CommandText = "INSERT INTO cicm_db (version) VALUES ('13')";
dbCmd.ExecuteNonQuery();
dbCmd.Dispose();
}
void OptimizeDatabase()
{
IDbCommand dbCmd = dbCon.CreateCommand();

View File

@@ -0,0 +1,94 @@
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : V12.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Contains SQL queries to create the database version 7.
//
// --[ 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
*******************************************************************************/
namespace Cicm.Database.Schemas.Sql
{
public static class V13
{
public static readonly string Admins = V12.Admins;
public static readonly string BrowserTests = V12.BrowserTests;
public static readonly string CicmDb = "CREATE TABLE `cicm_db` (\n" +
"`id` int(11) NOT NULL AUTO_INCREMENT,\n" +
"`version` int(11) NOT NULL,\n" +
"`updated` datetime DEFAULT CURRENT_TIMESTAMP,\n" +
"PRIMARY KEY (`id`)\n" + ");\n" +
"INSERT INTO cicm_db (version) VALUES ('13');";
public static readonly string Companies = V12.Companies;
public static readonly string Computers = V12.Computers;
public static readonly string Consoles = V12.Consoles;
public static readonly string DiskFormats = V12.DiskFormats;
public static readonly string Forbidden = V12.Forbidden;
public static readonly string Gpus = V12.Gpus;
public static readonly string Logs = V12.Logs;
public static readonly string MoneyDonations = V12.MoneyDonations;
public static readonly string MusicSynths = V12.MusicSynths;
public static readonly string News = V12.News;
public static readonly string OwnedComputers = V12.OwnedComputers;
public static readonly string OwnedConsoles = V12.OwnedConsoles;
public static readonly string Processors = V12.Processors;
public static readonly string SoundSynths = V12.SoundSynths;
public static readonly string ComputersForeignKeys = V12.ComputersForeignKeys;
public static readonly string ConsolesForeignKeys = V12.ConsolesForeignKeys;
public static readonly string Iso3166Numeric = V12.Iso3166Numeric;
public static readonly string Iso3166NumericValues = V12.Iso3166NumericValues;
public static readonly string CompaniesForeignKeys = V12.CompaniesForeignKeys;
public static readonly string CompanyLogos = V12.CompanyLogos;
public static readonly string CompanyDescriptions = V12.CompanyDescriptions;
public static readonly string InstructionSets = V12.InstructionSets;
public static readonly string InstructionSetExtensions = V12.InstructionSetExtensions;
public static readonly string InstructionSetExtensionsByProcessor = V12.InstructionSetExtensionsByProcessor;
}
}

View File

@@ -54,7 +54,7 @@ namespace cicm_web.Models
public float Mhz2;
public string Model;
public int MusicChannels;
public MusicSynth MusicSynth;
public SoundSynth MusicSynth;
public int Ram;
public string Resolution;
public int Rom;
@@ -136,7 +136,7 @@ namespace cicm_web.Models
if(dbItem.MusicSynth > 0)
{
item.MusicSynth = MusicSynth.GetItem(dbItem.MusicSynth);
item.MusicSynth = SoundSynth.GetItem(dbItem.MusicSynth);
item.MusicChannels = dbItem.MusicChannels;
}

View File

@@ -49,7 +49,7 @@ namespace cicm_web.Models
public float Mhz2;
public string Model;
public int MusicChannels;
public MusicSynth MusicSynth;
public SoundSynth MusicSynth;
public int Palette;
public int Ram;
public string Resolution;
@@ -122,7 +122,7 @@ namespace cicm_web.Models
if(dbItem.MusicSynth > 0)
{
item.MusicSynth = MusicSynth.GetItem(dbItem.MusicSynth);
item.MusicSynth = SoundSynth.GetItem(dbItem.MusicSynth);
item.MusicChannels = dbItem.MusicChannels;
}

View File

@@ -1,60 +0,0 @@
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : MusicSynth.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Music Synthetizer 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
*******************************************************************************/
using System.Collections.Generic;
namespace cicm_web.Models
{
public class MusicSynth
{
public int Id;
public string Name;
public static MusicSynth GetItem(int id)
{
Cicm.Database.Schemas.MusicSynth dbItem = Program.Database?.Operations.GetMusicSynth(id);
return dbItem == null ? null : new MusicSynth {Name = dbItem.Name, Id = dbItem.Id};
}
public static MusicSynth[] GetAllItems()
{
List<Cicm.Database.Schemas.MusicSynth> dbItems = null;
bool? result = Program.Database?.Operations.GetMusicSynths(out dbItems);
if(result == null || result.Value == false || dbItems == null) return null;
List<MusicSynth> items = new List<MusicSynth>();
foreach(Cicm.Database.Schemas.MusicSynth dbItem in dbItems)
items.Add(new MusicSynth {Id = dbItem.Id, Name = dbItem.Name});
return items.ToArray();
}
}
}

View File

@@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<Version>3.0.99.189</Version>
<Version>3.0.99.192</Version>
<Company>Canary Islands Computer Museum</Company>
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
<Product>Canary Islands Computer Museum Website</Product>