diff --git a/GroomWise.Application/Mappers/GroomingServiceMapper.cs b/GroomWise.Application/Mappers/GroomingServiceMapper.cs index 0cdab32..5a5f085 100644 --- a/GroomWise.Application/Mappers/GroomingServiceMapper.cs +++ b/GroomWise.Application/Mappers/GroomingServiceMapper.cs @@ -15,4 +15,9 @@ public static ObservableGroomingService ToObservable(this GroomingService groomi { return groomingService.Adapt(); } + + public static GroomingService ToEntity(this ObservableGroomingService observableGroomingService) + { + return observableGroomingService.Adapt(); + } } diff --git a/GroomWise.Application/ViewModels/GroomingServiceViewModel.cs b/GroomWise.Application/ViewModels/GroomingServiceViewModel.cs index a99f7bd..171b8c2 100644 --- a/GroomWise.Application/ViewModels/GroomingServiceViewModel.cs +++ b/GroomWise.Application/ViewModels/GroomingServiceViewModel.cs @@ -3,11 +3,95 @@ // Unauthorized copying or redistribution of all files, in source and binary forms via any medium // without written, signed consent from the author is strictly prohibited. +using GroomWise.Application.Events; +using GroomWise.Application.Mappers; +using GroomWise.Application.Observables; +using GroomWise.Domain.Enums; +using GroomWise.Infrastructure.Database; +using GroomWise.Infrastructure.Navigation.Interfaces; using Injectio.Attributes; using MvvmGen; +using MvvmGen.Events; +using Swordfish.NET.Collections; namespace GroomWise.Application.ViewModels; [ViewModel] [RegisterSingleton] -public partial class GroomingServiceViewModel { } +[Inject(typeof(GroomWiseDbContext))] +[Inject(typeof(IDialogService))] +[Inject(typeof(INavigationService))] +[Inject(typeof(IEventAggregator))] +public partial class GroomingServiceViewModel +{ + [Property] + private ObservableGroomingService _activeGroomingService = new(); + + [Property] + private ConcurrentObservableCollection _groomingServices = new(); + + partial void OnInitialize() + { + PopulateCollections(); + } + + private async void PopulateCollections() + { + await Task.Run(() => + { + var services = GroomWiseDbContext.GroomingServices + .GetAll() + .Select(GroomingServiceMapper.ToObservable); + + GroomingServices = new ConcurrentObservableCollection( + services + ); + }); + } + + [Command] + private async Task CreateService() + { + await Task.Run(() => + { + DialogService.CreateAddServicesDialog(this, NavigationService); + }); + } + + [Command] + private async Task SaveService() + { + await Task.Run(() => + { + if (string.IsNullOrEmpty(ActiveGroomingService.Type)) + { + EventAggregator.Publish( + new PublishNotificationEvent( + $"Service name cannot be blank", + NotificationType.Danger + ) + ); + return; + } + var dialogResult = DialogService.Create( + "GroomWise", + "Create Service?", + NavigationService + ); + if (dialogResult is true) + { + var service = ActiveGroomingService.ToEntity(); + GroomWiseDbContext.GroomingServices.Insert(service); + DialogService.CloseDialogs(NavigationService); + EventAggregator.Publish( + new PublishNotificationEvent( + $"Service {ActiveGroomingService.Type} saved", + NotificationType.Success + ) + ); + ActiveGroomingService = new(); + PopulateCollections(); + } + }); + } +} diff --git a/GroomWise.Infrastructure/Navigation/Interfaces/IDialogService.cs b/GroomWise.Infrastructure/Navigation/Interfaces/IDialogService.cs index f865231..eb95d2e 100644 --- a/GroomWise.Infrastructure/Navigation/Interfaces/IDialogService.cs +++ b/GroomWise.Infrastructure/Navigation/Interfaces/IDialogService.cs @@ -11,4 +11,5 @@ public interface IDialogService void CloseDialogs(INavigationService navigationService); void CreateAddAppointmentsDialog(object viewModel, INavigationService navigationService); void CreateAddCustomersDialog(object viewModel, INavigationService navigationService); + void CreateAddServicesDialog(object viewModel, INavigationService navigationService); } diff --git a/GroomWise.WPF/Services/DialogService.cs b/GroomWise.WPF/Services/DialogService.cs index c3005d7..ae15e12 100644 --- a/GroomWise.WPF/Services/DialogService.cs +++ b/GroomWise.WPF/Services/DialogService.cs @@ -91,4 +91,23 @@ await App.Current.Dispatcher.InvokeAsync(() => }); }); } + + public void CreateAddServicesDialog(object viewModel, INavigationService navigationService) + { + Task.Run(async () => + { + await App.Current.Dispatcher.InvokeAsync(() => + { + if (!App.Current.Windows.OfType().Any()) + { + new AddServicesView(viewModel) + { + ShowInTaskbar = false, + WindowStartupLocation = WindowStartupLocation.CenterOwner, + Owner = (Window)navigationService.CurrentWindow! + }.Show(); + } + }); + }); + } } diff --git a/GroomWise.WPF/Views/Dialogs/AddAppointmentsView.xaml b/GroomWise.WPF/Views/Dialogs/AddAppointmentsView.xaml index d7884bf..40b0c9d 100644 --- a/GroomWise.WPF/Views/Dialogs/AddAppointmentsView.xaml +++ b/GroomWise.WPF/Views/Dialogs/AddAppointmentsView.xaml @@ -59,7 +59,7 @@ diff --git a/GroomWise.WPF/Views/Dialogs/AddServicesView.xaml b/GroomWise.WPF/Views/Dialogs/AddServicesView.xaml new file mode 100644 index 0000000..f2b57fd --- /dev/null +++ b/GroomWise.WPF/Views/Dialogs/AddServicesView.xaml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/GroomWise.WPF/Views/Dialogs/AddServicesView.xaml.cs b/GroomWise.WPF/Views/Dialogs/AddServicesView.xaml.cs new file mode 100644 index 0000000..9343aa3 --- /dev/null +++ b/GroomWise.WPF/Views/Dialogs/AddServicesView.xaml.cs @@ -0,0 +1,25 @@ +// Copyright (C) 2023 Russell Camo (Russkyc).- All Rights Reserved +// +// Unauthorized copying or redistribution of all files, in source and binary forms via any medium +// without written, signed consent from the author is strictly prohibited. + +using System.ComponentModel; +using System.Linq; + +namespace GroomWise.Views.Dialogs; + +public partial class AddServicesView +{ + public AddServicesView(object vm) + { + DataContext = vm; + InitializeComponent(); + } + + protected override void OnClosing(CancelEventArgs e) + { + var parent = App.Current.Windows.OfType().FirstOrDefault(); + parent.Focus(); + base.OnClosing(e); + } +} diff --git a/GroomWise.WPF/Views/Pages/ServicesView.xaml b/GroomWise.WPF/Views/Pages/ServicesView.xaml index 7c8745a..a2891fc 100644 --- a/GroomWise.WPF/Views/Pages/ServicesView.xaml +++ b/GroomWise.WPF/Views/Pages/ServicesView.xaml @@ -15,122 +15,66 @@ d:DesignWidth="1280" Style="{StaticResource FadeInFromBottomAnimation}" mc:Ignorable="d"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/GroomWise.WPF/Views/Templates/DashboardNotificationTemplate.xaml b/GroomWise.WPF/Views/Templates/DashboardNotificationTemplate.xaml index 89b3f7f..098b5f4 100644 --- a/GroomWise.WPF/Views/Templates/DashboardNotificationTemplate.xaml +++ b/GroomWise.WPF/Views/Templates/DashboardNotificationTemplate.xaml @@ -65,13 +65,13 @@ FontSize="14" FontWeight="Medium" Foreground="{DynamicResource fg-000}" - Text="{Binding Title, UpdateSourceTrigger=PropertyChanged}" /> + Text="{Binding Service.Type, UpdateSourceTrigger=PropertyChanged}" />