saving securables, more logic
This commit is contained in:
parent
66b2691c41
commit
c9aa439712
@ -101,7 +101,6 @@ CREATE TABLE `participant` (
|
|||||||
`street` VARCHAR(128) NULL DEFAULT NULL,
|
`street` VARCHAR(128) NULL DEFAULT NULL,
|
||||||
`postal_code` VARCHAR(5) NULL DEFAULT NULL,
|
`postal_code` VARCHAR(5) NULL DEFAULT NULL,
|
||||||
`city` VARCHAR(64) NULL DEFAULT NULL,
|
`city` VARCHAR(64) NULL DEFAULT NULL,
|
||||||
`roles` INT(10) UNSIGNED NULL DEFAULT 0 COMMENT 'Bitarray of assigned roles',
|
|
||||||
`flags` INT(10) UNSIGNED NULL DEFAULT NULL,
|
`flags` INT(10) UNSIGNED NULL DEFAULT NULL,
|
||||||
`created` DATETIME NULL DEFAULT current_timestamp(),
|
`created` DATETIME NULL DEFAULT current_timestamp(),
|
||||||
`modified` DATETIME NULL DEFAULT NULL ON UPDATE current_timestamp(),
|
`modified` DATETIME NULL DEFAULT NULL ON UPDATE current_timestamp(),
|
||||||
@ -187,7 +186,7 @@ ENGINE=InnoDB
|
|||||||
|
|
||||||
|
|
||||||
CREATE TABLE `securable` (
|
CREATE TABLE `securable` (
|
||||||
`id` INT(10) UNSIGNED NOT NULL,
|
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
`name` VARCHAR(50) NOT NULL DEFAULT '',
|
`name` VARCHAR(50) NOT NULL DEFAULT '',
|
||||||
`created` DATETIME NULL DEFAULT current_timestamp(),
|
`created` DATETIME NULL DEFAULT current_timestamp(),
|
||||||
`modified` DATETIME NULL DEFAULT NULL ON UPDATE current_timestamp(),
|
`modified` DATETIME NULL DEFAULT NULL ON UPDATE current_timestamp(),
|
||||||
|
|||||||
@ -174,8 +174,8 @@
|
|||||||
</Button>
|
</Button>
|
||||||
<Label Content="Name" Grid.Row="4" Grid.Column="1" HorizontalAlignment="Right" />
|
<Label Content="Name" Grid.Row="4" Grid.Column="1" HorizontalAlignment="Right" />
|
||||||
<Label Content="Descr." Grid.Row="5" Grid.Column="1" HorizontalAlignment="Right" />
|
<Label Content="Descr." Grid.Row="5" Grid.Column="1" HorizontalAlignment="Right" />
|
||||||
<TextBox x:Name="textBoxRoleName" Grid.Row="4" Grid.Column="2" Margin="2" />
|
<TextBox x:Name="textBoxRoleName" Grid.Row="4" Grid.Column="2" Margin="2" VerticalContentAlignment="Center"/>
|
||||||
<TextBox x:Name="textBoxRoleDescription" Grid.Row="5" Grid.Column="2" Grid.RowSpan="2" Margin="2" />
|
<TextBox x:Name="textBoxRoleDescription" Grid.Row="5" Grid.Column="2" Grid.RowSpan="2" Margin="2" VerticalContentAlignment="Top"/>
|
||||||
<Button x:Name="buttonSaveRole" Grid.Row="7" Grid.Column="2" Margin="2" Click="buttonSaveRole_Click">
|
<Button x:Name="buttonSaveRole" Grid.Row="7" Grid.Column="2" Margin="2" Click="buttonSaveRole_Click">
|
||||||
<DockPanel>
|
<DockPanel>
|
||||||
<Image Source="./Resources/disk_blue.png" Margin="0,0,5,0" Height="24" DockPanel.Dock="Left" Width="16"/>
|
<Image Source="./Resources/disk_blue.png" Margin="0,0,5,0" Height="24" DockPanel.Dock="Left" Width="16"/>
|
||||||
@ -225,7 +225,7 @@
|
|||||||
<Image Source="./Resources/delete2.png" Margin="0,0,5,0" Height="24" DockPanel.Dock="Left" Width="22"/>
|
<Image Source="./Resources/delete2.png" Margin="0,0,5,0" Height="24" DockPanel.Dock="Left" Width="22"/>
|
||||||
</Button>
|
</Button>
|
||||||
<Label Content="Name" Grid.Row="4" Grid.Column="1" HorizontalAlignment="Right" />
|
<Label Content="Name" Grid.Row="4" Grid.Column="1" HorizontalAlignment="Right" />
|
||||||
<TextBox x:Name="textBoxSecurableName" Grid.Row="4" Grid.Column="2" Margin="2" />
|
<TextBox x:Name="textBoxSecurableName" Grid.Row="4" Grid.Column="2" Margin="2" VerticalContentAlignment="Center"/>
|
||||||
<Button x:Name="buttonSaveSecurable" Grid.Row="5" Grid.Column="2" Margin="2" Click="buttonSaveSecurable_Click">
|
<Button x:Name="buttonSaveSecurable" Grid.Row="5" Grid.Column="2" Margin="2" Click="buttonSaveSecurable_Click">
|
||||||
<DockPanel>
|
<DockPanel>
|
||||||
<Image Source="./Resources/disk_blue.png" Margin="0,0,5,0" Height="24" DockPanel.Dock="Left" Width="16"/>
|
<Image Source="./Resources/disk_blue.png" Margin="0,0,5,0" Height="24" DockPanel.Dock="Left" Width="16"/>
|
||||||
|
|||||||
@ -63,9 +63,13 @@ namespace RoleEditor
|
|||||||
_roles.Add(r);
|
_roles.Add(r);
|
||||||
this.listBoxRoles.ItemsSource = _roles;
|
this.listBoxRoles.ItemsSource = _roles;
|
||||||
|
|
||||||
// set other item sources
|
// load all securables
|
||||||
this.listBoxUser.ItemsSource = _users;
|
foreach(Securable s in await Securable.LoadAll(_dbManager))
|
||||||
|
_securables.Add(s);
|
||||||
this.listBoxSecurables.ItemsSource = _securables;
|
this.listBoxSecurables.ItemsSource = _securables;
|
||||||
|
|
||||||
|
// set other item sources (filled later after selection)
|
||||||
|
this.listBoxUser.ItemsSource = _users;
|
||||||
this.listBoxRoleSecurables.ItemsSource = _assignedSecurables;
|
this.listBoxRoleSecurables.ItemsSource = _assignedSecurables;
|
||||||
this.listBoxUserRoles.ItemsSource = _assignedRoles;
|
this.listBoxUserRoles.ItemsSource = _assignedRoles;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,21 +16,57 @@ namespace brecal.model
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region public static methods
|
||||||
|
|
||||||
|
public static async Task<List<Securable>> LoadAll(IDBManager manager)
|
||||||
|
{
|
||||||
|
List<DbEntity> loadResultList = await manager.Load(SetLoadQuery, LoadElems);
|
||||||
|
List<Securable> result = new();
|
||||||
|
foreach (Securable s in loadResultList.Cast<Securable>())
|
||||||
|
result.Add(s);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetLoadQuery(IDbCommand cmd, params object[] list)
|
||||||
|
{
|
||||||
|
cmd.CommandText = "SELECT id, name, created, modified FROM securable";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<DbEntity> LoadElems(IDataReader reader)
|
||||||
|
{
|
||||||
|
List<DbEntity> result = new List<DbEntity>();
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
Securable s = new();
|
||||||
|
s.Id = (uint)reader.GetInt32(0);
|
||||||
|
if (!reader.IsDBNull(1)) s.Name = reader.GetString(1);
|
||||||
|
if (!reader.IsDBNull(2)) s.Created = reader.GetDateTime(2);
|
||||||
|
if (!reader.IsDBNull(3)) s.Modified = reader.GetDateTime(3);
|
||||||
|
result.Add(s);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region overrides
|
#region overrides
|
||||||
|
|
||||||
public override void SetUpdate(IDbCommand cmd)
|
public override void SetUpdate(IDbCommand cmd)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
cmd.CommandText = "UPDATE securable set name = @NAME WHERE id = @ID";
|
||||||
|
this.SetParameters(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetCreate(IDbCommand cmd)
|
public override void SetCreate(IDbCommand cmd)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
cmd.CommandText = "INSERT INTO securable (name) VALUES ( @NAME)";
|
||||||
|
this.SetParameters(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetDelete(IDbCommand cmd)
|
public override void SetDelete(IDbCommand cmd)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
cmd.CommandText = "DELETE FROM securable WHERE id = @ID";
|
||||||
|
this.SetParameters(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
@ -40,5 +76,22 @@ namespace brecal.model
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region private methods
|
||||||
|
|
||||||
|
private void SetParameters(IDbCommand cmd)
|
||||||
|
{
|
||||||
|
IDbDataParameter name = cmd.CreateParameter();
|
||||||
|
name.ParameterName = "NAME";
|
||||||
|
name.Value = this.Name;
|
||||||
|
cmd.Parameters.Add(name);
|
||||||
|
|
||||||
|
IDataParameter idParam = cmd.CreateParameter();
|
||||||
|
idParam.ParameterName = "ID";
|
||||||
|
idParam.Value = this.Id;
|
||||||
|
cmd.Parameters.Add(idParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ namespace brecal.mysql
|
|||||||
public class DBManager : IDBManager
|
public class DBManager : IDBManager
|
||||||
{
|
{
|
||||||
// TODO: remove this and use certificates instead
|
// TODO: remove this and use certificates instead
|
||||||
private static readonly string _connectionString = "Server=localhost;User ID=ds;Password=HalloWach23;Database=bremen_calling";
|
private static readonly string _connectionString = "Server=lager;User ID=ds;Password=HalloWach23;Database=bremen_calling";
|
||||||
|
|
||||||
public async Task<List<DbEntity>> Load(QueryFunc prepareAction, LoadFunc<IDataReader> loadAction, params object[] args)
|
public async Task<List<DbEntity>> Load(QueryFunc prepareAction, LoadFunc<IDataReader> loadAction, params object[] args)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user