Refactoring durchgeführt

This commit is contained in:
HuskyTeufel
2021-09-14 17:08:06 +02:00
parent 6b2ed0d5ab
commit 8eccf7c478
24 changed files with 430 additions and 57 deletions

View File

@@ -4,6 +4,9 @@ using DaSaSo.Domain.Services.ClientServices;
using DaSaSo.EntityFramework;
using DaSaSo.EntityFramework.Services;
using DaSaSo.ViewModel;
using DaSaSo.ViewModel.Factories;
using DaSaSo.ViewModel.Interface;
using DaSaSo.ViewModel.State.Navigation;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
@@ -23,19 +26,27 @@ namespace DaSaSo.Wpf
protected override async void OnStartup(StartupEventArgs e)
{
IServiceProvider serviceProvider = CreateServiceProvider();
IDataService<Client> clientService = new ClientDataService(new DaSaSoDbContextFactory());
var d = await clientService.GetAll();
base.OnStartup(e);
MainWindow? window = new MainWindow() { DataContext = new MainWindowViewModel() };
MainWindow? window = new MainWindow() { DataContext = serviceProvider.GetRequiredService<MainWindowViewModel>() };
window.Show();
base.OnStartup(e);
}
private IServiceProvider CreateServiceProvider()
{
IServiceCollection services = new ServiceCollection();
services.AddSingleton<DaSaSoDbContext>();
//services.AddSingleton<IDataService<Client>, ClientDataService>();
services.AddSingleton<DaSaSoDbContextFactory>();
services.AddSingleton<IDataService<Client>, ClientDataService>();
services.AddSingleton<IViewModelAbstractFactory, ViewModelAbstractFactory>();
services.AddSingleton<IViewModelFactory<HomeViewModel>, HomeViewModelFactory>();
services.AddSingleton<IViewModelFactory<ClientListViewModel>, ClientListViewModelFactory>();
services.AddScoped<INavigator, Navigator>();
services.AddScoped<MainWindowViewModel>();
return services.BuildServiceProvider();
}

View File

@@ -0,0 +1,22 @@
<UserControl x:Class="DaSaSo.Wpf.Controls.NavigationBar"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:DaSaSo.Wpf.Controls"
xmlns:nav="clr-namespace:DaSaSo.ViewModel.Enums;assembly=DaSaSo.ViewModel"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<RadioButton Grid.Row="0" Content="Kunden" Style="{StaticResource ToggleButtonList}" Command="{Binding UpdateViewModelCommand}" CommandParameter="{x:Static nav:EViewType.Clients}" />
<RadioButton Grid.Row="1" Content="Projekte" Style="{StaticResource ToggleButtonList}" Command="{Binding UpdateViewModelCommand}" CommandParameter="{x:Static nav:EViewType.Projects}" />
<RadioButton Grid.Row="2" Content="Baustellen" Style="{StaticResource ToggleButtonList}" Command="{Binding UpdateViewModelCommand}" CommandParameter="{x:Static nav:EViewType.Buildingsites}" />
<RadioButton Grid.Row="3" Content="Objekten" Style="{StaticResource ToggleButtonList}" Command="{Binding UpdateViewModelCommand}" CommandParameter="{x:Static nav:EViewType.SewerObjects}" />
</Grid>
</UserControl>

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace DaSaSo.Wpf.Controls
{
/// <summary>
/// Interaction logic for NavigationBar.xaml
/// </summary>
public partial class NavigationBar : UserControl
{
public NavigationBar()
{
InitializeComponent();
}
}
}

View File

@@ -7,26 +7,41 @@
</ApplicationDefinition>
</ItemGroup>
<ItemGroup>
<Compile Update="Controls\NavigationBar.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="View\Client\ClientEditView.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="View\Client\ClientListView.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="View\HomeView.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="View\Project\ProjectListView.xaml.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Page Update="Controls\NavigationBar.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="my_controls.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Styles\Navigation_Style.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="View\Client\ClientEditView.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="View\Client\ClientListView.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="View\HomeView.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="View\Project\ProjectListView.xaml">
<SubType>Designer</SubType>
</Page>

View File

@@ -0,0 +1,4 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
</ResourceDictionary>

View File

@@ -0,0 +1,12 @@
<UserControl x:Class="DaSaSo.Wpf.View.HomeView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:DaSaSo.Wpf.View" xmlns:viewmodel="clr-namespace:DaSaSo.ViewModel;assembly=DaSaSo.ViewModel" d:DataContext="{d:DesignInstance Type=viewmodel:HomeViewModel}"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<TextBlock Text="{Binding Welcome }" />
</Grid>
</UserControl>

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace DaSaSo.Wpf.View
{
/// <summary>
/// Interaction logic for HomeView.xaml
/// </summary>
public partial class HomeView : UserControl
{
public HomeView()
{
InitializeComponent();
}
}
}

View File

@@ -5,6 +5,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ClientViews="clr-namespace:DaSaSo.Wpf.View.Client"
xmlns:ProjektViews="clr-namespace:DaSaSo.Wpf.View.Project"
xmlns:controls="clr-namespace:DaSaSo.Wpf.Controls"
xmlns:View="clr-namespace:DaSaSo.Wpf.View"
xmlns:local="clr-namespace:DaSaSo.Wpf" xmlns:viewmodel="clr-namespace:DaSaSo.ViewModel;assembly=DaSaSo.ViewModel" d:DataContext="{d:DesignInstance Type=viewmodel:MainWindowViewModel}"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
@@ -18,6 +20,9 @@
<DataTemplate DataType="{x:Type viewmodel:ProjectListViewModel}">
<ProjektViews:ProjectListView />
</DataTemplate>
<DataTemplate DataType="{x:Type viewmodel:HomeViewModel}">
<View:HomeView />
</DataTemplate>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
@@ -28,13 +33,8 @@
<RowDefinition />
<RowDefinition Height="20" />
</Grid.RowDefinitions>
<StackPanel Grid.Column="0" Grid.Row="0">
<RadioButton Content="Kunden" Style="{StaticResource ToggleButtonList}" Command="{Binding ListClientsCommand}" />
<RadioButton Content="Projekte" Style="{StaticResource ToggleButtonList}" Command="{Binding ListProjectCommand}" />
<RadioButton Content="Baustellen" Style="{StaticResource ToggleButtonList}" Command="{Binding ListBuildingsiteCommand}" />
<RadioButton Content="Objekte" Style="{StaticResource ToggleButtonList}" Command="{Binding ListSewerObjectsCommand}" />
</StackPanel>
<ContentControl Grid.Column="1" Grid.Row="0" Content="{Binding ActualViewModel}" />
<controls:NavigationBar Grid.Column="0" Grid.Row="0" DataContext="{Binding Navigator }" />
<ContentControl Grid.Column="1" Grid.Row="0" Content="{Binding Navigator.CurrentViewModel}" />
<StatusBar Grid.Row="1" Grid.ColumnSpan="2">
<StatusBarItem Content="{Binding SelectedClient.Firstname}" />
</StatusBar>