diff --git a/misc/create_schema.sql b/misc/create_schema.sql index 8df7d30..7bf326f 100644 --- a/misc/create_schema.sql +++ b/misc/create_schema.sql @@ -175,6 +175,8 @@ CREATE TABLE `role` ( `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, `name` VARCHAR(50) NOT NULL DEFAULT '0' COMMENT 'unique role name', `description` VARCHAR(255) NULL DEFAULT '0' COMMENT 'role description', + `created` DATETIME NULL DEFAULT current_timestamp(), + `modified` DATETIME NULL DEFAULT NULL ON UPDATE current_timestamp(), PRIMARY KEY (`id`), UNIQUE INDEX `name` (`name`) ) @@ -187,6 +189,8 @@ ENGINE=InnoDB CREATE TABLE `securable` ( `id` INT(10) UNSIGNED NOT NULL, `name` VARCHAR(50) NOT NULL DEFAULT '', + `created` DATETIME NULL DEFAULT current_timestamp(), + `modified` DATETIME NULL DEFAULT NULL ON UPDATE current_timestamp(), PRIMARY KEY (`id`), UNIQUE INDEX `name` (`name`) ) @@ -199,6 +203,8 @@ CREATE TABLE `user_role_map` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `user_id` INT(10) UNSIGNED NOT NULL DEFAULT 0, `role_id` INT(10) UNSIGNED NOT NULL DEFAULT 0, + `created` DATETIME NULL DEFAULT current_timestamp(), + `modified` DATETIME NULL DEFAULT NULL ON UPDATE current_timestamp(), PRIMARY KEY (`id`), INDEX `FK_USER_ROLE` (`user_id`), INDEX `FK_ROLE_USER` (`role_id`), @@ -214,6 +220,8 @@ CREATE TABLE `role_securable_map` ( `id` INT(10) UNSIGNED NOT NULL, `role_id` INT(10) UNSIGNED NOT NULL, `securable_id` INT(10) UNSIGNED NOT NULL, + `created` DATETIME NULL DEFAULT current_timestamp(), + `modified` DATETIME NULL DEFAULT NULL ON UPDATE current_timestamp(), PRIMARY KEY (`id`), INDEX `FK_ROLE_SECURABLE` (`role_id`), INDEX `FK_SECURABLE_ROLE` (`securable_id`), diff --git a/src/RoleEditor/MainWindow.xaml b/src/RoleEditor/MainWindow.xaml index 237d08f..8d24419 100644 --- a/src/RoleEditor/MainWindow.xaml +++ b/src/RoleEditor/MainWindow.xaml @@ -5,7 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:RoleEditor" mc:Ignorable="d" - Title="Bremen calling admin editor" Height="600" Width="800" Icon="Resources/lock_preferences.ico"> + Title="Bremen calling admin editor" Height="600" Width="800" Icon="Resources/lock_preferences.ico" Loaded="Window_Loaded"> diff --git a/src/RoleEditor/MainWindow.xaml.cs b/src/RoleEditor/MainWindow.xaml.cs index 8d37ed8..53313db 100644 --- a/src/RoleEditor/MainWindow.xaml.cs +++ b/src/RoleEditor/MainWindow.xaml.cs @@ -14,6 +14,8 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using System.Collections.ObjectModel; +using brecal.model; namespace RoleEditor { @@ -22,11 +24,36 @@ namespace RoleEditor /// public partial class MainWindow : Window { + #region private fields + + private ObservableCollection _participants = new ObservableCollection(); + private ObservableCollection _roles = new ObservableCollection(); + private ObservableCollection _securables = new ObservableCollection(); + private ObservableCollection _users = new ObservableCollection(); + private ObservableCollection _assignedRoles = new ObservableCollection(); + private ObservableCollection _assignedSecurables = new ObservableCollection(); + + #endregion + + #region Construction / Loading + public MainWindow() { InitializeComponent(); } + private void Window_Loaded(object sender, RoutedEventArgs e) + { + // try database connection + + // load all participants + + // load all roles + + } + + #endregion + #region button callbacks private void buttonParticipantSave_Click(object sender, RoutedEventArgs e) @@ -71,6 +98,8 @@ namespace RoleEditor #endregion + #region listbox selection callbacks + private void listBoxParticipant_SelectionChanged(object sender, SelectionChangedEventArgs e) { @@ -91,6 +120,10 @@ namespace RoleEditor } + #endregion + + #region menuitem callbacks + private void menuItemDeleteParticipant_Click(object sender, RoutedEventArgs e) { @@ -130,5 +163,8 @@ namespace RoleEditor { } + + #endregion + } } diff --git a/src/RoleEditor/RoleEditor.csproj b/src/RoleEditor/RoleEditor.csproj index 21970fb..936e6bb 100644 --- a/src/RoleEditor/RoleEditor.csproj +++ b/src/RoleEditor/RoleEditor.csproj @@ -21,6 +21,11 @@ + + + + + diff --git a/src/RoleEditor/RoleEditor.sln b/src/RoleEditor/RoleEditor.sln index e3f05ce..6b98d6e 100644 --- a/src/RoleEditor/RoleEditor.sln +++ b/src/RoleEditor/RoleEditor.sln @@ -3,7 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.5.33516.290 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RoleEditor", "RoleEditor.csproj", "{8A8CB0D3-7728-468E-AB11-E811BA5B5BC0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RoleEditor", "RoleEditor.csproj", "{8A8CB0D3-7728-468E-AB11-E811BA5B5BC0}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "brecal.model", "..\brecal.model\brecal.model.csproj", "{F3BC5ADC-BF57-47DC-A5D5-CC4A13857DEE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "brecal.mysql", "..\brecal.mysql\brecal.mysql.csproj", "{E88F908B-48C9-46BD-A3AE-C36FBE9EDF1F}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +19,14 @@ Global {8A8CB0D3-7728-468E-AB11-E811BA5B5BC0}.Debug|Any CPU.Build.0 = Debug|Any CPU {8A8CB0D3-7728-468E-AB11-E811BA5B5BC0}.Release|Any CPU.ActiveCfg = Release|Any CPU {8A8CB0D3-7728-468E-AB11-E811BA5B5BC0}.Release|Any CPU.Build.0 = Release|Any CPU + {F3BC5ADC-BF57-47DC-A5D5-CC4A13857DEE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F3BC5ADC-BF57-47DC-A5D5-CC4A13857DEE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F3BC5ADC-BF57-47DC-A5D5-CC4A13857DEE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F3BC5ADC-BF57-47DC-A5D5-CC4A13857DEE}.Release|Any CPU.Build.0 = Release|Any CPU + {E88F908B-48C9-46BD-A3AE-C36FBE9EDF1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E88F908B-48C9-46BD-A3AE-C36FBE9EDF1F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E88F908B-48C9-46BD-A3AE-C36FBE9EDF1F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E88F908B-48C9-46BD-A3AE-C36FBE9EDF1F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/brecal.model/DbEntity.cs b/src/brecal.model/DbEntity.cs new file mode 100644 index 0000000..19b74b2 --- /dev/null +++ b/src/brecal.model/DbEntity.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace brecal.model +{ + public class DbEntity + { + /// + /// DB primary key + /// + public uint Id { get; set; } + + /// + /// Creation timestamp, if null record is unsaved + /// + public DateTime? Created { get; set; } + + /// + /// Modified timestamp, if null record was never modified + /// + public DateTime? Modified { get; set; } + + } +} diff --git a/src/brecal.model/IDBManager.cs b/src/brecal.model/IDBManager.cs new file mode 100644 index 0000000..0b1f44e --- /dev/null +++ b/src/brecal.model/IDBManager.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace brecal.model +{ + public interface IDBManager + { + + void Load(Action prepareAction, Action loadAction); + + Task ExecuteScalar(Action prepareAction); + + Task ExecuteNonQuery(Action prepareAction); + + } +} diff --git a/src/brecal.model/Participant.cs b/src/brecal.model/Participant.cs new file mode 100644 index 0000000..49e2de0 --- /dev/null +++ b/src/brecal.model/Participant.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace brecal.model +{ + public class Participant : DbEntity + { + #region Properties + + public string? Name { get; set; } + + public string? Street { get; set; } + + public string? PostalCode { get; set; } + + public string? City { get; set; } + + public uint Flags { get; set; } + + #endregion + + #region overrides + + public override string ToString() + { + return this.Name ?? $"{base.Id} - {this.GetType().Name}"; + } + + #endregion + + } +} diff --git a/src/brecal.model/Role.cs b/src/brecal.model/Role.cs new file mode 100644 index 0000000..bc182bd --- /dev/null +++ b/src/brecal.model/Role.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace brecal.model +{ + public class Role : DbEntity + { + + #region Properties + + public string? Name { get; set; } + + public string? Description { get; set; } + + #endregion + + #region overrides + + public override string ToString() + { + return this.Name ?? $"{base.Id} - {this.GetType().Name}"; + } + + #endregion + + } +} diff --git a/src/brecal.model/RoleAssignment.cs b/src/brecal.model/RoleAssignment.cs new file mode 100644 index 0000000..3fd46b5 --- /dev/null +++ b/src/brecal.model/RoleAssignment.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace brecal.model +{ + public class RoleAssignment : DbEntity + { + + #region Properties + + public Role? AssignedRole { get; set; } + + public User? AssignedUser { get; set; } + + #endregion + + } +} diff --git a/src/brecal.model/Securable.cs b/src/brecal.model/Securable.cs new file mode 100644 index 0000000..906e8e8 --- /dev/null +++ b/src/brecal.model/Securable.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace brecal.model +{ + public class Securable : DbEntity + { + + #region Properties + + public string? Name { get; set; } + + #endregion + + #region overrides + + public override string ToString() + { + return this.Name ?? $"{base.Id} - {this.GetType().Name}"; + } + + #endregion + + } +} diff --git a/src/brecal.model/SecurableAssignment.cs b/src/brecal.model/SecurableAssignment.cs new file mode 100644 index 0000000..7a68bd2 --- /dev/null +++ b/src/brecal.model/SecurableAssignment.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace brecal.model +{ + public class SecurableAssignment : DbEntity + { + #region Properties + + public Role? AssignedRole { get; set; } + + public Securable? AssignedSecurable { get; set; } + + #endregion + } +} diff --git a/src/brecal.model/User.cs b/src/brecal.model/User.cs new file mode 100644 index 0000000..3358dcb --- /dev/null +++ b/src/brecal.model/User.cs @@ -0,0 +1,29 @@ +namespace brecal.model +{ + public class User : DbEntity + { + #region Properties + + public string? Firstname { get; set; } + + public string? Lastname { get; set; } + + public string Username { get; set; } = ""; + + public string? PasswordHash { get; set; } + + public string? APIKey { get; set; } + + #endregion + + #region overrides + + public override string ToString() + { + return this.Username ?? $"{base.Id} - {this.GetType().Name}"; + } + + #endregion + + } +} \ No newline at end of file diff --git a/src/brecal.model/brecal.model.csproj b/src/brecal.model/brecal.model.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/src/brecal.model/brecal.model.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/src/brecal.mysql/DBManager.cs b/src/brecal.mysql/DBManager.cs new file mode 100644 index 0000000..f85f5b9 --- /dev/null +++ b/src/brecal.mysql/DBManager.cs @@ -0,0 +1,61 @@ +using brecal.model; +using MySqlConnector; +using System.Data; +using System.Runtime.CompilerServices; + +namespace brecal.mysql +{ + public class DBManager : IDBManager + { + private static string _connectionString = ""; + + + public async void Generic() + { + await using var connection = new MySqlConnection("Server=myserver;User ID=mylogin;Password=mypass;Database=mydatabase"); + await connection.OpenAsync(); + + using var command = new MySqlCommand("SELECT field FROM table;", connection); + await using var reader = await command.ExecuteReaderAsync(); + while (await reader.ReadAsync()) + Console.WriteLine(reader.GetString(0)); + } + + public async void Load(Action prepareAction, Action loadAction) + { + await using MySqlConnection connection = new MySqlConnection(_connectionString); + await connection.OpenAsync(); + using MySqlCommand cmd = new MySqlCommand(); + cmd.Connection = connection; + prepareAction(cmd); + MySqlDataReader reader = await cmd.ExecuteReaderAsync(); + loadAction(reader); + reader.Close(); + } + + public async Task ExecuteScalar(Action prepareAction) + { + await using MySqlConnection connection = new MySqlConnection(_connectionString); + await connection.OpenAsync(); + + using MySqlCommand cmd = new MySqlCommand(); + cmd.Connection = connection; + prepareAction(cmd); + object? result = await cmd.ExecuteScalarAsync(); + return result; + } + + public async Task ExecuteNonQuery(Action prepareAction) + { + await using MySqlConnection connection = new MySqlConnection(_connectionString); + await connection.OpenAsync(); + + using MySqlCommand cmd = new MySqlCommand(); + cmd.Connection = connection; + prepareAction(cmd); + int result = await cmd.ExecuteNonQueryAsync(); + return result; + } + + } +} \ No newline at end of file diff --git a/src/brecal.mysql/brecal.mysql.csproj b/src/brecal.mysql/brecal.mysql.csproj new file mode 100644 index 0000000..786b11e --- /dev/null +++ b/src/brecal.mysql/brecal.mysql.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + +