StarSim

StarSim.git
git clone git://git.lenczewski.org/StarSim.git
Log | Files | Refs | README | LICENSE

commit ca68e34acfefe3dca49adc9f34317d6c74ea307c
parent f24df0645bd8784ffa31a77b604564017070ffe3
Author: Mikolaj Lenczewski <33129490+EnderRifter@users.noreply.github.com>
Date:   Fri, 16 Aug 2019 15:53:59 +0200

Added remaining views for database actions and their relevant view models

Diffstat:
MStarSim/StarSimGui/StarSimGui.csproj | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
AStarSim/StarSimGui/ViewModels/Database ViewModels/CreateSystemsViewModel.cs | 32++++++++++++++++++++++++++++++++
AStarSim/StarSimGui/ViewModels/Database ViewModels/CreateUsersViewModel.cs | 32++++++++++++++++++++++++++++++++
AStarSim/StarSimGui/ViewModels/Database ViewModels/DeleteSystemsViewModel.cs | 32++++++++++++++++++++++++++++++++
AStarSim/StarSimGui/ViewModels/Database ViewModels/DeleteUsersViewModel.cs | 32++++++++++++++++++++++++++++++++
AStarSim/StarSimGui/ViewModels/Database ViewModels/ReadSystemsViewModel.cs | 147+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
AStarSim/StarSimGui/ViewModels/Database ViewModels/ReadUsersViewModel.cs | 147+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
DStarSim/StarSimGui/ViewModels/Database ViewModels/SystemReadViewModel.cs | 147-------------------------------------------------------------------------------
AStarSim/StarSimGui/ViewModels/Database ViewModels/UpdateSystemsViewModel.cs | 32++++++++++++++++++++++++++++++++
AStarSim/StarSimGui/ViewModels/Database ViewModels/UpdateUsersViewModel.cs | 32++++++++++++++++++++++++++++++++
DStarSim/StarSimGui/ViewModels/Database ViewModels/UserReadViewModel.cs | 147-------------------------------------------------------------------------------
MStarSim/StarSimGui/ViewModels/DatabaseViewModel.cs | 84+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
AStarSim/StarSimGui/Views/Database Views/CreateSystems.xaml | 19+++++++++++++++++++
AStarSim/StarSimGui/Views/Database Views/CreateSystems.xaml.cs | 19+++++++++++++++++++
AStarSim/StarSimGui/Views/Database Views/CreateUsers.xaml | 19+++++++++++++++++++
AStarSim/StarSimGui/Views/Database Views/CreateUsers.xaml.cs | 20++++++++++++++++++++
AStarSim/StarSimGui/Views/Database Views/DeleteSystems.xaml | 19+++++++++++++++++++
AStarSim/StarSimGui/Views/Database Views/DeleteSystems.xaml.cs | 19+++++++++++++++++++
AStarSim/StarSimGui/Views/Database Views/DeleteUsers.xaml | 19+++++++++++++++++++
AStarSim/StarSimGui/Views/Database Views/DeleteUsers.xaml.cs | 19+++++++++++++++++++
MStarSim/StarSimGui/Views/Database Views/ReadSystems.xaml | 2+-
MStarSim/StarSimGui/Views/Database Views/ReadUsers.xaml | 2+-
AStarSim/StarSimGui/Views/Database Views/UpdateSystems.xaml | 19+++++++++++++++++++
AStarSim/StarSimGui/Views/Database Views/UpdateSystems.xaml.cs | 19+++++++++++++++++++
AStarSim/StarSimGui/Views/Database Views/UpdateUsers.xaml | 19+++++++++++++++++++
AStarSim/StarSimGui/Views/Database Views/UpdateUsers.xaml.cs | 19+++++++++++++++++++
MStarSim/StarSimGui/Views/Database.xaml | 34++++++++--------------------------
27 files changed, 848 insertions(+), 337 deletions(-)

