From 3fd9140980da97725eb7925b9d9ff5e8a0c1e60b Mon Sep 17 00:00:00 2001 From: Rene Evertz Date: Wed, 14 May 2025 10:05:15 +0200 Subject: [PATCH] Refactor - VM nicht direkt an View --- BeWo/BeWo.csproj | 2 + BeWo/Core/BeWoWpfUtils.cs | 33 +- BeWo/DebugConfig.cs | 6 +- .../SchulbegleitenderDienstEmployeeView.xaml | 333 +- .../View/AbsenceTimeEditView.xaml | 146 +- BeWo/Services/BeWoControlFactory.cs | 11 +- BeWo/Services/BeWoWindowFactory.cs | 10 +- BeWo/Services/BeWoWindowService.cs | 17 +- BeWo/Services/IControlFactory.cs | 6 +- BeWo/Services/IWindowFactory.cs | 5 +- BeWo/Services/IWindowService.cs | 7 +- BeWo/View/BeWoFileView.xaml | 288 +- BeWo/View/Controls/NewsItemEditControl.xaml | 116 +- .../Detail/AI/AiConversationChatView.xaml | 14 +- .../Detail/AI/AiConversationChatView.xaml.cs | 26 +- .../Accounting/DigitalInvoiceOverview.xaml | 272 +- .../Detail/Accounting/GeneralInvoiceView.xaml | 384 ++- .../ServiceInvoiceCreatePopUpView.xaml | 140 +- .../ServiceInvoiceItemEditView.xaml | 764 +++-- .../Detail/Accounting/ServiceInvoiceView.xaml | 481 ++- .../SettlementInvoiceItemEditView2.xaml | 681 +++-- .../Accounting/SettlementInvoiceView.xaml | 336 +- .../AccountingTransactionBookingView2.xaml | 202 +- BeWo/View/Detail/AdditionalServiceView.xaml | 1534 +++++++--- .../Detail/AssessmentSheetCategoryView.xaml | 353 ++- .../View/Detail/AssessmentSheetValueView.xaml | 329 +- BeWo/View/Detail/CustomerView.xaml | 5 +- BeWo/View/Detail/CustomerView.xaml.cs | 21 +- BeWo/View/Detail/EmployeeView.xaml | 125 +- BeWo/View/Detail/InvoiceNumberView.xaml | 127 +- BeWo/View/Detail/InvoiceView.xaml | 748 +++-- BeWo/View/Detail/MassnahmenTreeViewView.xaml | 193 +- BeWo/View/Detail/MedRecordEditView.xaml | 209 +- ...MedikamentenverordnungslistenEditView.xaml | 620 ++-- BeWo/View/Detail/NewsItemView.xaml | 254 +- .../Detail/SupportConceptGoalRatingView.xaml | 340 ++- BeWo/View/Detail/UserGroupView.xaml | 315 +- .../WohneinheitBelegungEditPopup.xaml | 125 +- .../Wohneinheit/WohneinheitEditPopup.xaml | 5 +- .../WohneinheitVerwaltungViewV2.xaml | 96 +- .../View/Detail/WordDocumentTemplateView.xaml | 251 +- .../Zeiterfassung/ServiceRecordEditView.xaml | 2689 +++++++++++------ .../Zeiterfassung/ServiceRecordView2.xaml | 2 +- .../Zeiterfassung/ServiceRecordView2.xaml.cs | 23 +- BeWo/View/EmployeeArbeitszeitView.xaml | 634 ++-- BeWo/View/HomeView.xaml | 1726 +++++++---- BeWo/View/Master/FinanceView.xaml | 2 +- .../Navigation/CustomerNavigationView.xaml.cs | 16 +- .../Navigation/EmployeeNavigationView.xaml.cs | 17 +- .../OrganisationNavigationView.xaml.cs | 16 +- .../Navigation/PersonNavigationView.xaml.cs | 16 +- .../SupportConceptNavigationView.xaml.cs | 16 +- BeWo/ViewModel/AiConversationVM.cs | 6 +- .../ListViewModel/AiConversationListVM.cs | 395 +-- BeWo/ViewModel/VMFactory.cs | 1796 +++++------ .../View/AiConversationChatViewModel.cs | 387 +++ BeWo/ownChat/ChatServiceCustomer.xaml | 249 +- BeWo/ownChat/ChatServiceEmployee.xaml | 149 +- 58 files changed, 11934 insertions(+), 6135 deletions(-) create mode 100644 BeWo/ViewModel/View/AiConversationChatViewModel.cs diff --git a/BeWo/BeWo.csproj b/BeWo/BeWo.csproj index 9945947dc..430d603bc 100644 --- a/BeWo/BeWo.csproj +++ b/BeWo/BeWo.csproj @@ -104,6 +104,7 @@ + AiConfigView.xaml @@ -3519,6 +3520,7 @@ + diff --git a/BeWo/Core/BeWoWpfUtils.cs b/BeWo/Core/BeWoWpfUtils.cs index b78f48448..182ffb075 100644 --- a/BeWo/Core/BeWoWpfUtils.cs +++ b/BeWo/Core/BeWoWpfUtils.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.Windows; using System.Windows.Controls; using System.Windows.Media; +using System.Windows.Threading; using BeWo.View; using DevExpress.Xpf.Grid; @@ -294,24 +295,30 @@ namespace BeWo.Core return null; } - public static void ScrollToTop(ListBox listBox) + public static void ScrollToTop(ListBox listBox, DispatcherPriority priority = DispatcherPriority.Loaded) { - if (VisualTreeHelper.GetChildrenCount(listBox) > 0) - { - Border border = (Border)VisualTreeHelper.GetChild(listBox, 0); - ScrollViewer scrollViewer = (ScrollViewer)VisualTreeHelper.GetChild(border, 0); - scrollViewer.ScrollToTop(); - } + listBox.Dispatcher.InvokeAsync(() => + { + if (VisualTreeHelper.GetChildrenCount(listBox) > 0) + { + Border border = (Border)VisualTreeHelper.GetChild(listBox, 0); + ScrollViewer scrollViewer = (ScrollViewer)VisualTreeHelper.GetChild(border, 0); + scrollViewer.ScrollToTop(); + } + }, priority); } - public static void ScrollToBottom(ListBox listBox) + public static void ScrollToBottom(ListBox listBox, DispatcherPriority priority = DispatcherPriority.Loaded) { - if (VisualTreeHelper.GetChildrenCount(listBox) > 0) + listBox.Dispatcher.InvokeAsync(() => { - Border border = (Border)VisualTreeHelper.GetChild(listBox, 0); - ScrollViewer scrollViewer = (ScrollViewer)VisualTreeHelper.GetChild(border, 0); - scrollViewer.ScrollToBottom(); - } + if (VisualTreeHelper.GetChildrenCount(listBox) > 0) + { + Border border = (Border)VisualTreeHelper.GetChild(listBox, 0); + ScrollViewer scrollViewer = (ScrollViewer)VisualTreeHelper.GetChild(border, 0); + scrollViewer.ScrollToBottom(); + } + }, priority); } } } \ No newline at end of file diff --git a/BeWo/DebugConfig.cs b/BeWo/DebugConfig.cs index ad6d26b7f..badf2fb8b 100644 --- a/BeWo/DebugConfig.cs +++ b/BeWo/DebugConfig.cs @@ -147,9 +147,9 @@ namespace BeWo AutoLogin = true, //SelectView = UIContext.AiConversation, //SelectIndex = 8, - //DefaultLoginUsername = "m1", - //DefaultLoginPassword = "bewobewo", - //DefaultProfilename = "5000000000", + DefaultLoginUsername = "m1", + DefaultLoginPassword = "bewobewo", + DefaultProfilename = "5000000000", EnableAutoRemoteDebugging = true }); diff --git a/BeWo/SchulbegleitenderDienst/SchulbegleitenderDienstEmployeeView.xaml b/BeWo/SchulbegleitenderDienst/SchulbegleitenderDienstEmployeeView.xaml index dfc1e024a..453810e76 100644 --- a/BeWo/SchulbegleitenderDienst/SchulbegleitenderDienstEmployeeView.xaml +++ b/BeWo/SchulbegleitenderDienst/SchulbegleitenderDienstEmployeeView.xaml @@ -1,127 +1,236 @@ - + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/BeWo/SchulbegleitenderDienst/View/AbsenceTimeEditView.xaml b/BeWo/SchulbegleitenderDienst/View/AbsenceTimeEditView.xaml index ce581b3c9..1ae7d36ce 100644 --- a/BeWo/SchulbegleitenderDienst/View/AbsenceTimeEditView.xaml +++ b/BeWo/SchulbegleitenderDienst/View/AbsenceTimeEditView.xaml @@ -1,14 +1,16 @@ - + @@ -18,36 +20,116 @@ - + - - - - + + + + - - - - - - - - + + + + + + + + + + \ No newline at end of file diff --git a/BeWo/View/Detail/Accounting/ServiceInvoiceCreatePopUpView.xaml b/BeWo/View/Detail/Accounting/ServiceInvoiceCreatePopUpView.xaml index 22c2af212..a9cfe3578 100644 --- a/BeWo/View/Detail/Accounting/ServiceInvoiceCreatePopUpView.xaml +++ b/BeWo/View/Detail/Accounting/ServiceInvoiceCreatePopUpView.xaml @@ -1,26 +1,47 @@ - + - - - + + + - + @@ -38,41 +59,84 @@ Klicken Sie anschließend auf "Erstellen". - + - + - + - + + + + - - + + - - - - - - + + + + + + - + - + \ No newline at end of file diff --git a/BeWo/View/Detail/AccountingTransactionBookingView2.xaml b/BeWo/View/Detail/AccountingTransactionBookingView2.xaml index d3f650115..287afd736 100644 --- a/BeWo/View/Detail/AccountingTransactionBookingView2.xaml +++ b/BeWo/View/Detail/AccountingTransactionBookingView2.xaml @@ -1,82 +1,148 @@ - - - - - - - - + - - - - - - - - + + + + + + + + + + + + + + + - - - - + + + + - - + + - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - + --> + \ No newline at end of file diff --git a/BeWo/View/Detail/AdditionalServiceView.xaml b/BeWo/View/Detail/AdditionalServiceView.xaml index 20d1fdc34..a1a6a8dd9 100644 --- a/BeWo/View/Detail/AdditionalServiceView.xaml +++ b/BeWo/View/Detail/AdditionalServiceView.xaml @@ -1,49 +1,68 @@ - + - - - - + + @@ -188,44 +266,48 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + - + - + - - + + - - - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - - + + + \ No newline at end of file diff --git a/BeWo/View/Detail/AssessmentSheetValueView.xaml b/BeWo/View/Detail/AssessmentSheetValueView.xaml index 1a91435d1..150a2608e 100644 --- a/BeWo/View/Detail/AssessmentSheetValueView.xaml +++ b/BeWo/View/Detail/AssessmentSheetValueView.xaml @@ -1,114 +1,253 @@ - + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - + + + + + - - + + - - - + + - - + + - - + + - - - - - - - - - + + + + + + + + + - + - - + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + - + + + - - - - - + + + + + - - - - - - - - - - - + + + + + + + + + + + - + - - - - - + + + + + - + - + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - + - - - - + - + - + @@ -124,18 +201,34 @@ - + - diff --git a/BeWo/View/Detail/MedRecordEditView.xaml b/BeWo/View/Detail/MedRecordEditView.xaml index 6dba224f3..dda8f7660 100644 --- a/BeWo/View/Detail/MedRecordEditView.xaml +++ b/BeWo/View/Detail/MedRecordEditView.xaml @@ -1,26 +1,40 @@ - - + + - + - + @@ -41,50 +55,139 @@ - + - - + - - - + + + - - - - - - - - - - - - + + - - - - + + + + - - + + - + - + - + - + - - + + - + - + - + ValueDataMember="Rating"> + - + @@ -235,11 +340,10 @@ - + - + \ No newline at end of file diff --git a/BeWo/View/Detail/UserGroupView.xaml b/BeWo/View/Detail/UserGroupView.xaml index ce53c562e..ce133ddd1 100644 --- a/BeWo/View/Detail/UserGroupView.xaml +++ b/BeWo/View/Detail/UserGroupView.xaml @@ -1,108 +1,221 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + Focusable="True" + mc:Ignorable="d"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - - - + + + - - - + + + - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + \ No newline at end of file diff --git a/BeWo/View/Master/FinanceView.xaml b/BeWo/View/Master/FinanceView.xaml index 525ec10c4..471518a8e 100644 --- a/BeWo/View/Master/FinanceView.xaml +++ b/BeWo/View/Master/FinanceView.xaml @@ -9,7 +9,7 @@ xmlns:shared="clr-namespace:BS.Shared;assembly=BS.Shared" xmlns:uc="clr-namespace:BeWo.Controls;assembly=BeWo.Controls" xmlns:val="clr-namespace:BeWo.Validation" - xmlns:viewmodel="clr-namespace:BeWo.ViewModel" + xmlns:viewmodel="clr-namespace:BeWo.ViewModel" Width="Auto" Height="Auto" HorizontalAlignment="Stretch" diff --git a/BeWo/View/Navigation/CustomerNavigationView.xaml.cs b/BeWo/View/Navigation/CustomerNavigationView.xaml.cs index fb2534669..5b3dfafca 100644 --- a/BeWo/View/Navigation/CustomerNavigationView.xaml.cs +++ b/BeWo/View/Navigation/CustomerNavigationView.xaml.cs @@ -31,6 +31,7 @@ using System; using BeWo.View.Windows; using System.Collections; using System.Windows.Input; +using BeWo.ViewModel.View; namespace BeWo.View.Navigation { @@ -201,18 +202,23 @@ namespace BeWo.View.Navigation return dict; } - private void OpenAiWindow() + private AiConversationChatViewModel getAiConversationChatViewModel() { var context = GetVisibleInformationReferences(); - MainControl.WindowService.ShowAiConversationWindow(UIContext.Customer, context); + var vm = VMFactory.CreateAiConversationChatViewModel(UIContext.Customer, context); + + return vm; + } + + private void OpenAiWindow() + { + MainControl.WindowService.ShowAiConversationWindow(getAiConversationChatViewModel()); } private void OpenAiPopup() { - var context = GetVisibleInformationReferences(); - - MainControl.WindowService.ShowAiConversationModalViewWindow(UIContext.Customer, context); + MainControl.WindowService.ShowAiConversationModalViewWindow(getAiConversationChatViewModel()); } private void SupportConceptFilterComboBoxOnSelectionChanged(object o, SelectionChangedEventArgs selectionChangedEventArgs) diff --git a/BeWo/View/Navigation/EmployeeNavigationView.xaml.cs b/BeWo/View/Navigation/EmployeeNavigationView.xaml.cs index 1d0b623b3..8a935eb7d 100644 --- a/BeWo/View/Navigation/EmployeeNavigationView.xaml.cs +++ b/BeWo/View/Navigation/EmployeeNavigationView.xaml.cs @@ -14,7 +14,7 @@ using BeWo.View.Detail; using BeWo.View.Navigation.Sorter; using BeWo.View.Windows; using BeWo.ViewModel; - +using BeWo.ViewModel.View; using BS.Shared; using BS.Shared.Core; using BS.Shared.DataContracts; @@ -108,18 +108,23 @@ namespace BeWo.View.Navigation return dict; } - private void OpenAiWindow() + private AiConversationChatViewModel getAiConversationChatViewModel() { var context = GetVisibleInformationReferences(); - MainControl.WindowService.ShowAiConversationWindow(UIContext.Employee, context); + var vm = VMFactory.CreateAiConversationChatViewModel(UIContext.Employee, context); + + return vm; + } + + private void OpenAiWindow() + { + MainControl.WindowService.ShowAiConversationWindow(getAiConversationChatViewModel()); } private void OpenAiPopup() { - var context = GetVisibleInformationReferences(); - - MainControl.WindowService.ShowAiConversationModalViewWindow(UIContext.Employee, context); + MainControl.WindowService.ShowAiConversationModalViewWindow(getAiConversationChatViewModel()); } private bool MainNavigationView_ArchiveObject(IFilterableDC obj) diff --git a/BeWo/View/Navigation/OrganisationNavigationView.xaml.cs b/BeWo/View/Navigation/OrganisationNavigationView.xaml.cs index c53f57b08..751a3b0d6 100644 --- a/BeWo/View/Navigation/OrganisationNavigationView.xaml.cs +++ b/BeWo/View/Navigation/OrganisationNavigationView.xaml.cs @@ -10,6 +10,7 @@ using BeWo.ServiceProxy; using BeWo.View.Detail; using BeWo.View.Navigation.Sorter; using BeWo.ViewModel; +using BeWo.ViewModel.View; using BS.Shared; using BS.Shared.Core; using BS.Shared.DataContracts; @@ -73,18 +74,23 @@ namespace BeWo.View.Navigation return dict; } - private void OpenAiWindow() + private AiConversationChatViewModel getAiConversationChatViewModel() { var context = GetVisibleInformationReferences(); - MainControl.WindowService.ShowAiConversationWindow(UIContext.Organisation, context); + var vm = VMFactory.CreateAiConversationChatViewModel(UIContext.Organisation, context); + + return vm; + } + + private void OpenAiWindow() + { + MainControl.WindowService.ShowAiConversationWindow(getAiConversationChatViewModel()); } private void OpenAiPopup() { - var context = GetVisibleInformationReferences(); - - MainControl.WindowService.ShowAiConversationModalViewWindow(UIContext.Organisation, context); + MainControl.WindowService.ShowAiConversationModalViewWindow(getAiConversationChatViewModel()); } private void mainNavigationView_CreateNewObject() diff --git a/BeWo/View/Navigation/PersonNavigationView.xaml.cs b/BeWo/View/Navigation/PersonNavigationView.xaml.cs index 34fdce350..4ccfbec55 100644 --- a/BeWo/View/Navigation/PersonNavigationView.xaml.cs +++ b/BeWo/View/Navigation/PersonNavigationView.xaml.cs @@ -19,6 +19,7 @@ using DevExpress.Mvvm; using BeWo.View.Windows; using System.Collections; using System.Windows.Input; +using BeWo.ViewModel.View; namespace BeWo.View.Navigation { @@ -110,18 +111,23 @@ namespace BeWo.View.Navigation return dict; } - private void OpenAiWindow() + private AiConversationChatViewModel getAiConversationChatViewModel() { var context = GetVisibleInformationReferences(); - MainControl.WindowService.ShowAiConversationWindow(UIContext.Person, context); + var vm = VMFactory.CreateAiConversationChatViewModel(UIContext.Person, context); + + return vm; + } + + private void OpenAiWindow() + { + MainControl.WindowService.ShowAiConversationWindow(getAiConversationChatViewModel()); } private void OpenAiPopup() { - var context = GetVisibleInformationReferences(); - - MainControl.WindowService.ShowAiConversationModalViewWindow(UIContext.Person, context); + MainControl.WindowService.ShowAiConversationModalViewWindow(getAiConversationChatViewModel()); } private void SupportConceptFilterComboBoxOnSelectionChanged(object o, SelectionChangedEventArgs selectionChangedEventArgs) diff --git a/BeWo/View/Navigation/SupportConceptNavigationView.xaml.cs b/BeWo/View/Navigation/SupportConceptNavigationView.xaml.cs index 6c3e0dd18..ca4049112 100644 --- a/BeWo/View/Navigation/SupportConceptNavigationView.xaml.cs +++ b/BeWo/View/Navigation/SupportConceptNavigationView.xaml.cs @@ -26,6 +26,7 @@ using BeWo.View.Windows; using DevExpress.Mvvm; using System.Collections; using System.Windows.Input; +using BeWo.ViewModel.View; namespace BeWo.View.Navigation { @@ -224,18 +225,23 @@ namespace BeWo.View.Navigation return dict; } - private void OpenAiWindow() + private AiConversationChatViewModel getAiConversationChatViewModel() { var context = GetVisibleInformationReferences(); - MainControl.WindowService.ShowAiConversationWindow(UIContext.SupportConcept, context); + var vm = VMFactory.CreateAiConversationChatViewModel(UIContext.SupportConcept, context); + + return vm; + } + + private void OpenAiWindow() + { + MainControl.WindowService.ShowAiConversationWindow(getAiConversationChatViewModel()); } private void OpenAiPopup() { - var context = GetVisibleInformationReferences(); - - MainControl.WindowService.ShowAiConversationModalViewWindow(UIContext.SupportConcept, context); + MainControl.WindowService.ShowAiConversationModalViewWindow(getAiConversationChatViewModel()); } private void SupportConceptFilterComboBoxOnSelectionChanged(object o, SelectionChangedEventArgs selectionChangedEventArgs) diff --git a/BeWo/ViewModel/AiConversationVM.cs b/BeWo/ViewModel/AiConversationVM.cs index 9df9179d9..edf07026b 100644 --- a/BeWo/ViewModel/AiConversationVM.cs +++ b/BeWo/ViewModel/AiConversationVM.cs @@ -75,11 +75,11 @@ namespace BeWo.ViewModel } } - [JsonProperty] public DateTime Created => DataContract.Created; - - [JsonProperty] public AiModelDC Modell => DataContract.Modell; + public string Context => DataContract.Context; + public Dictionary ContextBeWoObjects => DataContract.ContextBeWoObjects; + public UIContext UIContext => (UIContext)DataContract.UIContext; protected override void InitByDataContract(AiConversationDC pDataContract) { diff --git a/BeWo/ViewModel/ListViewModel/AiConversationListVM.cs b/BeWo/ViewModel/ListViewModel/AiConversationListVM.cs index 564e0d5ed..ca2884544 100644 --- a/BeWo/ViewModel/ListViewModel/AiConversationListVM.cs +++ b/BeWo/ViewModel/ListViewModel/AiConversationListVM.cs @@ -25,16 +25,6 @@ namespace BeWo.ViewModel.ListViewModel { public class AiConversationListVM : AbstractDCListMapperVM { - private bool _IsSettingsOpen; - private bool _IsCloneOpen; - private bool _IsSending; - - private string _MessageInput; - private string _ContextInput; - - private AiModelDC _SelectedModel; - private AiConfigVM _Config; - public AiConversationListVM() : this(null) { if (BeWoApp.IsInDesignMode) @@ -45,390 +35,9 @@ namespace BeWo.ViewModel.ListViewModel public AiConversationListVM(List pDCs) : base(pDCs) { - Models = new ObservableSortCollection(); - - SendNewMessageCommand = new DelegateCommand(SendNewMessage, () => SelectedVM is object && !string.IsNullOrWhiteSpace(MessageInput) && !IsSending); - OpenNewConversationCommand = new DelegateCommand(OpenNewConversation, () => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleChatAdd)); - StartConversationWithMessageCommand = new DelegateCommand(StartConversationWithMessage, () => !string.IsNullOrWhiteSpace(MessageInput) && !IsSending); - - ReloadConfigCommand = new DelegateCommand(ReloadConfig); - ReloadConversationsCommand = new DelegateCommand(ReloadConversations); - ReloadModelsCommand = new DelegateCommand(ReloadModels); - - OpenSettingCommand = new DelegateCommand(OpenSetting, () => (BeWoApp.AppSettings?.ModuleAiSettingsEnabled ?? true) && BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleViewSetting)); - OpenCloneCommand = new DelegateCommand(OpenClone, () => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleChatClone) && SelectedVM is object); - CloneCommand = new DelegateCommand(Clone); - - AskDeleteCommand = new DelegateCommand(AskDelete, () => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleChatDelete) && SelectedVM is object); - - SelectedVMChanged += (s, e) => FirePropertyChanged(nameof(IsNewConversationVisible)); + } - public event EventHandler SendNewMessageSuccess; - - public DelegateCommand SendNewMessageCommand { get; set; } - public DelegateCommand OpenNewConversationCommand { get; set; } - public DelegateCommand StartConversationWithMessageCommand { get; set; } - public DelegateCommand RequestNewConversationCommand { get; set; } - public DelegateCommand TestCommand { get; set; } - public DelegateCommand AskDeleteCommand { get; set; } - public DelegateCommand ReloadConfigCommand { get; set; } - public DelegateCommand ReloadConversationsCommand { get; set; } - public DelegateCommand ReloadModelsCommand { get; set; } - - public DelegateCommand OpenSettingCommand { get; set; } - public DelegateCommand OpenCloneCommand { get; set; } - public DelegateCommand CloneCommand { get; set; } - - public ObservableCollection Models { get; set; } - public AiModelDC SelectedModel - { - get { return _SelectedModel; } - set - { - if (_SelectedModel == value) - return; - - _SelectedModel = value; - FirePropertyChanged(nameof(SelectedModel)); - } - } - public AiConfigVM Config - { - get { return _Config; } - set - { - if (Config == value) - return; - - _Config = value; - FirePropertyChanged(nameof(Config)); - } - } - - public string MessageInput - { - get { return _MessageInput; } - set - { - if (MessageInput == value) - return; - - _MessageInput = value; - FirePropertyChanged(nameof(MessageInput)); - } - } - public string ContextInput - { - get { return _ContextInput; } - set - { - if (ContextInput == value) - return; - - _ContextInput = value; - FirePropertyChanged(nameof(ContextInput)); - } - } - - public bool IsSettingsOpen - { - get => _IsSettingsOpen; - set - { - _IsSettingsOpen = value; - FirePropertyChanged(nameof(IsSettingsOpen)); - } - } - public bool IsCloneOpen - { - get => _IsCloneOpen; - set - { - _IsCloneOpen = value; - FirePropertyChanged(nameof(IsCloneOpen)); - } - } - public bool IsSending - { - get => _IsSending; - set - { - _IsSending = value; - FirePropertyChanged(nameof(IsSending)); - } - } - public bool IsNewConversationVisible => SelectedVM is null; - - public int UIContext { get; set; } - public long? ReferenceObjectOid { get; set; } - public Dictionary ContextBeWoObjects { get; set; } - - private void StartConversationWithMessage() - { - StartSending(); - - try - { - var message = MessageInput; - - var conv = new AiConversationDC(); - - conv.Created = DateTime.Now; - conv.Updated = DateTime.Now; - conv.UIContext = UIContext; - conv.ContextBeWoObjects = ContextBeWoObjects; - conv.Messages = new List() - { - new AiConversationMessageDC() - { - Message = message, - Role = AiConversationMessageRole.User - } - }; - - var vm = InsertConverstion(conv); - - ServiceFacade.DoAiEnhancedServiceAsnyc( - x => x.CreateAiConversationWithMessage(conv, Config.SelectedModel.Oid.Value, message), - dc => UpdateConverstion(vm, dc), - e => EndSending()); - } - catch(Exception ex) - { - EndSending(); - } - } - private void OpenNewConversation() - { - SelectedVM = null; - } - private void SendNewMessage() - { - StartSending(); - - try - { - var conv = SelectedVM; - - var msg_dc = new AiConversationMessageDC(); - - msg_dc.Message = MessageInput; - msg_dc.Role = BS.Shared.AiConversationMessageRole.User; - msg_dc.Created = DateTime.Now; - - var msg_vm = new AiConversationMessageVM(msg_dc); - - conv.Messages.VMList.Add(msg_vm); - - ServiceFacade.DoAiEnhancedServiceAsnyc( - x => x.SendNewMessage(conv.DataContract.Oid.Value, MessageInput), - (messages) => - { - if (messages.Count != 2) - throw new InvalidOperationException("message count: " + messages.Count); - - msg_vm.DataContract = messages[0]; - - conv.Messages.VMList.Add(new AiConversationMessageVM(messages[1])); - - MessageInput = string.Empty; - - EndSending(); - - SendNewMessageSuccess?.Invoke(this, EventArgs.Empty); - }, - (exception) => - { - conv.Messages.VMList.Remove(msg_vm); - - EndSending(); - } - ); - } - catch (Exception ex) { - EndSending(); - } - } - private void StartSending() - { - if (IsSending) - throw new InvalidOperationException("Sendet bereits"); - - IsSending = true; - } - private void EndSending() - { - if (!IsSending) - throw new InvalidOperationException("Sendet nicht"); - - IsSending = false; - } - private void Test() - { - throw new NotImplementedException(); - - //var limit = 5; - - //var models = ServiceFacade.DoOperationsEnhancedServiceSnyc(x => x.GetAiModels()); - //Models.MakeEqualTo(models); - - //VMList.Clear(); - - //foreach (var vm in Models) - //{ - // var dc = new AiConversationDC(); - - // dc.Created = DateTime.Now; - // dc.Displayname = "Example"; - // dc.Modell = vm.ToString(); - - // var pvm = new AiConversationVM(dc); - - // VMList.Add(pvm); - //} - - //var msg = "Wie alt ist Frau Müller?"; - //var context = "Frau Müller wurde am 1.1.1950 geboren. Aktuelle haben wir folgende Universalzeit: " + DateTime.Now.ToUniversalTime(); - - //for (var i = 0; i < limit; i++) - //{ - // foreach (var vm in VMList) - // { - // ServiceFacade.DoOperationsEnhancedServiceAsnyc(x => x.SendNewMessage(vm.CommitToDataContract(), context, msg), (message) => - // { - // vm.Messages.VMList.Add(new AiConversationMessageVM(message)); - // }); - // } - //} - } - - private AiConversationVM InsertConverstion(AiConversationDC dc) - { - var vm = new AiConversationVM(dc); - VMList.Insert(0, vm); - SelectedVM = vm; - - return vm; - } - - private void UpdateConverstion(AiConversationVM vm, AiConversationDC dc) - { - vm.UpdateByDataContract(dc); - - MessageInput = string.Empty; - - EndSending(); - - SendNewMessageSuccess?.Invoke(this, EventArgs.Empty); - } - - private void ReloadConfig() - { - ServiceFacade.DoAiEnhancedServiceAsnyc(x => x.GetAiConfig(), (x) => - { - if (Config is null) - Config = new AiConfigVM(x); - else - Config.Update(x); - }); - } - public void UpdateConfig() - { - if (!Config.IsDirty) - return; - - ServiceFacade.DoAiEnhancedServiceAsnyc(x => x.UpdateAiConfig(Config.CommitToDataContract()), (x) => - { - Config.Update(x); - }); - } - - private void ReloadModels() - { - ServiceFacade.DoAiEnhancedServiceAsnyc(x => x.GetAiModels(), (x) => - { - Models.MakeEqualTo(x); - - if (Config.SelectedModel is null && Models.Any()) - Config.SelectedModel = Models.First(); - }); - } - private void ReloadConversations() - { - var ui_context = UIContext; - var reference = ReferenceObjectOid; - - ServiceFacade.DoAiEnhancedServiceAsnyc(x => x.GetAiConversations(ui_context, reference), (x) => - { - x.Reverse(); - var vms = new AiConversationListVM(x); - VMList.MakeEqualTo(vms.VMList); - }); - } - - private void OpenSetting() - { - ServiceFacade.DoAiEnhancedServiceAsnyc(x => x.GetAiModels(), (x) => - { - Models.MakeEqualTo(x); - IsSettingsOpen = true; - }); - } - private void OpenClone() - { - foreach (var message in SelectedVM.Messages.VMList) - { - message.IsChecked = true; - } - - IsCloneOpen = true; - } - private void Clone() - { - var conv = SelectedVM; - - AiConversationMessageVM last = null; - foreach (var msg in conv.Messages.VMList) - { - if (!msg.IsChecked) - break; - - last = msg; - } - - var conv_oid = conv.DataContract.Oid.Value; - var msg_oid = last?.DataContract.Oid; - - ServiceFacade.DoAiEnhancedServiceAsnyc(x => x.CloneAiConversation(conv_oid, msg_oid), dc => - { - InsertConverstion(dc); - CloseClone(); - }); - } - private void CloseClone() - { - IsCloneOpen = false; - } - - public void AskDelete() - { - var selected = SelectedVM; - - var oid = selected.DataContract.Oid.Value; - - var msg = $"Wollen Sie die ausgewählte Konversation ({oid}) löschen?"; - - if (MessageBox.Show(msg, "Konversation löschen", MessageBoxButton.YesNo, MessageBoxImage.Warning) == - MessageBoxResult.Yes) - { - ServiceFacade.DoAiEnhancedServiceAsnyc(x => x.DeleteAiConversation(oid), () => { - VMList.Remove(selected); - CommandManager.InvalidateRequerySuggested(); - //SelectedVM = VMList.FirstOrDefault(); - }); - } - } #region Designer private void InitDesigner() { @@ -489,7 +98,7 @@ namespace BeWo.ViewModel.ListViewModel InitDummyConversations(10); - //SelectedVM = conversation_vm; + SelectedVM = conversation_vm; } private void InitDummyConversations(int count) { diff --git a/BeWo/ViewModel/VMFactory.cs b/BeWo/ViewModel/VMFactory.cs index ef34318d1..6d5a6669e 100644 --- a/BeWo/ViewModel/VMFactory.cs +++ b/BeWo/ViewModel/VMFactory.cs @@ -6,7 +6,7 @@ using BeWo.Core.Service; using BeWo.SchulbegleitenderDienst.ViewModel; using BeWo.ServiceProxy; using BeWo.ViewModel.ListViewModel; - +using BeWo.ViewModel.View; using BS.Shared; using BS.Shared.Core; using BS.Shared.DataContracts; @@ -17,890 +17,912 @@ using DevExpress.XtraEditors.Filtering.Templates; namespace BeWo.ViewModel { - public static class VMFactory - { - public static void CreateAbsenceReasonListVMAsync(Action pCallBack) - { - ServiceFacade.DoCustomerServiceAsync(s => s.GetAllAbsenceReasons(), r => pCallBack(new AbsenceReasonListVM(r))); - } - - public static void CreateAbsenceTimeListVMAsync(IEnumerable pDCs, AbsenceReasonVisibilityType? type, Action pCallBack) - { - ServiceFacade.DoCustomerServiceAsync(s => s.GetAllAbsenceReasons(), cb => pCallBack(new AbsenceTimeListVM(pDCs, cb.Where(a => !a.Sichtbarkeit.HasValue || a.Sichtbarkeit.Value == AbsenceReasonVisibilityType.All || a.Sichtbarkeit.Value == type).ToList()))); - } - - public static AbsenceTimeListVM CreateAbsenceTimeListVM(IEnumerable pDCs, AbsenceReasonVisibilityType? type) - { - var list = ServiceFacade.DoCustomerServiceSync(s => s.GetAllAbsenceReasons()); - - return new AbsenceTimeListVM(pDCs, list.Where(a => !a.Sichtbarkeit.HasValue || a.Sichtbarkeit.Value == AbsenceReasonVisibilityType.All || a.Sichtbarkeit.Value == type).ToList()); - } - - public static void CreateOvertimeListVMAsync(IEnumerable pDCs, Action pCallBack) - { - //ServiceFacade.DoValueListServiceAsync(v => v.GetAllValueListEntrysByType(ValueListEntryType.Auszahlungsart), cb => pCallBack(new OvertimeListVM(pDCs))); - ServiceFacade.DoEmployeeServiceAsync(v => v.GetAllOvertimes(), cb => pCallBack(new OvertimeListVM(pDCs))); - } - - public static void CreateAccountingBookingVMAsnyc(Action pCallBack) - { - Cache.GetInstance().GetSupportConceptTree( - tree => Cache.GetInstance().GetAllValueListEntrysByTypeAsync(ValueListEntryType.AccountingTransactionType, categories => pCallBack(new AccountingBookingVM(tree, categories)))); - } - - public static void CreateAccountingTransactionListVMAsnyc(DateTimeSpan pSpan, long? pSupportConceptOid, long? pCostBearerSupportConceptRelOid, Action pCallBack) - { - ServiceFacade.DoOperationsServiceAsync(s => s.GetAccountingTransactions(pSpan, pSupportConceptOid, pCostBearerSupportConceptRelOid), r => pCallBack(new AccountingTransactionListVM(r))); - } - - public static void CreateAssessmentSheetCategoryListVM(Action cb) - { - ServiceFacade.DoEmployeeServiceAsync( - s1 => s1.GetAllAssessmentSheetValues(), v => ServiceFacade.DoEmployeeServiceAsync(s => s.GetAllAssessmentSheetCategories(), dcs => cb(new AssessmentSheetCategoryListVM(dcs, v)))); - } - - public static void CreateAssessmentSheetValueListVM(Action cb) - { - ServiceFacade.DoEmployeeServiceAsync(s => s.GetAllAssessmentSheetValues(), dcs => cb(new AssessmentSheetValueListVM(dcs))); - } - - public static void CreateBookingVMAsync(DateTimeSpan pSpan, Action pCallBack) - { - ServiceFacade.DoResourceServiceAsync(s => s.GetAllBookings(pSpan.StartDateTime, pSpan.EndDateTime), r => pCallBack(new BookingVM(r))); - } - - public static CustomerEmployeeRelationListVM CreateCustomerEmployeeRelationListVM(List pList) - { - var valueList = Cache.GetInstance().GetAllValueListEntrysByTypeSync(ValueListEntryType.StaffRoleType); - return new CustomerEmployeeRelationListVM(pList, valueList); - } - - public static WohnheimEmployeeRelationListVM CreateWohnheimEmployeeRelationListVM(List pList) - { - var valueList = Cache.GetInstance().GetAllValueListEntrysByTypeSync(ValueListEntryType.StaffRoleType); - return new WohnheimEmployeeRelationListVM(pList, valueList); - } - - public static WohnheimCustomerRelationListVM CreateWohnheimCustomerRelationListVM(List pList) - { - var valueList = Cache.GetInstance().GetAllValueListEntrysByTypeSync(ValueListEntryType.StaffRoleType); - return new WohnheimCustomerRelationListVM(pList, valueList); - } - - public static GoalRatingListVM CreateGoalRatingListVM(List ratingList) - { - var typeList = Cache.GetInstance().GetAllRatingTypeList(); - return new GoalRatingListVM(ratingList, typeList); - } - - public static void CreateOrganisationPersonRelationListVMAsync(List pDCs, Action pCallBack) - { - pCallBack(new OrganisationPersonRelationListVM(pDCs)); - } - - public static CustomerPersonRelationListVM CreateCustomerEnvironmentPersonRelListVM(List pList, ValueListEntryType vtype) - { - var valueList = Cache.GetInstance().GetAllValueListEntrysByTypeSync(vtype); - - return new CustomerPersonRelationListVM(pList, valueList); - } - - public static void CreateCustomerEnvironmentOrganisationRelListVMAsync(List pList, Action pCallBack) - { - Cache.GetInstance().GetAllValueListEntrysByTypeAsync(ValueListEntryType.EnvironmentOrganisationType, r => pCallBack(new CustomerOrganisationRelationListVM(pList, r))); - } - - public static CustomerOrganisationRelationListVM CreateCustomerEnvironmentOrganisationRelListVM(List pList) - { - var valueList = Cache.GetInstance().GetAllValueListEntrysByTypeSync(ValueListEntryType.EnvironmentOrganisationType); - - return new CustomerOrganisationRelationListVM(pList, valueList); - } - - public static MedikamentenverordnungslisteListVM CreateMedikementenverordnungslisteListVM(IEnumerable pList) - { - var darreichungsformen = ServiceFacade.DoCustomerServiceSync(s => s.GetAllDarreichungsformen()); - var depotrhythmen = ServiceFacade.DoCustomerServiceSync(s => s.GetAllDepotRhythmen()); - - return new MedikamentenverordnungslisteListVM(pList, darreichungsformen, depotrhythmen); - } - - public static BargeldtransaktionsListVM CreateBargeldtransaktionsListVM(IEnumerable pList) - { - return new BargeldtransaktionsListVM(pList); - } - - public static void CreateCustomerVMAsync(long pOid, Action pCallBack) - { - ServiceFacade.DoCustomerServiceAsync(s => s.LoadCustomer(pOid), cb => CreateCustomerVMAsync(cb, pCallBack)); - } - - public static void CreateCustomerVMAsync(Action pCallBack) - { - ServiceFacade.DoOperationsServiceAsync( - s => s.GetVarFieldDefs(TableID.Customer), - cb => CreateCustomerVMAsync( - new CustomerDC - { - CustomerVarFields = cb - }, - pCallBack)); - } - - public static void CreateCustomerVMAsync(CustomerDC pCustomerDC, Action pCallBack) - { - if (BeWoApp.ICD10Diagnosis == null) - { - ServiceFacade.DoOperationsServiceAsync( - s => s.GetCompressedICD10Diagnosis(), - st => - { - st = Utils.Decompress(st); - var ds = st.Split(Environment.NewLine).ToDictionary(line => line.Substring(0, line.IndexOf(';')), line => line.Substring(line.IndexOf(';') + 1)); - - BeWoApp.ICD10Diagnosis = ds; - InternalCreateCustomerVM(pCustomerDC, pCallBack); - }); - } - else - { - InternalCreateCustomerVM(pCustomerDC, pCallBack); - } - } - - public static void CreateEmployeeVMAsync(long pOid, Action pCallBack) - { - ServiceFacade.DoEmployeeServiceAsync( - s => s.LoadEmployee(pOid), - r => - { - CreateEmployeeVMAsync(r, pCallBack); - }); - } - - public static void CreateEmployeeVMAsync(EmployeeDC pEmployeeDC, Action pCallBack) - { - ServiceFacade.DoEmployeeServiceAsync(s => s.GetAllEmploymentTypes(), - r1 => - Cache.GetInstance().GetAllValueListEntrysByTypeAsync( - ValueListEntryType.StaffQualificationsType, - r2 => - Cache.GetInstance() - .GetAllValueListEntrysByTypeAsync(ValueListEntryType.StaffActivityFocusType, - r3 => - Cache.GetInstance() - .GetAllValueListEntrysByTypeAsync(ValueListEntryType.ContractType, - r4 => - Cache.GetInstance() - .GetAllValueListEntrysByTypeAsync(ValueListEntryType.Nationality, - nat => - Cache.GetInstance() - .GetAllValueListEntrysByTypeAsync(ValueListEntryType.NotizenKategorieEmployee, - r7 => - ServiceFacade.DoEmployeeServiceAsync( - e => - e.GetAllAuszahlungsarten(), - r6 => - ServiceFacade.DoOperationsServiceAsync( - s => - s.GetSbdConfig(), - config => - pCallBack(new EmployeeVM(pEmployeeDC, r1, nat, r2, r3, r6, r4, config.Stundensaetze, r7)))))))))); - } - - public static void CreateEmployeeVMAsync(Action pCallBack) - { - CreateEmployeeVMAsync(new EmployeeDC(), pCallBack); - } - - public static void CreateWohnheimVMAsync(long pOid, List customers, Action pCallBack) - { - ServiceFacade.DoWohnheimServiceAsync( - s => s.LoadWohnheim(pOid), - r => - { - CreateWohnheimVMAsync(r, customers, pCallBack); - }); - } - - public static void CreateWohnheimVMAsync(WohnheimDC pWohnheimDC, List customers, Action pCallBack) - { - pCallBack(new WohnheimVM(pWohnheimDC, customers)); - } - - public static void CreateWohnheimVMAsync(List customers, Action pCallBack) - { - CreateWohnheimVMAsync(new WohnheimDC(), customers, pCallBack); - } - - public static void CreateEquityInvoiceBaselListVMAsync(long supportconeptOid, Action callback) - { - ServiceFacade.DoAccountingServiceAsync( - s => s.GetInvoiceBasesForSupportConcept(InvoiceType.CustomerEquity, supportconeptOid), - r => - { - r.Sort( - (dc1, dc2) => - { - if (dc2.InvoiceDate == null) - { - return -1; - } - - if (dc1.InvoiceDate == null) - { - return 1; - } - - return dc2.InvoiceDate.Value.CompareTo(dc1.InvoiceDate.Value); - }); - callback(new InvoiceBaseListVM(r)); - }); - } - - public static void CreateGeneralInvoiceBaselListVMAsync(CompactCustomerDC customer, CompactOrganisationDC organisation, CompactPersonDC person, Action callback) - { - if (organisation != null) - { - ServiceFacade.DoAccountingServiceAsync( - s => s.GetGeneralInvoiceBasesForOrganisation(organisation.OrganisationOid), - r => - { - r.Sort( - (dc1, dc2) => - { - if (dc2.InvoiceDate == null) - { - return -1; - } - - if (dc1.InvoiceDate == null) - { - return 1; - } - - return dc2.InvoiceDate.Value.CompareTo(dc1.InvoiceDate.Value); - }); - callback(new InvoiceBaseListVM(r)); - }); - } - else if (person != null) - { - ServiceFacade.DoAccountingServiceAsync( - s => s.GetGeneralInvoiceBasesForPerson(person.PersonOid), - r => - { - r.Sort( - (dc1, dc2) => - { - if (dc2.InvoiceDate == null) - { - return -1; - } - - if (dc1.InvoiceDate == null) - { - return 1; - } - - return dc2.InvoiceDate.Value.CompareTo(dc1.InvoiceDate.Value); - }); - callback(new InvoiceBaseListVM(r)); - }); - } - else if (customer != null) - { - ServiceFacade.DoAccountingServiceAsync( - s => s.GetGeneralInvoiceBasesForCustomer(customer.CustomerOid), - r => - { - r.Sort( - (dc1, dc2) => - { - if (dc2.InvoiceDate == null) - { - return -1; - } - - if (dc1.InvoiceDate == null) - { - return 1; - } - - return dc2.InvoiceDate.Value.CompareTo(dc1.InvoiceDate.Value); - }); - callback(new InvoiceBaseListVM(r)); - }); - } - } - - public static void CreateInvoiceListVMAsync(Action callback) - { - ServiceFacade.DoCustomerServiceAsync( - s1 => s1.GetAllActiveSupportConceptsCompact(), - r1 => - ServiceFacade.DoCustomerServiceAsync( - s2 => s2.GetAllActiveOrganisationsCompact(), r2 => ServiceFacade.DoOperationsServiceAsync(s3 => s3.GetAllActiveInvoices(), r3 => callback(new InvoiceListVM(r2, r1, r3))))); - } - - public static void CreateInvoiceOverviewListVM(Action callback) - { - ServiceFacade.DoAccountingServiceAsync(s => s.GetAllActiveInvoiceBases(), cb => callback(new InvoiceBaseListVM(cb))); - } - - public static void CreateOrganisationVMAsync(long pOid, Action pCallBack) - { - ServiceFacade.DoCustomerServiceAsync( - s => s.LoadOrganisation(pOid), - r1 => ServiceFacade.DoValueListServiceAsync(s1 => s1.GetAllValueListEntrysByType(ValueListEntryType.StaffQualificationsType), r2 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync(ValueListEntryType.OrganisationFunctionType, - r4 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync(ValueListEntryType.RoleInOrganisationType, - r3 => pCallBack(new OrganisationVM(r1, r2, r4, r3)))))); - } - - public static void CreateOrganisationVMAsync(Action pCallBack) - { - ServiceFacade.DoValueListServiceAsync( - s1 => s1.GetAllValueListEntrysByType(ValueListEntryType.StaffQualificationsType), - r1 => - ServiceFacade.DoOperationsServiceAsync( - s => s.GetVarFieldDefs(TableID.Organisation), - r2 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync( - ValueListEntryType.OrganisationFunctionType, - r4 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync( - ValueListEntryType.RoleInOrganisationType, - r3 => pCallBack(new OrganisationVM( - new OrganisationDC - { - VarFields = r2 - }, r1, r4, r3)))))); - } - - //public static void CreatePersonOrganisationRelationVMAsync(CompactOrganisationDC pOrganisation, Action pCallBack) - //{ - // pCallBack( - // new PersonOrganisationRelationVM( - // new Organisation2PersonDC - // { - // OrganisationOid = pOrganisation.OrganisationOid, - // OrganisationName = pOrganisation.Name, - // OrganisationVersion = pOrganisation.OrganisationVersion - // })); - //} - - public static void CreatePersonVMAsync(Action pCallBack) - { - Cache.GetInstance().GetAllValueListEntrysByTypeAsync( - ValueListEntryType.TitleType, - r1 => - ServiceFacade.DoOperationsServiceAsync( - s => s.GetVarFieldDefs(TableID.Person), - r2 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync( - ValueListEntryType.FunctionType, - r4 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync( - ValueListEntryType.RoleInOrganisationType, - r5 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync( - ValueListEntryType.Nationality, - r3 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync( - ValueListEntryType.Aufenthaltsstatus, - r6 => pCallBack( - new PersonVM( - new PersonDC - { - VarFields = r2 - }, - r1, - r4, - r5, - r3, - r6)))))))); - } - - public static void CreatePersonVMAsync(long pOid, Action pCallBack) - { - ServiceFacade.DoCustomerServiceAsync( - s => s.LoadPerson(pOid), - cb => - Cache.GetInstance().GetAllValueListEntrysByTypeAsync( - ValueListEntryType.TitleType, - r1 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync(ValueListEntryType.FunctionType, - r3 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync(ValueListEntryType.RoleInOrganisationType, - r4 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync(ValueListEntryType.Nationality, - r2 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync(ValueListEntryType.Aufenthaltsstatus, - r5 => pCallBack(new PersonVM(cb, r1, r3, r4, r2, r5)))))))); - } - - public static void CreateResourceListVMAsync(Action pCallBack) - { - ServiceFacade.DoResourceServiceAsync( - s => s.GetAllResources(), - r1 => ServiceFacade.DoValueListServiceAsync(s => s.GetAllValueListEntrysByType(ValueListEntryType.ResourceCategory), r2 => pCallBack(new ResourceListVM(r1, r2)))); - } - - public static void CreateServiceCategoryListVMAsync(Action pCallBack) - { - ServiceFacade.DoOperationsServiceAsync(s => s.GetAllServiceCategories(), - r => pCallBack(new ServiceCategoryListVM(r.Where(sc => sc.ScopeType == ScopeTypeId.Global).ToList()))); - } - - public static void CreateAdditionalServiceListVMAsync(Action pCallBack) - { - ServiceFacade.DoOperationsServiceAsync(s => s.GetAllAdditionalService(), - r => pCallBack(new AdditionalServiceListVM(r.ToList()))); - } - - public static void CreateAuszahlungsartenListVMAsync(Action pCallBack) - { - ServiceFacade.DoEmployeeServiceAsync(s => s.GetAllAuszahlungsarten(), - r => pCallBack(new AuszahlungsartListVM(r.ToList()))); - } - - public static void CreateBudgetListVMAsync(Action pCallBack) - { - ServiceFacade.DoOperationsServiceAsync(s => s.GetAllBudgets(), - r => pCallBack(new BudgetListVM(r.ToList()))); - } - - public static void CreatePreisListVMAsync(Action pCallBack) - { - ServiceFacade.DoOperationsServiceAsync(s => s.GetAllPreise(), - r => pCallBack(new PreisListVM(r.ToList()))); - } - - public static void CreateDienstListVMAsync(Action pCallBack) - { - ServiceFacade.DoOperationsServiceAsync(s => s.GetAllDienste(null), - r => pCallBack(new DienstInfoListVM(r.ToList()))); - } - - public static void CreateRatingTypeListVMAsync(Action pCallBack) - { - ServiceFacade.DoOperationsServiceAsync(s => s.GetAllRatingTypes(), - r => pCallBack(new RatingTypeListVM(r.ToList()))); - } - - public static void CreateTextModuleListVMAsync(Action pCallBack, bool pIsInAdministrationView = false, bool pIsInTextModuleEditor = false) - { - ServiceFacade.DoOperationsServiceAsync(s1 => s1.GetTextModules(pIsInTextModuleEditor, BeWoApp.LoggedOnEmployee.EmployeeOid.Value, BeWoApp.LoggedOnUser.HasRight(UserRightType.TextbausteineAlleAnsehen), pIsInAdministrationView), r1 => ServiceFacade.DoOperationsServiceAsync( - s2 => s2.GetAllServiceCategories(), - s3 => - { - var x = r1.FirstOrDefault(tm => tm.TextModuleOid == 41); - - pCallBack(new TextModuleListVM(r1.OrderBy(o => o.Name), s3)); - })); - } - - public static void CreateMedArtListVMAsync(Action pCallBack) - { - ServiceFacade.DoCustomerServiceAsync(s => s.GetAllMedArten(), - r => pCallBack(new MedArtListVM(r.ToList()))); - } - - public static void CreateServiceDescriptionListVMAsync(Action pCallBack) - { - ServiceFacade.DoOperationsServiceAsync( - s1 => s1.GetAllServiceDescriptions(), r1 => ServiceFacade.DoOperationsServiceAsync(s2 => s2.GetAllServiceCategories(), - r2 => pCallBack(new ServiceDescriptionListVM(r1.Where(sr => sr.ScopeType == ScopeTypeId.Global).ToList(), r2.Where(sc => sc.ScopeType == ScopeTypeId.Global).ToList())))); - } - - public static void CreateAdditionalServiceRegionListVMAsync(Action pCallBack) - { - ServiceFacade.DoOperationsServiceAsync(s1 => s1.GetAllAdditionalServiceRegion(), r1 => ServiceFacade.DoOperationsServiceAsync(s2 => s2.GetAllAdditionalService(), r2 => pCallBack(new AdditionalServiceRegionListVM(r1.ToList(), r2.ToList())))); - } - - public static void CreateServiceRecordVMAsync(long pEmployeeOid, Action pCallBack) - { - Cache.GetInstance().GetServiceCategoryDescriptionDict( - dict => - Cache.GetInstance().GetAllValueListEntrysByTypeAsync( - ValueListEntryType.SupportConceptGoalCategoryType, - goalCats => - Cache.GetInstance().GetAllValueListEntrysByTypeAsync( - ValueListEntryType.SupportConceptIndividualGoalCategoryType, - iGoalCats => - Cache.GetInstance().GetAllValueListEntrysByTypeAsync(ValueListEntryType.SupportConceptGoalType, - goals => Cache.GetInstance().GetAllValueListEntrysByTypeAsync(ValueListEntryType.DocumentType, - docTypes => - ServiceFacade.DoCustomerServiceAsync( - s => s.GetAllActiveWohnheimeCompact(), cb => ServiceFacade.DoCustomerServiceAsync(s2 => s2.GetAllDarreichungsformen(), abc => pCallBack(new ServiceRecordListVM(dict, goalCats, iGoalCats, goals, cb, docTypes, abc))))))))); - } - - public static void CreateMedRecordVMAsync(long pCustomerOid, Action pCallback) - { - ServiceFacade.DoCustomerServiceAsync(s => s.GetMedRecordsForCustomer(pCustomerOid), cb => pCallback(new MedRecordListVM(cb)), true); - } - - public static void CreateSettlementListForCostBearerAndPeriod(long costBearerOid, DateTime periodStart, DateTime periodEnd, Action callback) - { - ServiceFacade.DoAccountingServiceAsync( - s => s.GetSettlementInvoicesForCostBearerAndPeriod(costBearerOid, periodStart, periodEnd), - r => - { - r.Sort( - (dc1, dc2) => - { - if (dc2.InvoiceDate == null) - { - return -1; - } - - if (dc1.InvoiceDate == null) - { - return 1; - } - - return dc2.InvoiceDate.Value.CompareTo(dc1.InvoiceDate.Value); - }); - callback(new SettlementListVM(r)); - }); - } - - public static void CreateSettlementListForSupportConceptVMAsync(long supportconceptOid, Action callback) - { - ServiceFacade.DoAccountingServiceAsync( - s => s.GetSettlementInvoicesForSupportConcept(supportconceptOid), - r => - { - r.Sort( - (dc1, dc2) => - { - if (dc2.InvoiceDate == null) - { - return -1; - } - - if (dc1.InvoiceDate == null) - { - return 1; - } - - return dc2.InvoiceDate.Value.CompareTo(dc1.InvoiceDate.Value); - }); - callback(new SettlementListVM(r)); - }); - } - - public static void CreateSettlementVMAsync(long pSupportConcept2CostBearerOid, Action pCallBack) - { - ServiceFacade.DoOperationsServiceAsync(s => s.GenerateInitialSettlementDC(pSupportConcept2CostBearerOid), r => pCallBack(new SettlementVM(r))); - } - - public static void CreateSupportConceptCostBearerRelVMAsync(List pList, ObservableSortCollection budgets, Action pCallBack) - { - pCallBack(new SupportConceptCostBearerRelListVM(pList, budgets)); - } - - public static void CreateSupportConceptGoalListVMAsync(ValueListEntryType pType, ValueListEntryType pParentType, Action pCallBack) - { - Cache.GetInstance().GetAllValueListEntrysByTypeAsync(pType, r1 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync(pParentType, r2 => pCallBack(new SupportConceptGoalListVM(r1, r2)))); - } - - public static void CreateSupportConceptVMAsync(Action pCallback) - { - CreateSupportConceptVMAsync(new SupportConceptDC(), pCallback, true); - } - - public static void CreateSupportConceptVMAsync(long pOid, Action pCallback) - { - ServiceFacade.DoCustomerServiceAsync(s => s.LoadSupportConcept(pOid), - r => CreateSupportConceptVMAsync(r, pCallback, false)); - } - - public static void CreateSupportConceptVMAsync(SupportConceptDC dc, Action pCallBack, bool initOriginator) - { - Cache.GetInstance().GetAllValueListEntrysByTypeAsync( - ValueListEntryType.SupportConceptGoalCategoryType, - r1 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync( - ValueListEntryType.SupportConceptGoalType, - r2 => Cache.GetInstance().GetServiceCategoryDescriptionDict( - dict => ServiceFacade.DoOperationsServiceAsync(s => s.GetAllBudgets(), - r3 => - { - var vm = new SupportConceptVM(dc, r1, r2, dict, r3); - if (initOriginator) - { - vm.Originator = BeWoApp.LoggedOnUser.Employee; - } - - pCallBack(vm); - })))); - } - - public static void CreateTeamVMAsync(Action pCallBack) - { - pCallBack(new TeamVM(new TeamDC())); - } - - public static void CreateTeamVMAsync(long pTeamOid, Action pCallBack) - { - ServiceFacade.DoEmployeeServiceAsync(s => s.LoadTeam(pTeamOid), cb => pCallBack(new TeamVM(cb))); - } - - public static void CreateGroupOfPeopleVMAsync(Action pCallBack) - { - pCallBack(new GroupOfPeopleVM(new GroupOfPeopleDC())); - } - - public static void CreateGroupOfPeopleVMAsync(long pGroupOfPeopleOid, Action pCallBack) - { - ServiceFacade.DoEmployeeServiceAsync(s => s.LoadGroupOfPeople(pGroupOfPeopleOid), cb => pCallBack(new GroupOfPeopleVM(cb))); - } - - public static void CreateGroupOfPeopleListVMAsync(Action pCallBack) - { - ServiceFacade.DoEmployeeServiceAsync(s => s.GetAllGroups(BeWoApp.LoggedOnEmployee.EmployeeOid), cb => pCallBack(new GroupOfPeopleListVM(cb))); - } - - public static void CreateAdditinoalServiceGroupOfPeopleListVMAsync(Action pCallBack) - { - ServiceFacade.DoOperationsServiceAsync(s => s.GetAllAdditionalServiceGroupOfPeople(), cb => pCallBack(new AdditionalServiceGroupOfPeopleListVM(cb))); - } - - public static void CreateUserGroupVMAsync(long pOid, Action pCallBack) - { - ServiceFacade.DoUserServiceAsync(s => s.LoadUserGroup(pOid), r => pCallBack(new UserGroupVM(r)), true); - } - - public static void CreateUserGroupVMAsync(Action pCallBack) - { - pCallBack(new UserGroupVM(new UserGroupDC())); - } - - public static void CreateUserVMAsync(long pUserOid, Action pCallBack) - { - ServiceFacade.DoUserServiceAsync(s => s.LoadUser(pUserOid), r1 => ServiceFacade.DoUserServiceAsync(s => s.GetAllUserGroups(), r2 => pCallBack(new UserVM(r1, r2)), true), true); - } - - public static void CreateUserVMAsync(Action pCallBack) - { - ServiceFacade.DoUserServiceAsync(s => s.GetAllUserGroups(), cb => pCallBack(new UserVM(new UserDC(), cb)), true); - } - - public static void CreateValueListVMAsync(ValueListEntryType pType, Action pCallBack) - { - ServiceFacade.DoValueListServiceAsync(s => s.GetAllValueListEntrysByType(pType), r => pCallBack(new ValueListEntryListVM(pType, r))); - } - - - public static void CreateGoalCategoryVMAsync(Action pCallBack, bool pIsIncludingIndividualGoals = false) - { - var typeList = new List { ValueListEntryType.SupportConceptGoalType, ValueListEntryType.SupportConceptGoalCategoryType }; - if (pIsIncludingIndividualGoals) - { - typeList.Add(ValueListEntryType.SupportConceptIndividualGoalCategoryType); - typeList.Add(ValueListEntryType.SupportConceptIndividualGoalType); - } - - ServiceFacade.DoValueListServiceAsync( - s => s.GetAllValueListEntrysByTypes(typeList), - cb => pCallBack(new GenericValueListEntryListVM(cb))); - } - - public static void CreateEmploymentTypeListVMAsync(Action pCallBack) - { - ServiceFacade.DoEmployeeServiceAsync(s => s.GetAllEmploymentTypes(), r => pCallBack(new EmploymentTypeListVM(r))); - } - - private static void InternalCreateCustomerVM(CustomerDC pCustomerDC, Action pCallBack) - { - var list = new List - { - ValueListEntryType.DisabilityType, - ValueListEntryType.CustomerCareType, - ValueListEntryType.PlacementObjectiveType, - ValueListEntryType.TerminationReasonType, - ValueListEntryType.Nationality, - ValueListEntryType.Aufenthaltsstatus, - ValueListEntryType.RoleInFamily, - ValueListEntryType.NotizenKategorieCustomer, - ValueListEntryType.Auftragsherkunft, - ValueListEntryType.Vermittlungsgrundlage - }; - - ServiceFacade.DoValueListServiceAsync( - s => s.GetAllValueListEntrysByTypes(list), - cb => ServiceFacade.DoEmployeeServiceAsync(s2 => s2.GetAllAssessmentSheetCategories(), - cb2 => ServiceFacade.DoEmployeeServiceAsync(s3 => s3.GetAllAssessmentSheetValues(), - cb3 => ServiceFacade.DoCustomerServiceAsync(s4 => s4.GetAllMedArten(), - cb4 => pCallBack(new CustomerVM(pCustomerDC, cb, cb2, cb3, cb4)))))); - } - - public static void CreateAppointmentCategoryListVMAsync(Action pCallBack) - { - ServiceFacade.DoCustomerServiceAsync( - s => s.GetAllAppointmentCategories(), cats => pCallBack(new AppointmentCategoryListVM(cats))); - } - - public static WohnheimbuchungEmployeeRelListVM CreateEmployeeWohnheimbuchungsListVM(IEnumerable pList) - { - return new WohnheimbuchungEmployeeRelListVM(pList); - } - - public static Wohnheimbuchung2Costbearer2SupportConceptRelListVM CreateSupportConceptWohnheimbuchungsListVM(IEnumerable pList) - { - return new Wohnheimbuchung2Costbearer2SupportConceptRelListVM(pList); - } - - public static void CreateWohnheimbuchungsVMAsync(long? pOid, Action pCallBack) - { - Cache.GetInstance().GetServiceCategoryDescriptionDict( - dict => - { - if (pOid == null) - { - pCallBack(new WohnheimbuchungsVM(new WohnheimbuchungDC(), dict)); - } - else - { - ServiceFacade.DoCustomerServiceAsync(s => s.GetWohnheimbuchung(pOid.Value), cb => pCallBack(new WohnheimbuchungsVM(cb, dict))); - } - }); - } - - public static SupportConceptApprovalPeriodEmployeeRelListVM CreateSupportConceptApprovalPeriodEmployeeRelListVM(IEnumerable pList) - { - return new SupportConceptApprovalPeriodEmployeeRelListVM(pList); - } - - public static ArbeitszeitEintragListVM CreateArbeitszeitEintragListVm(IEnumerable pList) - { - return new ArbeitszeitEintragListVM(pList); - } - - public static void CreateSbdAdminVMAsync(Action pCallBack) - { - ServiceFacade.DoOperationsServiceAsync(s => s.GetSbdConfig(), r => - { - pCallBack(new SbdConfigVM(r)); - }); - } - - public static List CreateSupportConceptList() - { - List allSupportConcepts = new List(); - List activeSupportConcepts = new List(); - - allSupportConcepts = ServiceFacade.DoCustomerServiceSync( - s => s.GetAllSupportConceptsCompact(BeWoApp.LoggedOnUser.Employee.EmployeeOid)); - - foreach (var sc in allSupportConcepts) - { - if (!sc.IsDeleted) - activeSupportConcepts.Add(sc); - } - - return activeSupportConcepts; - } - public static List CreateCustomerList() - { - List allCustomers = new List(); - List activeCustomers = new List(); - - allCustomers = ServiceFacade.DoCustomerServiceSync( - s => s.GetAllCustomersCompact(BeWoApp.LoggedOnUser.Employee.EmployeeOid)); - - foreach (var customer in allCustomers) - { - if (!customer.IsDeleted) - activeCustomers.Add(customer); - } - - return activeCustomers; - } - public static List CreateOrganisationList() - { - List allOrganisations = new List(); - - allOrganisations = ServiceFacade.DoCustomerServiceSync(s => s.GetAllActiveOrganisationsCompact()); - - return allOrganisations; - } - public static List CreatePeopleList() - { - List allPeople = new List(); - List activePeople = new List(); - - allPeople = ServiceFacade.DoCustomerServiceSync(s => s.GetAllPersonsByTypeCompact(PersonType.Others)); - - foreach (var person in allPeople) - { - if (!person.IsDeleted) - activePeople.Add(person); - } - - return activePeople; - } - public static List CreateEmployeeList() - { - List allEmployee = new List(); - - allEmployee = ServiceFacade.DoEmployeeServiceSync(s => s.GetAllActiveEmployeesCompact()); - - return allEmployee; - } - public static List CreateTeamList() - { - List allTeams = new List(); - - allTeams = ServiceFacade.DoEmployeeServiceSync(s => s.GetAllTeamsCompact()); - - return allTeams; - - } - public static List CreateUserList() - { - List allUsers = new List(); - - allUsers = ServiceFacade.DoUserServiceSync(s => s.GetAllUsersCompact()); - - return allUsers; - } - public static List CreateUserGroupList() - { - List allUserGroups = new List(); - - allUserGroups = ServiceFacade.DoUserServiceSync(s => s.GetAllUserGroups()); - return allUserGroups; - } - - public static List CreateFolderList(TableID tid, long objectOid) - { - List folderList = new List(); - folderList = ServiceFacade.DoOperationsServiceSync(s => s.GetFolderTree(tid, objectOid)); - - return folderList; - } - - public static void CreateWohneinheitListVMs(List dcs, out WohneinheitListVM einheit_vm_list, out WohneinheitBelegungListVM beleg_vm_list) - { - einheit_vm_list = new WohneinheitListVM(dcs); - - var beleg_dc_list = new List(); - var beleg_dc2einheit_vm = new Dictionary(); - foreach (var einheit_vm in einheit_vm_list.VMList) - { - var einheit_dc = einheit_vm.DataContract; - - if (einheit_dc.Belegungen is null) - continue; - - foreach (var beleg_dc in einheit_dc.Belegungen) - { - beleg_dc_list.Add(beleg_dc); - beleg_dc2einheit_vm.Add(beleg_dc, einheit_vm); - } - } - - beleg_vm_list = new WohneinheitBelegungListVM(beleg_dc_list.OrderBy(x => x.Oid).ToList()); - - foreach (var beleg_vm in beleg_vm_list.VMList) - { - var beleg_dc = beleg_vm.DataContract; - - beleg_vm.Wohneinheit = beleg_dc2einheit_vm[beleg_dc]; - } - - einheit_vm_list.VMList.Sort(WohneinheitVM.Compare); - } - } + public static class VMFactory + { + public static void CreateAbsenceReasonListVMAsync(Action pCallBack) + { + ServiceFacade.DoCustomerServiceAsync(s => s.GetAllAbsenceReasons(), r => pCallBack(new AbsenceReasonListVM(r))); + } + + public static void CreateAbsenceTimeListVMAsync(IEnumerable pDCs, AbsenceReasonVisibilityType? type, Action pCallBack) + { + ServiceFacade.DoCustomerServiceAsync(s => s.GetAllAbsenceReasons(), cb => pCallBack(new AbsenceTimeListVM(pDCs, cb.Where(a => !a.Sichtbarkeit.HasValue || a.Sichtbarkeit.Value == AbsenceReasonVisibilityType.All || a.Sichtbarkeit.Value == type).ToList()))); + } + + public static AbsenceTimeListVM CreateAbsenceTimeListVM(IEnumerable pDCs, AbsenceReasonVisibilityType? type) + { + var list = ServiceFacade.DoCustomerServiceSync(s => s.GetAllAbsenceReasons()); + + return new AbsenceTimeListVM(pDCs, list.Where(a => !a.Sichtbarkeit.HasValue || a.Sichtbarkeit.Value == AbsenceReasonVisibilityType.All || a.Sichtbarkeit.Value == type).ToList()); + } + + public static void CreateOvertimeListVMAsync(IEnumerable pDCs, Action pCallBack) + { + //ServiceFacade.DoValueListServiceAsync(v => v.GetAllValueListEntrysByType(ValueListEntryType.Auszahlungsart), cb => pCallBack(new OvertimeListVM(pDCs))); + ServiceFacade.DoEmployeeServiceAsync(v => v.GetAllOvertimes(), cb => pCallBack(new OvertimeListVM(pDCs))); + } + + public static void CreateAccountingBookingVMAsnyc(Action pCallBack) + { + Cache.GetInstance().GetSupportConceptTree( + tree => Cache.GetInstance().GetAllValueListEntrysByTypeAsync(ValueListEntryType.AccountingTransactionType, categories => pCallBack(new AccountingBookingVM(tree, categories)))); + } + + public static void CreateAccountingTransactionListVMAsnyc(DateTimeSpan pSpan, long? pSupportConceptOid, long? pCostBearerSupportConceptRelOid, Action pCallBack) + { + ServiceFacade.DoOperationsServiceAsync(s => s.GetAccountingTransactions(pSpan, pSupportConceptOid, pCostBearerSupportConceptRelOid), r => pCallBack(new AccountingTransactionListVM(r))); + } + + public static void CreateAssessmentSheetCategoryListVM(Action cb) + { + ServiceFacade.DoEmployeeServiceAsync( + s1 => s1.GetAllAssessmentSheetValues(), v => ServiceFacade.DoEmployeeServiceAsync(s => s.GetAllAssessmentSheetCategories(), dcs => cb(new AssessmentSheetCategoryListVM(dcs, v)))); + } + + public static void CreateAssessmentSheetValueListVM(Action cb) + { + ServiceFacade.DoEmployeeServiceAsync(s => s.GetAllAssessmentSheetValues(), dcs => cb(new AssessmentSheetValueListVM(dcs))); + } + + public static void CreateBookingVMAsync(DateTimeSpan pSpan, Action pCallBack) + { + ServiceFacade.DoResourceServiceAsync(s => s.GetAllBookings(pSpan.StartDateTime, pSpan.EndDateTime), r => pCallBack(new BookingVM(r))); + } + + public static CustomerEmployeeRelationListVM CreateCustomerEmployeeRelationListVM(List pList) + { + var valueList = Cache.GetInstance().GetAllValueListEntrysByTypeSync(ValueListEntryType.StaffRoleType); + return new CustomerEmployeeRelationListVM(pList, valueList); + } + + public static WohnheimEmployeeRelationListVM CreateWohnheimEmployeeRelationListVM(List pList) + { + var valueList = Cache.GetInstance().GetAllValueListEntrysByTypeSync(ValueListEntryType.StaffRoleType); + return new WohnheimEmployeeRelationListVM(pList, valueList); + } + + public static WohnheimCustomerRelationListVM CreateWohnheimCustomerRelationListVM(List pList) + { + var valueList = Cache.GetInstance().GetAllValueListEntrysByTypeSync(ValueListEntryType.StaffRoleType); + return new WohnheimCustomerRelationListVM(pList, valueList); + } + + public static GoalRatingListVM CreateGoalRatingListVM(List ratingList) + { + var typeList = Cache.GetInstance().GetAllRatingTypeList(); + return new GoalRatingListVM(ratingList, typeList); + } + + public static void CreateOrganisationPersonRelationListVMAsync(List pDCs, Action pCallBack) + { + pCallBack(new OrganisationPersonRelationListVM(pDCs)); + } + + public static CustomerPersonRelationListVM CreateCustomerEnvironmentPersonRelListVM(List pList, ValueListEntryType vtype) + { + var valueList = Cache.GetInstance().GetAllValueListEntrysByTypeSync(vtype); + + return new CustomerPersonRelationListVM(pList, valueList); + } + + public static void CreateCustomerEnvironmentOrganisationRelListVMAsync(List pList, Action pCallBack) + { + Cache.GetInstance().GetAllValueListEntrysByTypeAsync(ValueListEntryType.EnvironmentOrganisationType, r => pCallBack(new CustomerOrganisationRelationListVM(pList, r))); + } + + public static CustomerOrganisationRelationListVM CreateCustomerEnvironmentOrganisationRelListVM(List pList) + { + var valueList = Cache.GetInstance().GetAllValueListEntrysByTypeSync(ValueListEntryType.EnvironmentOrganisationType); + + return new CustomerOrganisationRelationListVM(pList, valueList); + } + + public static MedikamentenverordnungslisteListVM CreateMedikementenverordnungslisteListVM(IEnumerable pList) + { + var darreichungsformen = ServiceFacade.DoCustomerServiceSync(s => s.GetAllDarreichungsformen()); + var depotrhythmen = ServiceFacade.DoCustomerServiceSync(s => s.GetAllDepotRhythmen()); + + return new MedikamentenverordnungslisteListVM(pList, darreichungsformen, depotrhythmen); + } + + public static BargeldtransaktionsListVM CreateBargeldtransaktionsListVM(IEnumerable pList) + { + return new BargeldtransaktionsListVM(pList); + } + + public static void CreateCustomerVMAsync(long pOid, Action pCallBack) + { + ServiceFacade.DoCustomerServiceAsync(s => s.LoadCustomer(pOid), cb => CreateCustomerVMAsync(cb, pCallBack)); + } + + public static void CreateCustomerVMAsync(Action pCallBack) + { + ServiceFacade.DoOperationsServiceAsync( + s => s.GetVarFieldDefs(TableID.Customer), + cb => CreateCustomerVMAsync( + new CustomerDC + { + CustomerVarFields = cb + }, + pCallBack)); + } + + public static void CreateCustomerVMAsync(CustomerDC pCustomerDC, Action pCallBack) + { + if (BeWoApp.ICD10Diagnosis == null) + { + ServiceFacade.DoOperationsServiceAsync( + s => s.GetCompressedICD10Diagnosis(), + st => + { + st = Utils.Decompress(st); + var ds = st.Split(Environment.NewLine).ToDictionary(line => line.Substring(0, line.IndexOf(';')), line => line.Substring(line.IndexOf(';') + 1)); + + BeWoApp.ICD10Diagnosis = ds; + InternalCreateCustomerVM(pCustomerDC, pCallBack); + }); + } + else + { + InternalCreateCustomerVM(pCustomerDC, pCallBack); + } + } + + public static void CreateEmployeeVMAsync(long pOid, Action pCallBack) + { + ServiceFacade.DoEmployeeServiceAsync( + s => s.LoadEmployee(pOid), + r => + { + CreateEmployeeVMAsync(r, pCallBack); + }); + } + + public static void CreateEmployeeVMAsync(EmployeeDC pEmployeeDC, Action pCallBack) + { + ServiceFacade.DoEmployeeServiceAsync(s => s.GetAllEmploymentTypes(), + r1 => + Cache.GetInstance().GetAllValueListEntrysByTypeAsync( + ValueListEntryType.StaffQualificationsType, + r2 => + Cache.GetInstance() + .GetAllValueListEntrysByTypeAsync(ValueListEntryType.StaffActivityFocusType, + r3 => + Cache.GetInstance() + .GetAllValueListEntrysByTypeAsync(ValueListEntryType.ContractType, + r4 => + Cache.GetInstance() + .GetAllValueListEntrysByTypeAsync(ValueListEntryType.Nationality, + nat => + Cache.GetInstance() + .GetAllValueListEntrysByTypeAsync(ValueListEntryType.NotizenKategorieEmployee, + r7 => + ServiceFacade.DoEmployeeServiceAsync( + e => + e.GetAllAuszahlungsarten(), + r6 => + ServiceFacade.DoOperationsServiceAsync( + s => + s.GetSbdConfig(), + config => + pCallBack(new EmployeeVM(pEmployeeDC, r1, nat, r2, r3, r6, r4, config.Stundensaetze, r7)))))))))); + } + + public static void CreateEmployeeVMAsync(Action pCallBack) + { + CreateEmployeeVMAsync(new EmployeeDC(), pCallBack); + } + + public static void CreateWohnheimVMAsync(long pOid, List customers, Action pCallBack) + { + ServiceFacade.DoWohnheimServiceAsync( + s => s.LoadWohnheim(pOid), + r => + { + CreateWohnheimVMAsync(r, customers, pCallBack); + }); + } + + public static void CreateWohnheimVMAsync(WohnheimDC pWohnheimDC, List customers, Action pCallBack) + { + pCallBack(new WohnheimVM(pWohnheimDC, customers)); + } + + public static void CreateWohnheimVMAsync(List customers, Action pCallBack) + { + CreateWohnheimVMAsync(new WohnheimDC(), customers, pCallBack); + } + + public static void CreateEquityInvoiceBaselListVMAsync(long supportconeptOid, Action callback) + { + ServiceFacade.DoAccountingServiceAsync( + s => s.GetInvoiceBasesForSupportConcept(InvoiceType.CustomerEquity, supportconeptOid), + r => + { + r.Sort( + (dc1, dc2) => + { + if (dc2.InvoiceDate == null) + { + return -1; + } + + if (dc1.InvoiceDate == null) + { + return 1; + } + + return dc2.InvoiceDate.Value.CompareTo(dc1.InvoiceDate.Value); + }); + callback(new InvoiceBaseListVM(r)); + }); + } + + public static void CreateGeneralInvoiceBaselListVMAsync(CompactCustomerDC customer, CompactOrganisationDC organisation, CompactPersonDC person, Action callback) + { + if (organisation != null) + { + ServiceFacade.DoAccountingServiceAsync( + s => s.GetGeneralInvoiceBasesForOrganisation(organisation.OrganisationOid), + r => + { + r.Sort( + (dc1, dc2) => + { + if (dc2.InvoiceDate == null) + { + return -1; + } + + if (dc1.InvoiceDate == null) + { + return 1; + } + + return dc2.InvoiceDate.Value.CompareTo(dc1.InvoiceDate.Value); + }); + callback(new InvoiceBaseListVM(r)); + }); + } + else if (person != null) + { + ServiceFacade.DoAccountingServiceAsync( + s => s.GetGeneralInvoiceBasesForPerson(person.PersonOid), + r => + { + r.Sort( + (dc1, dc2) => + { + if (dc2.InvoiceDate == null) + { + return -1; + } + + if (dc1.InvoiceDate == null) + { + return 1; + } + + return dc2.InvoiceDate.Value.CompareTo(dc1.InvoiceDate.Value); + }); + callback(new InvoiceBaseListVM(r)); + }); + } + else if (customer != null) + { + ServiceFacade.DoAccountingServiceAsync( + s => s.GetGeneralInvoiceBasesForCustomer(customer.CustomerOid), + r => + { + r.Sort( + (dc1, dc2) => + { + if (dc2.InvoiceDate == null) + { + return -1; + } + + if (dc1.InvoiceDate == null) + { + return 1; + } + + return dc2.InvoiceDate.Value.CompareTo(dc1.InvoiceDate.Value); + }); + callback(new InvoiceBaseListVM(r)); + }); + } + } + + public static void CreateInvoiceListVMAsync(Action callback) + { + ServiceFacade.DoCustomerServiceAsync( + s1 => s1.GetAllActiveSupportConceptsCompact(), + r1 => + ServiceFacade.DoCustomerServiceAsync( + s2 => s2.GetAllActiveOrganisationsCompact(), r2 => ServiceFacade.DoOperationsServiceAsync(s3 => s3.GetAllActiveInvoices(), r3 => callback(new InvoiceListVM(r2, r1, r3))))); + } + + public static void CreateInvoiceOverviewListVM(Action callback) + { + ServiceFacade.DoAccountingServiceAsync(s => s.GetAllActiveInvoiceBases(), cb => callback(new InvoiceBaseListVM(cb))); + } + + public static void CreateOrganisationVMAsync(long pOid, Action pCallBack) + { + ServiceFacade.DoCustomerServiceAsync( + s => s.LoadOrganisation(pOid), + r1 => ServiceFacade.DoValueListServiceAsync(s1 => s1.GetAllValueListEntrysByType(ValueListEntryType.StaffQualificationsType), r2 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync(ValueListEntryType.OrganisationFunctionType, + r4 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync(ValueListEntryType.RoleInOrganisationType, + r3 => pCallBack(new OrganisationVM(r1, r2, r4, r3)))))); + } + + public static void CreateOrganisationVMAsync(Action pCallBack) + { + ServiceFacade.DoValueListServiceAsync( + s1 => s1.GetAllValueListEntrysByType(ValueListEntryType.StaffQualificationsType), + r1 => + ServiceFacade.DoOperationsServiceAsync( + s => s.GetVarFieldDefs(TableID.Organisation), + r2 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync( + ValueListEntryType.OrganisationFunctionType, + r4 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync( + ValueListEntryType.RoleInOrganisationType, + r3 => pCallBack(new OrganisationVM( + new OrganisationDC + { + VarFields = r2 + }, r1, r4, r3)))))); + } + + //public static void CreatePersonOrganisationRelationVMAsync(CompactOrganisationDC pOrganisation, Action pCallBack) + //{ + // pCallBack( + // new PersonOrganisationRelationVM( + // new Organisation2PersonDC + // { + // OrganisationOid = pOrganisation.OrganisationOid, + // OrganisationName = pOrganisation.Name, + // OrganisationVersion = pOrganisation.OrganisationVersion + // })); + //} + + public static void CreatePersonVMAsync(Action pCallBack) + { + Cache.GetInstance().GetAllValueListEntrysByTypeAsync( + ValueListEntryType.TitleType, + r1 => + ServiceFacade.DoOperationsServiceAsync( + s => s.GetVarFieldDefs(TableID.Person), + r2 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync( + ValueListEntryType.FunctionType, + r4 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync( + ValueListEntryType.RoleInOrganisationType, + r5 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync( + ValueListEntryType.Nationality, + r3 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync( + ValueListEntryType.Aufenthaltsstatus, + r6 => pCallBack( + new PersonVM( + new PersonDC + { + VarFields = r2 + }, + r1, + r4, + r5, + r3, + r6)))))))); + } + + public static void CreatePersonVMAsync(long pOid, Action pCallBack) + { + ServiceFacade.DoCustomerServiceAsync( + s => s.LoadPerson(pOid), + cb => + Cache.GetInstance().GetAllValueListEntrysByTypeAsync( + ValueListEntryType.TitleType, + r1 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync(ValueListEntryType.FunctionType, + r3 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync(ValueListEntryType.RoleInOrganisationType, + r4 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync(ValueListEntryType.Nationality, + r2 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync(ValueListEntryType.Aufenthaltsstatus, + r5 => pCallBack(new PersonVM(cb, r1, r3, r4, r2, r5)))))))); + } + + public static void CreateResourceListVMAsync(Action pCallBack) + { + ServiceFacade.DoResourceServiceAsync( + s => s.GetAllResources(), + r1 => ServiceFacade.DoValueListServiceAsync(s => s.GetAllValueListEntrysByType(ValueListEntryType.ResourceCategory), r2 => pCallBack(new ResourceListVM(r1, r2)))); + } + + public static void CreateServiceCategoryListVMAsync(Action pCallBack) + { + ServiceFacade.DoOperationsServiceAsync(s => s.GetAllServiceCategories(), + r => pCallBack(new ServiceCategoryListVM(r.Where(sc => sc.ScopeType == ScopeTypeId.Global).ToList()))); + } + + public static void CreateAdditionalServiceListVMAsync(Action pCallBack) + { + ServiceFacade.DoOperationsServiceAsync(s => s.GetAllAdditionalService(), + r => pCallBack(new AdditionalServiceListVM(r.ToList()))); + } + + public static void CreateAuszahlungsartenListVMAsync(Action pCallBack) + { + ServiceFacade.DoEmployeeServiceAsync(s => s.GetAllAuszahlungsarten(), + r => pCallBack(new AuszahlungsartListVM(r.ToList()))); + } + + public static void CreateBudgetListVMAsync(Action pCallBack) + { + ServiceFacade.DoOperationsServiceAsync(s => s.GetAllBudgets(), + r => pCallBack(new BudgetListVM(r.ToList()))); + } + + public static void CreatePreisListVMAsync(Action pCallBack) + { + ServiceFacade.DoOperationsServiceAsync(s => s.GetAllPreise(), + r => pCallBack(new PreisListVM(r.ToList()))); + } + + public static void CreateDienstListVMAsync(Action pCallBack) + { + ServiceFacade.DoOperationsServiceAsync(s => s.GetAllDienste(null), + r => pCallBack(new DienstInfoListVM(r.ToList()))); + } + + public static void CreateRatingTypeListVMAsync(Action pCallBack) + { + ServiceFacade.DoOperationsServiceAsync(s => s.GetAllRatingTypes(), + r => pCallBack(new RatingTypeListVM(r.ToList()))); + } + + public static void CreateTextModuleListVMAsync(Action pCallBack, bool pIsInAdministrationView = false, bool pIsInTextModuleEditor = false) + { + ServiceFacade.DoOperationsServiceAsync(s1 => s1.GetTextModules(pIsInTextModuleEditor, BeWoApp.LoggedOnEmployee.EmployeeOid.Value, BeWoApp.LoggedOnUser.HasRight(UserRightType.TextbausteineAlleAnsehen), pIsInAdministrationView), r1 => ServiceFacade.DoOperationsServiceAsync( + s2 => s2.GetAllServiceCategories(), + s3 => + { + var x = r1.FirstOrDefault(tm => tm.TextModuleOid == 41); + + pCallBack(new TextModuleListVM(r1.OrderBy(o => o.Name), s3)); + })); + } + + public static void CreateMedArtListVMAsync(Action pCallBack) + { + ServiceFacade.DoCustomerServiceAsync(s => s.GetAllMedArten(), + r => pCallBack(new MedArtListVM(r.ToList()))); + } + + public static void CreateServiceDescriptionListVMAsync(Action pCallBack) + { + ServiceFacade.DoOperationsServiceAsync( + s1 => s1.GetAllServiceDescriptions(), r1 => ServiceFacade.DoOperationsServiceAsync(s2 => s2.GetAllServiceCategories(), + r2 => pCallBack(new ServiceDescriptionListVM(r1.Where(sr => sr.ScopeType == ScopeTypeId.Global).ToList(), r2.Where(sc => sc.ScopeType == ScopeTypeId.Global).ToList())))); + } + + public static void CreateAdditionalServiceRegionListVMAsync(Action pCallBack) + { + ServiceFacade.DoOperationsServiceAsync(s1 => s1.GetAllAdditionalServiceRegion(), r1 => ServiceFacade.DoOperationsServiceAsync(s2 => s2.GetAllAdditionalService(), r2 => pCallBack(new AdditionalServiceRegionListVM(r1.ToList(), r2.ToList())))); + } + + public static void CreateServiceRecordVMAsync(long pEmployeeOid, Action pCallBack) + { + Cache.GetInstance().GetServiceCategoryDescriptionDict( + dict => + Cache.GetInstance().GetAllValueListEntrysByTypeAsync( + ValueListEntryType.SupportConceptGoalCategoryType, + goalCats => + Cache.GetInstance().GetAllValueListEntrysByTypeAsync( + ValueListEntryType.SupportConceptIndividualGoalCategoryType, + iGoalCats => + Cache.GetInstance().GetAllValueListEntrysByTypeAsync(ValueListEntryType.SupportConceptGoalType, + goals => Cache.GetInstance().GetAllValueListEntrysByTypeAsync(ValueListEntryType.DocumentType, + docTypes => + ServiceFacade.DoCustomerServiceAsync( + s => s.GetAllActiveWohnheimeCompact(), cb => ServiceFacade.DoCustomerServiceAsync(s2 => s2.GetAllDarreichungsformen(), abc => pCallBack(new ServiceRecordListVM(dict, goalCats, iGoalCats, goals, cb, docTypes, abc))))))))); + } + + public static void CreateMedRecordVMAsync(long pCustomerOid, Action pCallback) + { + ServiceFacade.DoCustomerServiceAsync(s => s.GetMedRecordsForCustomer(pCustomerOid), cb => pCallback(new MedRecordListVM(cb)), true); + } + + public static void CreateSettlementListForCostBearerAndPeriod(long costBearerOid, DateTime periodStart, DateTime periodEnd, Action callback) + { + ServiceFacade.DoAccountingServiceAsync( + s => s.GetSettlementInvoicesForCostBearerAndPeriod(costBearerOid, periodStart, periodEnd), + r => + { + r.Sort( + (dc1, dc2) => + { + if (dc2.InvoiceDate == null) + { + return -1; + } + + if (dc1.InvoiceDate == null) + { + return 1; + } + + return dc2.InvoiceDate.Value.CompareTo(dc1.InvoiceDate.Value); + }); + callback(new SettlementListVM(r)); + }); + } + + public static void CreateSettlementListForSupportConceptVMAsync(long supportconceptOid, Action callback) + { + ServiceFacade.DoAccountingServiceAsync( + s => s.GetSettlementInvoicesForSupportConcept(supportconceptOid), + r => + { + r.Sort( + (dc1, dc2) => + { + if (dc2.InvoiceDate == null) + { + return -1; + } + + if (dc1.InvoiceDate == null) + { + return 1; + } + + return dc2.InvoiceDate.Value.CompareTo(dc1.InvoiceDate.Value); + }); + callback(new SettlementListVM(r)); + }); + } + + public static void CreateSettlementVMAsync(long pSupportConcept2CostBearerOid, Action pCallBack) + { + ServiceFacade.DoOperationsServiceAsync(s => s.GenerateInitialSettlementDC(pSupportConcept2CostBearerOid), r => pCallBack(new SettlementVM(r))); + } + + public static void CreateSupportConceptCostBearerRelVMAsync(List pList, ObservableSortCollection budgets, Action pCallBack) + { + pCallBack(new SupportConceptCostBearerRelListVM(pList, budgets)); + } + + public static void CreateSupportConceptGoalListVMAsync(ValueListEntryType pType, ValueListEntryType pParentType, Action pCallBack) + { + Cache.GetInstance().GetAllValueListEntrysByTypeAsync(pType, r1 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync(pParentType, r2 => pCallBack(new SupportConceptGoalListVM(r1, r2)))); + } + + public static void CreateSupportConceptVMAsync(Action pCallback) + { + CreateSupportConceptVMAsync(new SupportConceptDC(), pCallback, true); + } + + public static void CreateSupportConceptVMAsync(long pOid, Action pCallback) + { + ServiceFacade.DoCustomerServiceAsync(s => s.LoadSupportConcept(pOid), + r => CreateSupportConceptVMAsync(r, pCallback, false)); + } + + public static void CreateSupportConceptVMAsync(SupportConceptDC dc, Action pCallBack, bool initOriginator) + { + Cache.GetInstance().GetAllValueListEntrysByTypeAsync( + ValueListEntryType.SupportConceptGoalCategoryType, + r1 => Cache.GetInstance().GetAllValueListEntrysByTypeAsync( + ValueListEntryType.SupportConceptGoalType, + r2 => Cache.GetInstance().GetServiceCategoryDescriptionDict( + dict => ServiceFacade.DoOperationsServiceAsync(s => s.GetAllBudgets(), + r3 => + { + var vm = new SupportConceptVM(dc, r1, r2, dict, r3); + if (initOriginator) + { + vm.Originator = BeWoApp.LoggedOnUser.Employee; + } + + pCallBack(vm); + })))); + } + + public static void CreateTeamVMAsync(Action pCallBack) + { + pCallBack(new TeamVM(new TeamDC())); + } + + public static void CreateTeamVMAsync(long pTeamOid, Action pCallBack) + { + ServiceFacade.DoEmployeeServiceAsync(s => s.LoadTeam(pTeamOid), cb => pCallBack(new TeamVM(cb))); + } + + public static void CreateGroupOfPeopleVMAsync(Action pCallBack) + { + pCallBack(new GroupOfPeopleVM(new GroupOfPeopleDC())); + } + + public static void CreateGroupOfPeopleVMAsync(long pGroupOfPeopleOid, Action pCallBack) + { + ServiceFacade.DoEmployeeServiceAsync(s => s.LoadGroupOfPeople(pGroupOfPeopleOid), cb => pCallBack(new GroupOfPeopleVM(cb))); + } + + public static void CreateGroupOfPeopleListVMAsync(Action pCallBack) + { + ServiceFacade.DoEmployeeServiceAsync(s => s.GetAllGroups(BeWoApp.LoggedOnEmployee.EmployeeOid), cb => pCallBack(new GroupOfPeopleListVM(cb))); + } + + public static void CreateAdditinoalServiceGroupOfPeopleListVMAsync(Action pCallBack) + { + ServiceFacade.DoOperationsServiceAsync(s => s.GetAllAdditionalServiceGroupOfPeople(), cb => pCallBack(new AdditionalServiceGroupOfPeopleListVM(cb))); + } + + public static void CreateUserGroupVMAsync(long pOid, Action pCallBack) + { + ServiceFacade.DoUserServiceAsync(s => s.LoadUserGroup(pOid), r => pCallBack(new UserGroupVM(r)), true); + } + + public static void CreateUserGroupVMAsync(Action pCallBack) + { + pCallBack(new UserGroupVM(new UserGroupDC())); + } + + public static void CreateUserVMAsync(long pUserOid, Action pCallBack) + { + ServiceFacade.DoUserServiceAsync(s => s.LoadUser(pUserOid), r1 => ServiceFacade.DoUserServiceAsync(s => s.GetAllUserGroups(), r2 => pCallBack(new UserVM(r1, r2)), true), true); + } + + public static void CreateUserVMAsync(Action pCallBack) + { + ServiceFacade.DoUserServiceAsync(s => s.GetAllUserGroups(), cb => pCallBack(new UserVM(new UserDC(), cb)), true); + } + + public static void CreateValueListVMAsync(ValueListEntryType pType, Action pCallBack) + { + ServiceFacade.DoValueListServiceAsync(s => s.GetAllValueListEntrysByType(pType), r => pCallBack(new ValueListEntryListVM(pType, r))); + } + + + public static void CreateGoalCategoryVMAsync(Action pCallBack, bool pIsIncludingIndividualGoals = false) + { + var typeList = new List { ValueListEntryType.SupportConceptGoalType, ValueListEntryType.SupportConceptGoalCategoryType }; + if (pIsIncludingIndividualGoals) + { + typeList.Add(ValueListEntryType.SupportConceptIndividualGoalCategoryType); + typeList.Add(ValueListEntryType.SupportConceptIndividualGoalType); + } + + ServiceFacade.DoValueListServiceAsync( + s => s.GetAllValueListEntrysByTypes(typeList), + cb => pCallBack(new GenericValueListEntryListVM(cb))); + } + + public static void CreateEmploymentTypeListVMAsync(Action pCallBack) + { + ServiceFacade.DoEmployeeServiceAsync(s => s.GetAllEmploymentTypes(), r => pCallBack(new EmploymentTypeListVM(r))); + } + + private static void InternalCreateCustomerVM(CustomerDC pCustomerDC, Action pCallBack) + { + var list = new List + { + ValueListEntryType.DisabilityType, + ValueListEntryType.CustomerCareType, + ValueListEntryType.PlacementObjectiveType, + ValueListEntryType.TerminationReasonType, + ValueListEntryType.Nationality, + ValueListEntryType.Aufenthaltsstatus, + ValueListEntryType.RoleInFamily, + ValueListEntryType.NotizenKategorieCustomer, + ValueListEntryType.Auftragsherkunft, + ValueListEntryType.Vermittlungsgrundlage + }; + + ServiceFacade.DoValueListServiceAsync( + s => s.GetAllValueListEntrysByTypes(list), + cb => ServiceFacade.DoEmployeeServiceAsync(s2 => s2.GetAllAssessmentSheetCategories(), + cb2 => ServiceFacade.DoEmployeeServiceAsync(s3 => s3.GetAllAssessmentSheetValues(), + cb3 => ServiceFacade.DoCustomerServiceAsync(s4 => s4.GetAllMedArten(), + cb4 => pCallBack(new CustomerVM(pCustomerDC, cb, cb2, cb3, cb4)))))); + } + + public static void CreateAppointmentCategoryListVMAsync(Action pCallBack) + { + ServiceFacade.DoCustomerServiceAsync( + s => s.GetAllAppointmentCategories(), cats => pCallBack(new AppointmentCategoryListVM(cats))); + } + + public static WohnheimbuchungEmployeeRelListVM CreateEmployeeWohnheimbuchungsListVM(IEnumerable pList) + { + return new WohnheimbuchungEmployeeRelListVM(pList); + } + + public static Wohnheimbuchung2Costbearer2SupportConceptRelListVM CreateSupportConceptWohnheimbuchungsListVM(IEnumerable pList) + { + return new Wohnheimbuchung2Costbearer2SupportConceptRelListVM(pList); + } + + public static void CreateWohnheimbuchungsVMAsync(long? pOid, Action pCallBack) + { + Cache.GetInstance().GetServiceCategoryDescriptionDict( + dict => + { + if (pOid == null) + { + pCallBack(new WohnheimbuchungsVM(new WohnheimbuchungDC(), dict)); + } + else + { + ServiceFacade.DoCustomerServiceAsync(s => s.GetWohnheimbuchung(pOid.Value), cb => pCallBack(new WohnheimbuchungsVM(cb, dict))); + } + }); + } + + public static SupportConceptApprovalPeriodEmployeeRelListVM CreateSupportConceptApprovalPeriodEmployeeRelListVM(IEnumerable pList) + { + return new SupportConceptApprovalPeriodEmployeeRelListVM(pList); + } + + public static ArbeitszeitEintragListVM CreateArbeitszeitEintragListVm(IEnumerable pList) + { + return new ArbeitszeitEintragListVM(pList); + } + + public static void CreateSbdAdminVMAsync(Action pCallBack) + { + ServiceFacade.DoOperationsServiceAsync(s => s.GetSbdConfig(), r => + { + pCallBack(new SbdConfigVM(r)); + }); + } + + public static List CreateSupportConceptList() + { + List allSupportConcepts = new List(); + List activeSupportConcepts = new List(); + + allSupportConcepts = ServiceFacade.DoCustomerServiceSync( + s => s.GetAllSupportConceptsCompact(BeWoApp.LoggedOnUser.Employee.EmployeeOid)); + + foreach (var sc in allSupportConcepts) + { + if (!sc.IsDeleted) + activeSupportConcepts.Add(sc); + } + + return activeSupportConcepts; + } + public static List CreateCustomerList() + { + List allCustomers = new List(); + List activeCustomers = new List(); + + allCustomers = ServiceFacade.DoCustomerServiceSync( + s => s.GetAllCustomersCompact(BeWoApp.LoggedOnUser.Employee.EmployeeOid)); + + foreach (var customer in allCustomers) + { + if (!customer.IsDeleted) + activeCustomers.Add(customer); + } + + return activeCustomers; + } + public static List CreateOrganisationList() + { + List allOrganisations = new List(); + + allOrganisations = ServiceFacade.DoCustomerServiceSync(s => s.GetAllActiveOrganisationsCompact()); + + return allOrganisations; + } + public static List CreatePeopleList() + { + List allPeople = new List(); + List activePeople = new List(); + + allPeople = ServiceFacade.DoCustomerServiceSync(s => s.GetAllPersonsByTypeCompact(PersonType.Others)); + + foreach (var person in allPeople) + { + if (!person.IsDeleted) + activePeople.Add(person); + } + + return activePeople; + } + public static List CreateEmployeeList() + { + List allEmployee = new List(); + + allEmployee = ServiceFacade.DoEmployeeServiceSync(s => s.GetAllActiveEmployeesCompact()); + + return allEmployee; + } + public static List CreateTeamList() + { + List allTeams = new List(); + + allTeams = ServiceFacade.DoEmployeeServiceSync(s => s.GetAllTeamsCompact()); + + return allTeams; + + } + public static List CreateUserList() + { + List allUsers = new List(); + + allUsers = ServiceFacade.DoUserServiceSync(s => s.GetAllUsersCompact()); + + return allUsers; + } + public static List CreateUserGroupList() + { + List allUserGroups = new List(); + + allUserGroups = ServiceFacade.DoUserServiceSync(s => s.GetAllUserGroups()); + return allUserGroups; + } + + public static List CreateFolderList(TableID tid, long objectOid) + { + List folderList = new List(); + folderList = ServiceFacade.DoOperationsServiceSync(s => s.GetFolderTree(tid, objectOid)); + + return folderList; + } + + public static void CreateWohneinheitListVMs(List dcs, out WohneinheitListVM einheit_vm_list, out WohneinheitBelegungListVM beleg_vm_list) + { + einheit_vm_list = new WohneinheitListVM(dcs); + + var beleg_dc_list = new List(); + var beleg_dc2einheit_vm = new Dictionary(); + foreach (var einheit_vm in einheit_vm_list.VMList) + { + var einheit_dc = einheit_vm.DataContract; + + if (einheit_dc.Belegungen is null) + continue; + + foreach (var beleg_dc in einheit_dc.Belegungen) + { + beleg_dc_list.Add(beleg_dc); + beleg_dc2einheit_vm.Add(beleg_dc, einheit_vm); + } + } + + beleg_vm_list = new WohneinheitBelegungListVM(beleg_dc_list.OrderBy(x => x.Oid).ToList()); + + foreach (var beleg_vm in beleg_vm_list.VMList) + { + var beleg_dc = beleg_vm.DataContract; + + beleg_vm.Wohneinheit = beleg_dc2einheit_vm[beleg_dc]; + } + + einheit_vm_list.VMList.Sort(WohneinheitVM.Compare); + } + + public static AiConversationChatViewModel CreateAiConversationChatViewModel(UIContext uIContext, Dictionary bewoObjects, long? reference_oid = null) + { + var vm = new AiConversationChatViewModel(); + + vm.UIContext = uIContext; + vm.ContextBeWoObjects = bewoObjects; + vm.ReferenceObjectOid = reference_oid; + + return vm; + } + + public static void CreateAiConversationListVM(UIContext uIContext, long? reference_oid, Action callback) + { + ServiceFacade.DoAiEnhancedServiceAsnyc( + s => s.GetAiConversations((int)uIContext, reference_oid), + cb => + { + cb.Reverse(); + callback(new AiConversationListVM(cb)); + }); + } + } } \ No newline at end of file diff --git a/BeWo/ViewModel/View/AiConversationChatViewModel.cs b/BeWo/ViewModel/View/AiConversationChatViewModel.cs new file mode 100644 index 000000000..65c83a1ca --- /dev/null +++ b/BeWo/ViewModel/View/AiConversationChatViewModel.cs @@ -0,0 +1,387 @@ +using BS.Shared.DataContracts; +using BS.Shared; +using BS.Shared.DataContracts.Feature.AI; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using BeWo.ViewModel.ListViewModel; +using System.Windows.Input; +using BS.Shared.Core; +using DevExpress.Mvvm; +using BeWo.ServiceProxy; +using BS.Shared.Extensions; + +namespace BeWo.ViewModel.View +{ + public class AiConversationChatViewModel : AbstractBaseVM + { + private bool _IsSettingsOpen; + private bool _IsCloneOpen; + private bool _IsSending; + + private string _MessageInput; + private string _ContextInput; + + private AiModelDC _SelectedModel; + private AiConfigVM _Config; + + public AiConversationChatViewModel() + { + Models = new ObservableSortCollection(); + + SendNewMessageCommand = new DelegateCommand(SendNewMessage, () => ListVM.SelectedVM is object && !string.IsNullOrWhiteSpace(MessageInput) && !IsSending); + OpenNewConversationCommand = new DelegateCommand(OpenNewConversation, () => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleChatAdd)); + StartConversationWithMessageCommand = new DelegateCommand(StartConversationWithMessage, () => !string.IsNullOrWhiteSpace(MessageInput) && !IsSending); + + ReloadConfigCommand = new DelegateCommand(ReloadConfig); + ReloadConversationsCommand = new DelegateCommand(ReloadConversations); + ReloadModelsCommand = new DelegateCommand(ReloadModels); + + OpenSettingCommand = new DelegateCommand(OpenSetting, () => (BeWoApp.AppSettings?.ModuleAiSettingsEnabled ?? true) && BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleViewSetting)); + OpenCloneCommand = new DelegateCommand(OpenClone, () => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleChatClone) && ListVM.SelectedVM is object); + CloneCommand = new DelegateCommand(Clone); + + AskDeleteCommand = new DelegateCommand(AskDelete, () => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleChatDelete) && ListVM.SelectedVM is object); + + ListVM = new AiConversationListVM(); + ListVM.SelectedVMChanged += (s, e) => FirePropertyChanged(nameof(IsNewConversationVisible)); + } + + public event EventHandler SendNewMessageSuccess; + + public ICommand SendNewMessageCommand { get; set; } + public ICommand OpenNewConversationCommand { get; set; } + public ICommand StartConversationWithMessageCommand { get; set; } + public ICommand RequestNewConversationCommand { get; set; } + public ICommand TestCommand { get; set; } + public ICommand AskDeleteCommand { get; set; } + public ICommand ReloadConfigCommand { get; set; } + public ICommand ReloadConversationsCommand { get; set; } + public ICommand ReloadModelsCommand { get; set; } + + public ICommand OpenSettingCommand { get; set; } + public ICommand OpenCloneCommand { get; set; } + public ICommand CloneCommand { get; set; } + + public AiConversationListVM ListVM { get; set; } + + public ObservableCollection Models { get; set; } + public AiModelDC SelectedModel + { + get { return _SelectedModel; } + set + { + if (_SelectedModel == value) + return; + + _SelectedModel = value; + FirePropertyChanged(nameof(SelectedModel)); + } + } + public AiConfigVM Config + { + get { return _Config; } + set + { + if (Config == value) + return; + + _Config = value; + FirePropertyChanged(nameof(Config)); + } + } + + public string MessageInput + { + get { return _MessageInput; } + set + { + if (MessageInput == value) + return; + + _MessageInput = value; + FirePropertyChanged(nameof(MessageInput)); + } + } + public string ContextInput + { + get { return _ContextInput; } + set + { + if (ContextInput == value) + return; + + _ContextInput = value; + FirePropertyChanged(nameof(ContextInput)); + } + } + + public bool IsSettingsOpen + { + get => _IsSettingsOpen; + set + { + _IsSettingsOpen = value; + FirePropertyChanged(nameof(IsSettingsOpen)); + } + } + public bool IsCloneOpen + { + get => _IsCloneOpen; + set + { + _IsCloneOpen = value; + FirePropertyChanged(nameof(IsCloneOpen)); + } + } + public bool IsSending + { + get => _IsSending; + set + { + _IsSending = value; + FirePropertyChanged(nameof(IsSending)); + } + } + public bool IsNewConversationVisible => ListVM.SelectedVM is null; + + public UIContext UIContext { get; set; } + public long? ReferenceObjectOid { get; set; } + public Dictionary ContextBeWoObjects { get; set; } + + private void StartConversationWithMessage() + { + StartSending(); + + try + { + var message = MessageInput; + + var conv = new AiConversationDC(); + + conv.Created = DateTime.Now; + conv.Updated = DateTime.Now; + conv.UIContext = (int)UIContext; + conv.ContextBeWoObjects = ContextBeWoObjects; + conv.Messages = new List() + { + new AiConversationMessageDC() + { + Message = message, + Role = AiConversationMessageRole.User + } + }; + + var vm = InsertConverstion(conv); + + ServiceFacade.DoAiEnhancedServiceAsnyc( + x => x.CreateAiConversationWithMessage(conv, Config.SelectedModel.Oid.Value, message), + dc => UpdateConverstion(vm, dc), + e => EndSending()); + } + catch (Exception ex) + { + EndSending(); + } + } + private void OpenNewConversation() + { + ListVM.SelectedVM = null; + } + private void SendNewMessage() + { + StartSending(); + + try + { + var conv = ListVM.SelectedVM; + + var msg_dc = new AiConversationMessageDC(); + + msg_dc.Message = MessageInput; + msg_dc.Role = BS.Shared.AiConversationMessageRole.User; + msg_dc.Created = DateTime.Now; + + var msg_vm = new AiConversationMessageVM(msg_dc); + + conv.Messages.VMList.Add(msg_vm); + + ServiceFacade.DoAiEnhancedServiceAsnyc( + x => x.SendNewMessage(conv.DataContract.Oid.Value, MessageInput), + (messages) => + { + if (messages.Count != 2) + throw new InvalidOperationException("message count: " + messages.Count); + + msg_vm.DataContract = messages[0]; + + conv.Messages.VMList.Add(new AiConversationMessageVM(messages[1])); + + MessageInput = string.Empty; + + EndSending(); + + SendNewMessageSuccess?.Invoke(this, EventArgs.Empty); + }, + (exception) => + { + conv.Messages.VMList.Remove(msg_vm); + + EndSending(); + } + ); + } + catch (Exception ex) + { + EndSending(); + } + } + private void StartSending() + { + if (IsSending) + throw new InvalidOperationException("Sendet bereits"); + + IsSending = true; + } + private void EndSending() + { + if (!IsSending) + throw new InvalidOperationException("Sendet nicht"); + + IsSending = false; + } + private void Test() + { + throw new NotImplementedException(); + } + + private AiConversationVM InsertConverstion(AiConversationDC dc) + { + var vm = new AiConversationVM(dc); + ListVM.VMList.Insert(0, vm); + ListVM.SelectedVM = vm; + + return vm; + } + + private void UpdateConverstion(AiConversationVM vm, AiConversationDC dc) + { + vm.UpdateByDataContract(dc); + + MessageInput = string.Empty; + + EndSending(); + + SendNewMessageSuccess?.Invoke(this, EventArgs.Empty); + } + + private void ReloadConfig() + { + ServiceFacade.DoAiEnhancedServiceAsnyc(x => x.GetAiConfig(), (x) => + { + if (Config is null) + Config = new AiConfigVM(x); + else + Config.Update(x); + }); + } + public void UpdateConfig() + { + if (!Config.IsDirty) + return; + + ServiceFacade.DoAiEnhancedServiceAsnyc(x => x.UpdateAiConfig(Config.CommitToDataContract()), (x) => + { + Config.Update(x); + }); + } + + private void ReloadModels() + { + ServiceFacade.DoAiEnhancedServiceAsnyc(x => x.GetAiModels(), (x) => + { + Models.MakeEqualTo(x); + + if (Config.SelectedModel is null && Models.Any()) + Config.SelectedModel = Models.First(); + }); + } + private void ReloadConversations() + { + var ui_context = UIContext; + var reference = ReferenceObjectOid; + + VMFactory.CreateAiConversationListVM(ui_context, reference, (listvm) => + { + ListVM.VMList.MakeEqualTo(listvm.VMList); + }); + } + + private void OpenSetting() + { + ServiceFacade.DoAiEnhancedServiceAsnyc(x => x.GetAiModels(), (x) => + { + Models.MakeEqualTo(x); + IsSettingsOpen = true; + }); + } + private void OpenClone() + { + foreach (var message in ListVM.SelectedVM.Messages.VMList) + { + message.IsChecked = true; + } + + IsCloneOpen = true; + } + private void Clone() + { + var conv = ListVM.SelectedVM; + + AiConversationMessageVM last = null; + foreach (var msg in conv.Messages.VMList) + { + if (!msg.IsChecked) + break; + + last = msg; + } + + var conv_oid = conv.DataContract.Oid.Value; + var msg_oid = last?.DataContract.Oid; + + ServiceFacade.DoAiEnhancedServiceAsnyc(x => x.CloneAiConversation(conv_oid, msg_oid), dc => + { + InsertConverstion(dc); + CloseClone(); + }); + } + private void CloseClone() + { + IsCloneOpen = false; + } + + public void AskDelete() + { + var selected = ListVM.SelectedVM; + + var oid = selected.DataContract.Oid.Value; + + var msg = $"Wollen Sie die ausgewählte Konversation ({oid}) löschen?"; + + if (MessageBox.Show(msg, "Konversation löschen", MessageBoxButton.YesNo, MessageBoxImage.Warning) == + MessageBoxResult.Yes) + { + ServiceFacade.DoAiEnhancedServiceAsnyc(x => x.DeleteAiConversation(oid), () => { + ListVM.VMList.Remove(selected); + CommandManager.InvalidateRequerySuggested(); + //SelectedVM = VMList.FirstOrDefault(); + }); + } + } + } +} diff --git a/BeWo/ownChat/ChatServiceCustomer.xaml b/BeWo/ownChat/ChatServiceCustomer.xaml index c9a9f181e..df58e358f 100644 --- a/BeWo/ownChat/ChatServiceCustomer.xaml +++ b/BeWo/ownChat/ChatServiceCustomer.xaml @@ -1,25 +1,33 @@ - - - - + + + + - - - - + + + + @@ -37,39 +45,118 @@ - - --> - - - - - - - + + + + + + - - - + + + \ No newline at end of file diff --git a/BeWo/ownChat/ChatServiceEmployee.xaml b/BeWo/ownChat/ChatServiceEmployee.xaml index d23824372..861c97c61 100644 --- a/BeWo/ownChat/ChatServiceEmployee.xaml +++ b/BeWo/ownChat/ChatServiceEmployee.xaml @@ -1,30 +1,38 @@ - - - - - + + + + + - - - - + + + + - - + + @@ -37,45 +45,96 @@ - - - - - + + + + \ No newline at end of file