From 6cf888c5e3d207f3d8c3c8053b862ade7b5ee9e4 Mon Sep 17 00:00:00 2001 From: HuskyTeufel Date: Fri, 15 Oct 2021 10:43:47 +0200 Subject: [PATCH] =?UTF-8?q?Impr=C3=A4gnierungsliste=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DaSaSo.Domain/Enums/EMainWindowViewType.cs | 3 +- .../Services/ImpregnationDataService.cs | 56 +++++++++++++++++++ .../Factories/MainWindowViewModelFactory.cs | 11 +++- .../ImpregnierungListViewModel.cs | 53 ++++++++++++++++++ DaSaSo.ViewModel/SewerMainListViewModel.cs | 2 +- .../Controls/MainWindowNavigationBar.xaml | 7 ++- DaSaSo.Wpf/DaSaSo.Wpf.csproj.user | 6 ++ .../AddServicesHostBuilderExtensions.cs | 1 + .../AddViewModelsHostBuilderExtensions.cs | 8 +++ .../Impregnation/ImpregnationListView.xaml | 12 ++++ .../Impregnation/ImpregnationListView.xaml.cs | 28 ++++++++++ DaSaSo.Wpf/Window/MainWindow.xaml | 4 ++ 12 files changed, 184 insertions(+), 7 deletions(-) create mode 100644 DaSaSo.EntityFramework/Services/ImpregnationDataService.cs create mode 100644 DaSaSo.ViewModel/ImpregnierungListViewModel.cs create mode 100644 DaSaSo.Wpf/View/Impregnation/ImpregnationListView.xaml create mode 100644 DaSaSo.Wpf/View/Impregnation/ImpregnationListView.xaml.cs diff --git a/DaSaSo.Domain/Enums/EMainWindowViewType.cs b/DaSaSo.Domain/Enums/EMainWindowViewType.cs index 53140ca..a4c83a0 100644 --- a/DaSaSo.Domain/Enums/EMainWindowViewType.cs +++ b/DaSaSo.Domain/Enums/EMainWindowViewType.cs @@ -8,6 +8,7 @@ Projects, Buildingsites, SewerObjects, - SewerMainMenu + SewerMainMenu, + Impregnierung } } diff --git a/DaSaSo.EntityFramework/Services/ImpregnationDataService.cs b/DaSaSo.EntityFramework/Services/ImpregnationDataService.cs new file mode 100644 index 0000000..caf2d50 --- /dev/null +++ b/DaSaSo.EntityFramework/Services/ImpregnationDataService.cs @@ -0,0 +1,56 @@ +using DaSaSo.Domain.Model; +using DaSaSo.Domain.Services; +using DaSaSo.EntityFramework.Services.Common; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DaSaSo.EntityFramework.Services +{ + public class ImpregnationDataService : IDataService + { + private readonly DaSaSoDbContextFactory _contextFactory; + private readonly NonQueryDataService _nonQueryDataService; + + public ImpregnationDataService(DaSaSoDbContextFactory contextFactory) + { + _contextFactory = contextFactory; + _nonQueryDataService = new NonQueryDataService(contextFactory); + } + + public async Task Create(Impregnation entity) + { + return await _nonQueryDataService.Create(entity); + } + + public Impregnation CreateNonAsync(Impregnation entity) + { + throw new NotImplementedException(); + } + + public async Task Delete(int id) + { + return await _nonQueryDataService.Delete(id); + } + + public Task Get(int id) + { + throw new NotImplementedException(); + } + + public async Task> GetAll() + { + using DaSaSoDbContext context = _contextFactory.CreateDbContext(); + IEnumerable entities = await context.Impregnations.ToListAsync(); + return entities; + } + + public Task Update(int id, Impregnation entity) + { + return _nonQueryDataService.Update(id, entity); + } + } +} diff --git a/DaSaSo.ViewModel/Factories/MainWindowViewModelFactory.cs b/DaSaSo.ViewModel/Factories/MainWindowViewModelFactory.cs index 11e4bbb..2585635 100644 --- a/DaSaSo.ViewModel/Factories/MainWindowViewModelFactory.cs +++ b/DaSaSo.ViewModel/Factories/MainWindowViewModelFactory.cs @@ -13,6 +13,7 @@ namespace DaSaSo.ViewModel.Factories private CreateViewModel _createBuildingsiteListViewModel; private CreateViewModel _createSewerObjectListViewModel; private CreateViewModel _createSewerMainMenuListViewModel; + private CreateViewModel _createImpregnierungListViewModel; public MainWindowViewModelFactory( CreateViewModel createHomeViewModel, @@ -21,7 +22,8 @@ namespace DaSaSo.ViewModel.Factories CreateViewModel createProjektListViewModel, CreateViewModel createBuildingsiteListViewModel, CreateViewModel createSewerObjectListViewModel, - CreateViewModel createSewerMainMenuListViewModel + CreateViewModel createSewerMainMenuListViewModel, + CreateViewModel createImpregnierungListViewModel ) { _createHomeViewModel = createHomeViewModel; @@ -31,6 +33,8 @@ namespace DaSaSo.ViewModel.Factories _createBuildingsiteListViewModel = createBuildingsiteListViewModel; _createSewerObjectListViewModel = createSewerObjectListViewModel; _createSewerMainMenuListViewModel = createSewerMainMenuListViewModel; + _createImpregnierungListViewModel = createImpregnierungListViewModel; + } public BaseViewModel CreateViewModel(EMainWindowViewType viewType) @@ -52,7 +56,10 @@ namespace DaSaSo.ViewModel.Factories return _createSewerObjectListViewModel(); case EMainWindowViewType.SewerMainMenu: return _createSewerMainMenuListViewModel(); - + case EMainWindowViewType.Impregnierung: + return _createImpregnierungListViewModel(); + + default: throw new ArgumentException("The Viewtype does not have a ViewModel.", "viewType"); } diff --git a/DaSaSo.ViewModel/ImpregnierungListViewModel.cs b/DaSaSo.ViewModel/ImpregnierungListViewModel.cs new file mode 100644 index 0000000..0517840 --- /dev/null +++ b/DaSaSo.ViewModel/ImpregnierungListViewModel.cs @@ -0,0 +1,53 @@ +using DaSaSo.Domain.Model; +using DaSaSo.Domain.Services; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DaSaSo.ViewModel +{ + public class ImpregnierungListViewModel : BaseViewModel + { + public ObservableCollection Impregnations; + private readonly IDataService _impregnationService; + bool _isLoading; + + public bool IsLoading { + get => _isLoading; + set + { + if(_isLoading != value) + { + _isLoading = value; + OnPropertyChanged(); + } + } + } + + public ImpregnierungListViewModel(IDataService impregnationService) + { + IsLoading = true; + Impregnations = new ObservableCollection(); + _impregnationService = impregnationService; + LoadImpregnations(); + + } + + private async void LoadImpregnations() + { + var impregList = await _impregnationService.GetAll(); + InitCollection(Impregnations, impregList); + IsLoading = false; + } + + private void InitCollection(ObservableCollection target, IEnumerable source) + { + target.Clear(); + foreach (var i in source) + target.Add(i); + } + } +} diff --git a/DaSaSo.ViewModel/SewerMainListViewModel.cs b/DaSaSo.ViewModel/SewerMainListViewModel.cs index b0db390..b170014 100644 --- a/DaSaSo.ViewModel/SewerMainListViewModel.cs +++ b/DaSaSo.ViewModel/SewerMainListViewModel.cs @@ -24,7 +24,7 @@ namespace DaSaSo.ViewModel private IActualProject ActualProject { get; set; } public ICommand UpdateCurrentSewerViewModelCommand { get; } public ICommand CloseCommand { get; set; } - public ICommand SchadenCommand { get; set; } + // public ICommand SchadenCommand { get; set; } public ICommand Schlauchliner { get; set; } public BaseViewModel CurrentSewerViewModel => Navigator.CurrentViewModel; diff --git a/DaSaSo.Wpf/Controls/MainWindowNavigationBar.xaml b/DaSaSo.Wpf/Controls/MainWindowNavigationBar.xaml index 33a6fb9..1c237e0 100644 --- a/DaSaSo.Wpf/Controls/MainWindowNavigationBar.xaml +++ b/DaSaSo.Wpf/Controls/MainWindowNavigationBar.xaml @@ -10,7 +10,7 @@ xmlns:converters="clr-namespace:DaSaSo.Wpf.Converters" d:DataContext="{d:DesignInstance Type=viewmodel:MainWindowViewModel}" mc:Ignorable="d" - d:DesignHeight="300" d:DesignWidth="200"> + d:DesignHeight="375" d:DesignWidth="200"> @@ -21,13 +21,14 @@ + - - + + diff --git a/DaSaSo.Wpf/DaSaSo.Wpf.csproj.user b/DaSaSo.Wpf/DaSaSo.Wpf.csproj.user index 993faf3..5ab348d 100644 --- a/DaSaSo.Wpf/DaSaSo.Wpf.csproj.user +++ b/DaSaSo.Wpf/DaSaSo.Wpf.csproj.user @@ -28,6 +28,9 @@ Code + + Code + Code @@ -90,6 +93,9 @@ Designer + + Designer + Designer diff --git a/DaSaSo.Wpf/HostBuilders/AddServicesHostBuilderExtensions.cs b/DaSaSo.Wpf/HostBuilders/AddServicesHostBuilderExtensions.cs index 4604c9f..09cf30d 100644 --- a/DaSaSo.Wpf/HostBuilders/AddServicesHostBuilderExtensions.cs +++ b/DaSaSo.Wpf/HostBuilders/AddServicesHostBuilderExtensions.cs @@ -26,6 +26,7 @@ namespace DaSaSo.Wpf.HostBuilders services.AddTransient, BuildingsiteDataService>(); services.AddSingleton, SewerObjectDataService>(); services.AddSingleton, SewerpointDataService>(); + services.AddSingleton, ImpregnationDataService>(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); diff --git a/DaSaSo.Wpf/HostBuilders/AddViewModelsHostBuilderExtensions.cs b/DaSaSo.Wpf/HostBuilders/AddViewModelsHostBuilderExtensions.cs index 3be7716..d9222c6 100644 --- a/DaSaSo.Wpf/HostBuilders/AddViewModelsHostBuilderExtensions.cs +++ b/DaSaSo.Wpf/HostBuilders/AddViewModelsHostBuilderExtensions.cs @@ -66,6 +66,14 @@ namespace DaSaSo.Wpf.HostBuilders { return () => new HomeViewModel(); }); + + services.AddSingleton>(services => + { + return () => new ImpregnierungListViewModel( + services.GetRequiredService>() + ); + }); + services.AddTransient>(services => { return () => new SewerStammdatenViewModel( diff --git a/DaSaSo.Wpf/View/Impregnation/ImpregnationListView.xaml b/DaSaSo.Wpf/View/Impregnation/ImpregnationListView.xaml new file mode 100644 index 0000000..906bbb9 --- /dev/null +++ b/DaSaSo.Wpf/View/Impregnation/ImpregnationListView.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/DaSaSo.Wpf/View/Impregnation/ImpregnationListView.xaml.cs b/DaSaSo.Wpf/View/Impregnation/ImpregnationListView.xaml.cs new file mode 100644 index 0000000..542481e --- /dev/null +++ b/DaSaSo.Wpf/View/Impregnation/ImpregnationListView.xaml.cs @@ -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.Impregnation +{ + /// + /// Interaction logic for ImpregnationListView.xaml + /// + public partial class ImpregnationListView : UserControl + { + public ImpregnationListView() + { + InitializeComponent(); + } + } +} diff --git a/DaSaSo.Wpf/Window/MainWindow.xaml b/DaSaSo.Wpf/Window/MainWindow.xaml index 3c1b1ea..2f26a27 100644 --- a/DaSaSo.Wpf/Window/MainWindow.xaml +++ b/DaSaSo.Wpf/Window/MainWindow.xaml @@ -8,6 +8,7 @@ xmlns:BuildingsiteViews="clr-namespace:DaSaSo.Wpf.View.Buildingsites" xmlns:SewerObjectViews="clr-namespace:DaSaSo.Wpf.View.SewerObjecte" xmlns:SewerObjectView="clr-namespace:DaSaSo.Wpf.View.SewerObject" + xmlns:ImpregnationViews="clr-namespace:DaSaSo.Wpf.View.Impregnation" 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}" @@ -41,6 +42,9 @@ + + +