diff --git a/StarSim/StarSimGui/StarSimGui.csproj b/StarSim/StarSimGui/StarSimGui.csproj @@ -26,8 +26,14 @@ </ItemGroup> <ItemGroup> + <AvaloniaResource Remove="Views\Database Views\CreateSystems.xaml" /> + <AvaloniaResource Remove="Views\Database Views\CreateUsers.xaml" /> + <AvaloniaResource Remove="Views\Database Views\DeleteSystems.xaml" /> + <AvaloniaResource Remove="Views\Database Views\DeleteUsers.xaml" /> <AvaloniaResource Remove="Views\Database Views\ReadSystems.xaml" /> <AvaloniaResource Remove="Views\Database Views\ReadUsers.xaml" /> + <AvaloniaResource Remove="Views\Database Views\UpdateSystems.xaml" /> + <AvaloniaResource Remove="Views\Database Views\UpdateUsers.xaml" /> <AvaloniaResource Remove="Views\Database.xaml" /> <AvaloniaResource Remove="Views\Overview.xaml" /> <AvaloniaResource Remove="Views\Simulation.xaml" /> @@ -40,8 +46,14 @@ </ItemGroup> <ItemGroup> + <None Remove="Views\Database Views\CreateSystems.xaml" /> + <None Remove="Views\Database Views\CreateUsers.xaml" /> + <None Remove="Views\Database Views\DeleteSystems.xaml" /> + <None Remove="Views\Database Views\DeleteUsers.xaml" /> <None Remove="Views\Database Views\ReadSystems.xaml" /> <None Remove="Views\Database Views\ReadUsers.xaml" /> + <None Remove="Views\Database Views\UpdateSystems.xaml" /> + <None Remove="Views\Database Views\UpdateUsers.xaml" /> <None Remove="Views\Database.xaml" /> <None Remove="Views\Overview.xaml" /> <None Remove="Views\Simulation.xaml" /> @@ -100,10 +112,52 @@ </ItemGroup> <ItemGroup> + <EmbeddedResource Include="Views\Database Views\CreateUsers.xaml"> + <Generator>MSBuild:Compile</Generator> + </EmbeddedResource> + </ItemGroup> + + <ItemGroup> + <EmbeddedResource Include="Views\Database Views\CreateSystems.xaml"> + <Generator>MSBuild:Compile</Generator> + </EmbeddedResource> + </ItemGroup> + + <ItemGroup> + <EmbeddedResource Include="Views\Database Views\UpdateUsers.xaml"> + <Generator>MSBuild:Compile</Generator> + </EmbeddedResource> + </ItemGroup> + + <ItemGroup> + <EmbeddedResource Include="Views\Database Views\UpdateSystems.xaml"> + <Generator>MSBuild:Compile</Generator> + </EmbeddedResource> + </ItemGroup> + + <ItemGroup> + <EmbeddedResource Include="Views\Database Views\DeleteUsers.xaml"> + <Generator>MSBuild:Compile</Generator> + </EmbeddedResource> + </ItemGroup> + + <ItemGroup> + <EmbeddedResource Include="Views\Database Views\DeleteSystems.xaml"> + <Generator>MSBuild:Compile</Generator> + </EmbeddedResource> + </ItemGroup> + + <ItemGroup> <ProjectReference Include="..\StarSimLib\StarSimLib.csproj" /> </ItemGroup> <ItemGroup> + <Compile Update="Views\Database Views\CreateUsers.xaml.cs"> + <DependentUpon>CreateUsers.xaml</DependentUpon> + </Compile> + </ItemGroup> + + <ItemGroup> <None Update="App.xaml"> <Generator>MSBuild:Compile</Generator> </None> diff --git a/StarSim/StarSimGui/ViewModels/Database ViewModels/CreateSystemsViewModel.cs b/StarSim/StarSimGui/ViewModels/Database ViewModels/CreateSystemsViewModel.cs @@ -0,0 +1,31 @@ +using StarSimLib.Contexts; + +namespace StarSimGui.ViewModels.Database_ViewModels +{ + /// <summary> + /// Represents the create systems view. + /// </summary> + public class CreateSystemsViewModel : ViewModelBase + { + /// <summary> + /// The program database. + /// </summary> + private readonly SimulatorContext dbContext; + + /// <summary> + /// Initialises a new instance of the <see cref="CreateSystemsViewModel"/> class. + /// </summary> + public CreateSystemsViewModel() + { + } + + /// <summary> + /// Initialises a new instance of the <see cref="CreateSystemsViewModel"/> class. + /// </summary> + /// <param name="context">The <see cref="SimulatorContext"/> instance in which program data is stored.</param> + public CreateSystemsViewModel(in SimulatorContext context) : this() + { + dbContext = context; + } + } +} +\ No newline at end of file diff --git a/StarSim/StarSimGui/ViewModels/Database ViewModels/CreateUsersViewModel.cs b/StarSim/StarSimGui/ViewModels/Database ViewModels/CreateUsersViewModel.cs @@ -0,0 +1,31 @@ +using StarSimLib.Contexts; + +namespace StarSimGui.ViewModels.Database_ViewModels +{ + /// <summary> + /// Represents the create users view. + /// </summary> + public class CreateUsersViewModel : ViewModelBase + { + /// <summary> + /// The program database. + /// </summary> + private readonly SimulatorContext dbContext; + + /// <summary> + /// Initialises a new instance of the <see cref="CreateUsersViewModel"/> class. + /// </summary> + public CreateUsersViewModel() + { + } + + /// <summary> + /// Initialises a new instance of the <see cref="CreateUsersViewModel"/> class. + /// </summary> + /// <param name="context">The <see cref="SimulatorContext"/> instance in which program data is stored.</param> + public CreateUsersViewModel(in SimulatorContext context) : this() + { + dbContext = context; + } + } +} +\ No newline at end of file diff --git a/StarSim/StarSimGui/ViewModels/Database ViewModels/DeleteSystemsViewModel.cs b/StarSim/StarSimGui/ViewModels/Database ViewModels/DeleteSystemsViewModel.cs @@ -0,0 +1,31 @@ +using StarSimLib.Contexts; + +namespace StarSimGui.ViewModels.Database_ViewModels +{ + /// <summary> + /// Represents the delete systems view. + /// </summary> + public class DeleteSystemsViewModel : ViewModelBase + { + /// <summary> + /// The program database. + /// </summary> + private readonly SimulatorContext dbContext; + + /// <summary> + /// Initialises a new instance of the <see cref="DeleteSystemsViewModel"/> class. + /// </summary> + public DeleteSystemsViewModel() + { + } + + /// <summary> + /// Initialises a new instance of the <see cref="DeleteSystemsViewModel"/> class. + /// </summary> + /// <param name="context">The <see cref="SimulatorContext"/> instance in which program data is stored.</param> + public DeleteSystemsViewModel(in SimulatorContext context) : this() + { + dbContext = context; + } + } +} +\ No newline at end of file diff --git a/StarSim/StarSimGui/ViewModels/Database ViewModels/DeleteUsersViewModel.cs b/StarSim/StarSimGui/ViewModels/Database ViewModels/DeleteUsersViewModel.cs @@ -0,0 +1,31 @@ +using StarSimLib.Contexts; + +namespace StarSimGui.ViewModels.Database_ViewModels +{ + /// <summary> + /// Represents the delete users view. + /// </summary> + public class DeleteUsersViewModel : ViewModelBase + { + /// <summary> + /// The program database. + /// </summary> + private readonly SimulatorContext dbContext; + + /// <summary> + /// Initialises a new instance of the <see cref="DeleteUsersViewModel"/> class. + /// </summary> + public DeleteUsersViewModel() + { + } + + /// <summary> + /// Initialises a new instance of the <see cref="DeleteUsersViewModel"/> class. + /// </summary> + /// <param name="context">The <see cref="SimulatorContext"/> instance in which program data is stored.</param> + public DeleteUsersViewModel(in SimulatorContext context) : this() + { + dbContext = context; + } + } +} +\ No newline at end of file diff --git a/StarSim/StarSimGui/ViewModels/Database ViewModels/ReadSystemsViewModel.cs b/StarSim/StarSimGui/ViewModels/Database ViewModels/ReadSystemsViewModel.cs @@ -0,0 +1,146 @@ +using DynamicData.Binding; +using Microsoft.EntityFrameworkCore; +using ReactiveUI; +using StarSimLib.Contexts; +using StarSimLib.Models; + +namespace StarSimGui.ViewModels.Database_ViewModels +{ + /// <summary> + /// Represents the read systems view. + /// </summary> + public class ReadSystemsViewModel : ViewModelBase + { + /// <summary> + /// The program database. + /// </summary> + private readonly SimulatorContext dbContext; + + /// <summary> + /// Backing field for the <see cref="Bodies"/> property. + /// </summary> + private IObservableCollection<Body> bodiesObservable; + + /// <summary> + /// Backing field for the <see cref="Systems"/> property. + /// </summary> + private IObservableCollection<StarSimLib.Models.System> systemsObservable; + + /// <summary> + /// Backing field for the <see cref="SelectedBody"/> property. + /// </summary> + public Body selectedBody; + + /// <summary> + /// Backing field for the <see cref="SelectedSystem"/> property. + /// </summary> + public StarSimLib.Models.System selectedSystem; + + /// <summary> + /// Initialises a new instance of the <see cref="ReadSystemsViewModel"/> class. + /// </summary> + public ReadSystemsViewModel() + { + bodiesObservable = new ObservableCollectionExtended<Body>(); + + systemsObservable = new ObservableCollectionExtended<StarSimLib.Models.System>(); + } + + /// <summary> + /// Initialises a new instance of the <see cref="ReadSystemsViewModel"/> class. + /// </summary> + /// <param name="context">The <see cref="SimulatorContext"/> instance in which program data is stored.</param> + public ReadSystemsViewModel(in SimulatorContext context) : this() + { + dbContext = context; + + Bodies.Load(dbContext.Bodies.Include(body => body.BodyToSystemJoins).ThenInclude(join => join.System)); + + Systems.Load(dbContext.Systems.Include(system => system.BodyToSystemJoins).ThenInclude(join => join.Body)); + } + + /// <summary> + /// The bodies held in the database. + /// </summary> + public IObservableCollection<Body> Bodies + { + get + { + return bodiesObservable; + } + set + { + bodiesObservable = value; + this.RaisePropertyChanged(); + } + } + + /// <summary> + /// Whether the currently selected body is null. + /// </summary> + public bool IsSelectedBodyNull + { + get { return SelectedBody == null; } + } + + /// <summary> + /// Whether the currently selected system is null. + /// </summary> + public bool IsSelectedSystemNull + { + get { return SelectedSystem == null; } + } + + /// <summary> + /// The currently selected body from the <see cref="Bodies"/> collection. + /// </summary> + public Body SelectedBody + { + get + { + return selectedBody; + } + set + { + selectedBody = value; + this.RaisePropertyChanged(); + + this.RaisePropertyChanged(nameof(IsSelectedBodyNull)); + } + } + + /// <summary> + /// The currently selected system from the <see cref="Systems"/> collection. + /// </summary> + public StarSimLib.Models.System SelectedSystem + { + get + { + return selectedSystem; + } + set + { + selectedSystem = value; + this.RaisePropertyChanged(); + + this.RaisePropertyChanged(nameof(IsSelectedSystemNull)); + } + } + + /// <summary> + /// The systems held in the database. + /// </summary> + public IObservableCollection<StarSimLib.Models.System> Systems + { + get + { + return systemsObservable; + } + set + { + systemsObservable = value; + this.RaisePropertyChanged(); + } + } + } +} +\ No newline at end of file diff --git a/StarSim/StarSimGui/ViewModels/Database ViewModels/ReadUsersViewModel.cs b/StarSim/StarSimGui/ViewModels/Database ViewModels/ReadUsersViewModel.cs @@ -0,0 +1,146 @@ +using DynamicData.Binding; +using Microsoft.EntityFrameworkCore; +using ReactiveUI; +using StarSimLib.Contexts; +using StarSimLib.Models; + +namespace StarSimGui.ViewModels.Database_ViewModels +{ + /// <summary> + /// Represents the read users view. + /// </summary> + public class ReadUsersViewModel : ViewModelBase + { + /// <summary> + /// The program database. + /// </summary> + private readonly SimulatorContext dbContext; + + /// <summary> + /// Backing field for the <see cref="PublishedSystems"/> property. + /// </summary> + private IObservableCollection<PublishedSystem> publishedSystemsObservable; + + /// <summary> + /// Backing field for the <see cref="Users"/> property. + /// </summary> + private IObservableCollection<User> usersObservable; + + /// <summary> + /// Backing field for the <see cref="SelectedPublishedSystem"/> property. + /// </summary> + public PublishedSystem selectedPublishedSystem; + + /// <summary> + /// Backing field for the <see cref="SelectedUser"/> property. + /// </summary> + public User selectedUser; + + /// <summary> + /// Initialises a new instance of the <see cref="ReadUsersViewModel"/> class. + /// </summary> + public ReadUsersViewModel() + { + publishedSystemsObservable = new ObservableCollectionExtended<PublishedSystem>(); + + usersObservable = new ObservableCollectionExtended<User>(); + } + + /// <summary> + /// Initialises a new instance of the <see cref="ReadUsersViewModel"/> class. + /// </summary> + /// <param name="context">The <see cref="SimulatorContext"/> instance in which program data is stored.</param> + public ReadUsersViewModel(in SimulatorContext context) : this() + { + dbContext = context; + + PublishedSystems.Load(dbContext.PublishedSystems.Include(system => system.System)); + + Users.Load(dbContext.Users.Include(user => user.PublishedSystems).ThenInclude(system => system.System)); + } + + /// <summary> + /// Whether the currently selected published system is null. + /// </summary> + public bool IsSelectedPublishedSystemNull + { + get { return SelectedPublishedSystem == null; } + } + + /// <summary> + /// Whether the currently selected user is null. + /// </summary> + public bool IsSelectedUserNull + { + get { return SelectedUser == null; } + } + + /// <summary> + /// The published systems held in the database. + /// </summary> + public IObservableCollection<PublishedSystem> PublishedSystems + { + get + { + return publishedSystemsObservable; + } + set + { + publishedSystemsObservable = value; + this.RaisePropertyChanged(); + } + } + + /// <summary> + /// The currently selected published system from the <see cref="PublishedSystems"/> collection. + /// </summary> + public PublishedSystem SelectedPublishedSystem + { + get + { + return selectedPublishedSystem; + } + set + { + selectedPublishedSystem = value; + this.RaisePropertyChanged(); + + this.RaisePropertyChanged(nameof(IsSelectedPublishedSystemNull)); + } + } + + /// <summary> + /// The currently selected user from the <see cref="Users"/> collection. + /// </summary> + public User SelectedUser + { + get + { + return selectedUser; + } + set + { + selectedUser = value; + this.RaisePropertyChanged(); + + this.RaisePropertyChanged(nameof(IsSelectedUserNull)); + } + } + + /// <summary> + /// The users held in the database. + /// </summary> + public IObservableCollection<User> Users + { + get + { + return usersObservable; + } + set + { + usersObservable = value; + this.RaisePropertyChanged(); + } + } + } +} +\ No newline at end of file diff --git a/StarSim/StarSimGui/ViewModels/Database ViewModels/SystemReadViewModel.cs b/StarSim/StarSimGui/ViewModels/Database ViewModels/SystemReadViewModel.cs @@ -1,146 +0,0 @@ -using DynamicData.Binding; -using Microsoft.EntityFrameworkCore; -using ReactiveUI; -using StarSimLib.Contexts; -using StarSimLib.Models; - -namespace StarSimGui.ViewModels.Database_ViewModels -{ - /// <summary> - /// Represents the system read view. - /// </summary> - public class SystemReadViewModel : ViewModelBase - { - /// <summary> - /// The program database. - /// </summary> - private readonly SimulatorContext dbContext; - - /// <summary> - /// Backing field for the <see cref="Bodies"/> property. - /// </summary> - private IObservableCollection<Body> bodiesObservable; - - /// <summary> - /// Backing field for the <see cref="Systems"/> property. - /// </summary> - private IObservableCollection<StarSimLib.Models.System> systemsObservable; - - /// <summary> - /// Backing field for the <see cref="SelectedBody"/> property. - /// </summary> - public Body selectedBody; - - /// <summary> - /// Backing field for the <see cref="SelectedSystem"/> property. - /// </summary> - public StarSimLib.Models.System selectedSystem; - - /// <summary> - /// Initialises a new instance of the <see cref="SystemReadViewModel"/> class. - /// </summary> - public SystemReadViewModel() - { - bodiesObservable = new ObservableCollectionExtended<Body>(); - - systemsObservable = new ObservableCollectionExtended<StarSimLib.Models.System>(); - } - - /// <summary> - /// Initialises a new instance of the <see cref="SystemReadViewModel"/> class. - /// </summary> - /// <param name="context">The <see cref="SimulatorContext"/> instance in which program data is stored.</param> - public SystemReadViewModel(in SimulatorContext context) : this() - { - dbContext = context; - - Bodies.Load(dbContext.Bodies.Include(body => body.BodyToSystemJoins).ThenInclude(join => join.System)); - - Systems.Load(dbContext.Systems.Include(system => system.BodyToSystemJoins).ThenInclude(join => join.Body)); - } - - /// <summary> - /// The bodies held in the database. - /// </summary> - public IObservableCollection<Body> Bodies - { - get - { - return bodiesObservable; - } - set - { - bodiesObservable = value; - this.RaisePropertyChanged(); - } - } - - /// <summary> - /// Whether the currently selected body is null. - /// </summary> - public bool IsSelectedBodyNull - { - get { return SelectedBody == null; } - } - - /// <summary> - /// Whether the currently selected system is null. - /// </summary> - public bool IsSelectedSystemNull - { - get { return SelectedSystem == null; } - } - - /// <summary> - /// The currently selected body from the <see cref="Bodies"/> collection. - /// </summary> - public Body SelectedBody - { - get - { - return selectedBody; - } - set - { - selectedBody = value; - this.RaisePropertyChanged(); - - this.RaisePropertyChanged(nameof(IsSelectedBodyNull)); - } - } - - /// <summary> - /// The currently selected system from the <see cref="Systems"/> collection. - /// </summary> - public StarSimLib.Models.System SelectedSystem - { - get - { - return selectedSystem; - } - set - { - selectedSystem = value; - this.RaisePropertyChanged(); - - this.RaisePropertyChanged(nameof(IsSelectedSystemNull)); - } - } - - /// <summary> - /// The systems held in the database. - /// </summary> - public IObservableCollection<StarSimLib.Models.System> Systems - { - get - { - return systemsObservable; - } - set - { - systemsObservable = value; - this.RaisePropertyChanged(); - } - } - } -} -\ No newline at end of file diff --git a/StarSim/StarSimGui/ViewModels/Database ViewModels/UpdateSystemsViewModel.cs b/StarSim/StarSimGui/ViewModels/Database ViewModels/UpdateSystemsViewModel.cs @@ -0,0 +1,31 @@ +using StarSimLib.Contexts; + +namespace StarSimGui.ViewModels.Database_ViewModels +{ + /// <summary> + /// Represents the update systems view. + /// </summary> + public class UpdateSystemsViewModel : ViewModelBase + { + /// <summary> + /// The program database. + /// </summary> + private readonly SimulatorContext dbContext; + + /// <summary> + /// Initialises a new instance of the <see cref="UpdateSystemsViewModel"/> class. + /// </summary> + public UpdateSystemsViewModel() + { + } + + /// <summary> + /// Initialises a new instance of the <see cref="UpdateSystemsViewModel"/> class. + /// </summary> + /// <param name="context">The <see cref="SimulatorContext"/> instance in which program data is stored.</param> + public UpdateSystemsViewModel(in SimulatorContext context) : this() + { + dbContext = context; + } + } +} +\ No newline at end of file diff --git a/StarSim/StarSimGui/ViewModels/Database ViewModels/UpdateUsersViewModel.cs b/StarSim/StarSimGui/ViewModels/Database ViewModels/UpdateUsersViewModel.cs @@ -0,0 +1,31 @@ +using StarSimLib.Contexts; + +namespace StarSimGui.ViewModels.Database_ViewModels +{ + /// <summary> + /// Represents the update users view. + /// </summary> + public class UpdateUsersViewModel : ViewModelBase + { + /// <summary> + /// The program database. + /// </summary> + private readonly SimulatorContext dbContext; + + /// <summary> + /// Initialises a new instance of the <see cref="UpdateUsersViewModel"/> class. + /// </summary> + public UpdateUsersViewModel() + { + } + + /// <summary> + /// Initialises a new instance of the <see cref="UpdateUsersViewModel"/> class. + /// </summary> + /// <param name="context">The <see cref="SimulatorContext"/> instance in which program data is stored.</param> + public UpdateUsersViewModel(in SimulatorContext context) : this() + { + dbContext = context; + } + } +} +\ No newline at end of file diff --git a/StarSim/StarSimGui/ViewModels/Database ViewModels/UserReadViewModel.cs b/StarSim/StarSimGui/ViewModels/Database ViewModels/UserReadViewModel.cs @@ -1,146 +0,0 @@ -using DynamicData.Binding; -using Microsoft.EntityFrameworkCore; -using ReactiveUI; -using StarSimLib.Contexts; -using StarSimLib.Models; - -namespace StarSimGui.ViewModels.Database_ViewModels -{ - /// <summary> - /// Represents the user read view. - /// </summary> - public class UserReadViewModel : ViewModelBase - { - /// <summary> - /// The program database. - /// </summary> - private readonly SimulatorContext dbContext; - - /// <summary> - /// Backing field for the <see cref="PublishedSystems"/> property. - /// </summary> - private IObservableCollection<PublishedSystem> publishedSystemsObservable; - - /// <summary> - /// Backing field for the <see cref="Users"/> property. - /// </summary> - private IObservableCollection<User> usersObservable; - - /// <summary> - /// Backing field for the <see cref="SelectedPublishedSystem"/> property. - /// </summary> - public PublishedSystem selectedPublishedSystem; - - /// <summary> - /// Backing field for the <see cref="SelectedUser"/> property. - /// </summary> - public User selectedUser; - - /// <summary> - /// Initialises a new instance of the <see cref="UserReadViewModel"/> class. - /// </summary> - public UserReadViewModel() - { - publishedSystemsObservable = new ObservableCollectionExtended<PublishedSystem>(); - - usersObservable = new ObservableCollectionExtended<User>(); - } - - /// <summary> - /// Initialises a new instance of the <see cref="UserReadViewModel"/> class. - /// </summary> - /// <param name="context">The <see cref="SimulatorContext"/> instance in which program data is stored.</param> - public UserReadViewModel(in SimulatorContext context) : this() - { - dbContext = context; - - PublishedSystems.Load(dbContext.PublishedSystems.Include(system => system.System)); - - Users.Load(dbContext.Users.Include(user => user.PublishedSystems).ThenInclude(system => system.System)); - } - - /// <summary> - /// Whether the currently selected published system is null. - /// </summary> - public bool IsSelectedPublishedSystemNull - { - get { return SelectedPublishedSystem == null; } - } - - /// <summary> - /// Whether the currently selected user is null. - /// </summary> - public bool IsSelectedUserNull - { - get { return SelectedUser == null; } - } - - /// <summary> - /// The published systems held in the database. - /// </summary> - public IObservableCollection<PublishedSystem> PublishedSystems - { - get - { - return publishedSystemsObservable; - } - set - { - publishedSystemsObservable = value; - this.RaisePropertyChanged(); - } - } - - /// <summary> - /// The currently selected published system from the <see cref="PublishedSystems"/> collection. - /// </summary> - public PublishedSystem SelectedPublishedSystem - { - get - { - return selectedPublishedSystem; - } - set - { - selectedPublishedSystem = value; - this.RaisePropertyChanged(); - - this.RaisePropertyChanged(nameof(IsSelectedPublishedSystemNull)); - } - } - - /// <summary> - /// The currently selected user from the <see cref="Users"/> collection. - /// </summary> - public User SelectedUser - { - get - { - return selectedUser; - } - set - { - selectedUser = value; - this.RaisePropertyChanged(); - - this.RaisePropertyChanged(nameof(IsSelectedUserNull)); - } - } - - /// <summary> - /// The users held in the database. - /// </summary> - public IObservableCollection<User> Users - { - get - { - return usersObservable; - } - set - { - usersObservable = value; - this.RaisePropertyChanged(); - } - } - } -} -\ No newline at end of file diff --git a/StarSim/StarSimGui/ViewModels/DatabaseViewModel.cs b/StarSim/StarSimGui/ViewModels/DatabaseViewModel.cs @@ -15,19 +15,49 @@ namespace StarSimGui.ViewModels public class DatabaseViewModel : ViewModelBase { /// <summary> + /// Represents the create systems view. + /// </summary> + private readonly CreateSystemsViewModel createSystemsViewModel; + + /// <summary> + /// Represents the create users view. + /// </summary> + private readonly CreateUsersViewModel createUsersViewModel; + + /// <summary> /// The program database. /// </summary> private readonly SimulatorContext dbContext; /// <summary> - /// Represents the system read view. + /// Represents the delete systems view. + /// </summary> + private readonly DeleteSystemsViewModel deleteSystemsViewModel; + + /// <summary> + /// Represents the delete users view. + /// </summary> + private readonly DeleteUsersViewModel deleteUsersViewModel; + + /// <summary> + /// Represents the read systems view. + /// </summary> + private readonly ReadSystemsViewModel readSystemsViewModel; + + /// <summary> + /// Represents the read users view. /// </summary> - private readonly SystemReadViewModel systemReadViewModel; + private readonly ReadUsersViewModel readUsersViewModel; /// <summary> - /// Represents the user read view. + /// Represents the update systems view. /// </summary> - private readonly UserReadViewModel userReadViewModel; + private readonly UpdateSystemsViewModel updateSystemsViewModel; + + /// <summary> + /// Represents the update users view. + /// </summary> + private readonly UpdateUsersViewModel updateUsersViewModel; /// <summary> /// The currently logged in user. @@ -39,9 +69,21 @@ namespace StarSimGui.ViewModels /// </summary> public DatabaseViewModel() { - userReadViewModel = new UserReadViewModel(); + createSystemsViewModel = new CreateSystemsViewModel(); + + createUsersViewModel = new CreateUsersViewModel(); + + deleteSystemsViewModel = new DeleteSystemsViewModel(); + + deleteUsersViewModel = new DeleteUsersViewModel(); + + readSystemsViewModel = new ReadSystemsViewModel(); + + readUsersViewModel = new ReadUsersViewModel(); - systemReadViewModel = new SystemReadViewModel(); + updateSystemsViewModel = new UpdateSystemsViewModel(); + + updateUsersViewModel = new UpdateUsersViewModel(); } /// <summary> @@ -52,9 +94,21 @@ namespace StarSimGui.ViewModels { dbContext = context; - userReadViewModel = new UserReadViewModel(in context); + createSystemsViewModel = new CreateSystemsViewModel(in context); + + createUsersViewModel = new CreateUsersViewModel(in context); + + deleteSystemsViewModel = new DeleteSystemsViewModel(in context); + + deleteUsersViewModel = new DeleteUsersViewModel(in context); + + readSystemsViewModel = new ReadSystemsViewModel(in context); + + readUsersViewModel = new ReadUsersViewModel(in context); + + updateSystemsViewModel = new UpdateSystemsViewModel(in context); - systemReadViewModel = new SystemReadViewModel(in context); + updateUsersViewModel = new UpdateUsersViewModel(in context); } /// <summary> @@ -85,7 +139,7 @@ namespace StarSimGui.ViewModels /// </summary> public bool IsAdmin { - get { return (currentUser.Privileges & UserPrivileges.Admin) == UserPrivileges.Admin; } + get { return (currentUser?.Privileges & UserPrivileges.Admin) == UserPrivileges.Admin; } } /// <summary> @@ -105,19 +159,19 @@ namespace StarSimGui.ViewModels } /// <summary> - /// Exposes the <see cref="systemReadViewModel"/> field to the view. + /// Exposes the <see cref="readSystemsViewModel"/> field to the view. /// </summary> - public SystemReadViewModel SystemReadViewModel + public ReadSystemsViewModel ReadSystemsViewModel { - get { return systemReadViewModel; } + get { return readSystemsViewModel; } } /// <summary> - /// Exposes the <see cref="userReadViewModel"/> field to the view. + /// Exposes the <see cref="readUsersViewModel"/> field to the view. /// </summary> - public UserReadViewModel UserReadViewModel + public ReadUsersViewModel ReadUsersViewModel { - get { return userReadViewModel; } + get { return readUsersViewModel; } } /// <summary> diff --git a/StarSim/StarSimGui/Views/Database Views/CreateSystems.xaml b/StarSim/StarSimGui/Views/Database Views/CreateSystems.xaml @@ -0,0 +1,18 @@ +<UserControl xmlns="https://github.com/avaloniaui" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:vm="clr-namespace:StarSimGui.ViewModels.Database_ViewModels;assembly=StarSimGui" + xmlns:v="clr-namespace:StarSimGui.Views;assembly=StarSimGui" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + mc:Ignorable="d" + x:Class="StarSimGui.Views.Database_Views.CreateSystems"> + + <Design.DataContext> + <vm:CreateSystemsViewModel /> + </Design.DataContext> + + <Border BorderBrush="Gray" BorderThickness="2" CornerRadius="2" Margin="2"> + <Grid ColumnDefinitions="*,*,*,*" RowDefinitions="*,*,*,*"> + </Grid> + </Border> +</UserControl> +\ No newline at end of file diff --git a/StarSim/StarSimGui/Views/Database Views/CreateSystems.xaml.cs b/StarSim/StarSimGui/Views/Database Views/CreateSystems.xaml.cs @@ -0,0 +1,19 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace StarSimGui.Views.Database_Views +{ + public class CreateSystems : UserControl + { + public CreateSystems() + { + this.InitializeComponent(); + } + + private void InitializeComponent() + { + AvaloniaXamlLoader.Load(this); + } + } +} diff --git a/StarSim/StarSimGui/Views/Database Views/CreateUsers.xaml b/StarSim/StarSimGui/Views/Database Views/CreateUsers.xaml @@ -0,0 +1,18 @@ +<UserControl xmlns="https://github.com/avaloniaui" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:vm="clr-namespace:StarSimGui.ViewModels.Database_ViewModels;assembly=StarSimGui" + xmlns:v="clr-namespace:StarSimGui.Views;assembly=StarSimGui" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + mc:Ignorable="d" + x:Class="StarSimGui.Views.Database_Views.CreateUser"> + +<Design.DataContext> +<vm:CreateUsersViewModel /> +</Design.DataContext> + +<Border BorderBrush="Gray" BorderThickness="2" CornerRadius="2" Margin="2"> + <Grid ColumnDefinitions="*,*,*,*" RowDefinitions="*,*,*,*"> + </Grid> + </Border> +</UserControl> +\ No newline at end of file diff --git a/StarSim/StarSimGui/Views/Database Views/CreateUsers.xaml.cs b/StarSim/StarSimGui/Views/Database Views/CreateUsers.xaml.cs @@ -0,0 +1,19 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace StarSimGui.Views.Database_Views +{ + public class CreateUsers : UserControl + { + public CreateUsers() + { + this.InitializeComponent(); + } + + private void InitializeComponent() + { + AvaloniaXamlLoader.Load(this); + } + } +} +\ No newline at end of file diff --git a/StarSim/StarSimGui/Views/Database Views/DeleteSystems.xaml b/StarSim/StarSimGui/Views/Database Views/DeleteSystems.xaml @@ -0,0 +1,18 @@ +<UserControl xmlns="https://github.com/avaloniaui" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:vm="clr-namespace:StarSimGui.ViewModels.Database_ViewModels;assembly=StarSimGui" + xmlns:v="clr-namespace:StarSimGui.Views;assembly=StarSimGui" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + mc:Ignorable="d" + x:Class="StarSimGui.Views.Database_Views.DeleteSystems"> + + <Design.DataContext> + <vm:DeleteSystemsViewModel /> + </Design.DataContext> + + <Border BorderBrush="Gray" BorderThickness="2" CornerRadius="2" Margin="2"> + <Grid ColumnDefinitions="*,*,*,*" RowDefinitions="*,*,*,*"> + </Grid> + </Border> +</UserControl> +\ No newline at end of file diff --git a/StarSim/StarSimGui/Views/Database Views/DeleteSystems.xaml.cs b/StarSim/StarSimGui/Views/Database Views/DeleteSystems.xaml.cs @@ -0,0 +1,19 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace StarSimGui.Views.Database_Views +{ + public class DeleteSystems : UserControl + { + public DeleteSystems() + { + this.InitializeComponent(); + } + + private void InitializeComponent() + { + AvaloniaXamlLoader.Load(this); + } + } +} diff --git a/StarSim/StarSimGui/Views/Database Views/DeleteUsers.xaml b/StarSim/StarSimGui/Views/Database Views/DeleteUsers.xaml @@ -0,0 +1,18 @@ +<UserControl xmlns="https://github.com/avaloniaui" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:vm="clr-namespace:StarSimGui.ViewModels.Database_ViewModels;assembly=StarSimGui" + xmlns:v="clr-namespace:StarSimGui.Views;assembly=StarSimGui" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + mc:Ignorable="d" + x:Class="StarSimGui.Views.Database_Views.DeleteUsers"> + + <Design.DataContext> + <vm:DeleteUsersViewModel /> + </Design.DataContext> + + <Border BorderBrush="Gray" BorderThickness="2" CornerRadius="2" Margin="2"> + <Grid ColumnDefinitions="*,*,*,*" RowDefinitions="*,*,*,*"> + </Grid> + </Border> +</UserControl> +\ No newline at end of file diff --git a/StarSim/StarSimGui/Views/Database Views/DeleteUsers.xaml.cs b/StarSim/StarSimGui/Views/Database Views/DeleteUsers.xaml.cs @@ -0,0 +1,19 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace StarSimGui.Views.Database_Views +{ + public class DeleteUsers : UserControl + { + public DeleteUsers() + { + this.InitializeComponent(); + } + + private void InitializeComponent() + { + AvaloniaXamlLoader.Load(this); + } + } +} diff --git a/StarSim/StarSimGui/Views/Database Views/ReadSystems.xaml b/StarSim/StarSimGui/Views/Database Views/ReadSystems.xaml @@ -9,7 +9,7 @@ Background="WhiteSmoke"> <Design.DataContext> - <vm:SystemReadViewModel /> + <vm:ReadSystemsViewModel /> </Design.DataContext> <Border BorderBrush="Gray" BorderThickness="2" CornerRadius="2" Margin="2"> diff --git a/StarSim/StarSimGui/Views/Database Views/ReadUsers.xaml b/StarSim/StarSimGui/Views/Database Views/ReadUsers.xaml @@ -9,7 +9,7 @@ Background="WhiteSmoke"> <Design.DataContext> - <vm:UserReadViewModel /> + <vm:ReadUsersViewModel /> </Design.DataContext> <Border BorderBrush="Gray" BorderThickness="2" CornerRadius="2" Margin="2"> diff --git a/StarSim/StarSimGui/Views/Database Views/UpdateSystems.xaml b/StarSim/StarSimGui/Views/Database Views/UpdateSystems.xaml @@ -0,0 +1,18 @@ +<UserControl xmlns="https://github.com/avaloniaui" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:vm="clr-namespace:StarSimGui.ViewModels.Database_ViewModels;assembly=StarSimGui" + xmlns:v="clr-namespace:StarSimGui.Views;assembly=StarSimGui" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + mc:Ignorable="d" + x:Class="StarSimGui.Views.Database_Views.UpdateSystems"> + + <Design.DataContext> + <vm:UpdateSystemsViewModel /> + </Design.DataContext> + + <Border BorderBrush="Gray" BorderThickness="2" CornerRadius="2" Margin="2"> + <Grid ColumnDefinitions="*,*,*,*" RowDefinitions="*,*,*,*"> + </Grid> + </Border> +</UserControl> +\ No newline at end of file diff --git a/StarSim/StarSimGui/Views/Database Views/UpdateSystems.xaml.cs b/StarSim/StarSimGui/Views/Database Views/UpdateSystems.xaml.cs @@ -0,0 +1,19 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace StarSimGui.Views.Database_Views +{ + public class UpdateSystems : UserControl + { + public UpdateSystems() + { + this.InitializeComponent(); + } + + private void InitializeComponent() + { + AvaloniaXamlLoader.Load(this); + } + } +} diff --git a/StarSim/StarSimGui/Views/Database Views/UpdateUsers.xaml b/StarSim/StarSimGui/Views/Database Views/UpdateUsers.xaml @@ -0,0 +1,18 @@ +<UserControl xmlns="https://github.com/avaloniaui" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:vm="clr-namespace:StarSimGui.ViewModels.Database_ViewModels;assembly=StarSimGui" + xmlns:v="clr-namespace:StarSimGui.Views;assembly=StarSimGui" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + mc:Ignorable="d" + x:Class="StarSimGui.Views.Database_Views.UpdateUsers"> + + <Design.DataContext> + <vm:UpdateUsersViewModel /> + </Design.DataContext> + + <Border BorderBrush="Gray" BorderThickness="2" CornerRadius="2" Margin="2"> + <Grid ColumnDefinitions="*,*,*,*" RowDefinitions="*,*,*,*"> + </Grid> + </Border> +</UserControl> +\ No newline at end of file diff --git a/StarSim/StarSimGui/Views/Database Views/UpdateUsers.xaml.cs b/StarSim/StarSimGui/Views/Database Views/UpdateUsers.xaml.cs @@ -0,0 +1,19 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace StarSimGui.Views.Database_Views +{ + public class UpdateUsers : UserControl + { + public UpdateUsers() + { + this.InitializeComponent(); + } + + private void InitializeComponent() + { + AvaloniaXamlLoader.Load(this); + } + } +} diff --git a/StarSim/StarSimGui/Views/Database.xaml b/StarSim/StarSimGui/Views/Database.xaml @@ -16,46 +16,28 @@ <Border BorderBrush="Gray" BorderThickness="2" CornerRadius="2" Margin="2"> <TabControl> <TabItem Header="Create Users" IsVisible="{Binding IsAdmin}"> - <Border BorderBrush="Gray" BorderThickness="2" CornerRadius="2" Margin="2"> - <Grid ColumnDefinitions="*,*,*,*" RowDefinitions="*,*,*,*"> - </Grid> - </Border> + <subviews:CreateUsers DataContext="{Binding}" /> </TabItem> <TabItem Header="Create Bodies/Systems" IsVisible="{Binding IsPublisher}"> - <Border BorderBrush="Gray" BorderThickness="2" CornerRadius="2" Margin="2"> - <Grid ColumnDefinitions="*,*,*,*" RowDefinitions="*,*,*,*"> - </Grid> - </Border> + <subviews:CreateSystems DataContext="{Binding}" /> </TabItem> <TabItem Header="View Users" IsVisible="{Binding IsDefault}"> - <subviews:ReadUsers DataContext="{Binding UserReadViewModel}" /> + <subviews:ReadUsers DataContext="{Binding ReadUsersViewModel}" /> </TabItem> <TabItem Header="View Bodies/Systems" IsVisible="{Binding IsDefault}"> - <subviews:ReadSystems DataContext="{Binding SystemReadViewModel}" /> + <subviews:ReadSystems DataContext="{Binding ReadSystemsViewModel}" /> </TabItem> <TabItem Header="Update Users" IsVisible="{Binding IsAdmin}"> - <Border BorderBrush="Gray" BorderThickness="2" CornerRadius="2" Margin="2"> - <Grid ColumnDefinitions="*,*,*,*" RowDefinitions="*,*,*,*"> - </Grid> - </Border> + <subviews:UpdateUsers DataContext="{Binding}" /> </TabItem> <TabItem Header="Update Bodies/Systems" IsVisible="{Binding IsPublisher}"> - <Border BorderBrush="Gray" BorderThickness="2" CornerRadius="2" Margin="2"> - <Grid ColumnDefinitions="*,*,*,*" RowDefinitions="*,*,*,*"> - </Grid> - </Border> + <subviews:UpdateSystems DataContext="{Binding}" /> </TabItem> <TabItem Header="Delete Users" IsVisible="{Binding IsAdmin}"> - <Border BorderBrush="Gray" BorderThickness="2" CornerRadius="2" Margin="2"> - <Grid ColumnDefinitions="*,*,*,*" RowDefinitions="*,*,*,*"> - </Grid> - </Border> + <subviews:DeleteUsers DataContext="{Binding}" /> </TabItem> <TabItem Header="Delete Bodies/Systems" IsVisible="{Binding IsPublisher}"> - <Border BorderBrush="Gray" BorderThickness="2" CornerRadius="2" Margin="2"> - <Grid ColumnDefinitions="*,*,*,*" RowDefinitions="*,*,*,*"> - </Grid> - </Border> + <subviews:DeleteSystems DataContext="{Binding}" /> </TabItem> </TabControl> </Border>