Skip to content

Commit

Permalink
feat: implement service management functionality
Browse files Browse the repository at this point in the history
Signed-off-by: Russell Camo <[email protected]>
  • Loading branch information
russkyc committed Aug 29, 2023
1 parent 99319ae commit f9860b5
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 120 deletions.
5 changes: 5 additions & 0 deletions GroomWise.Application/Mappers/GroomingServiceMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ public static ObservableGroomingService ToObservable(this GroomingService groomi
{
return groomingService.Adapt<ObservableGroomingService>();
}

public static GroomingService ToEntity(this ObservableGroomingService observableGroomingService)
{
return observableGroomingService.Adapt<GroomingService>();
}
}
86 changes: 85 additions & 1 deletion GroomWise.Application/ViewModels/GroomingServiceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ObservableGroomingService> _groomingServices = new();

partial void OnInitialize()
{
PopulateCollections();
}

private async void PopulateCollections()
{
await Task.Run(() =>
{
var services = GroomWiseDbContext.GroomingServices
.GetAll()
.Select(GroomingServiceMapper.ToObservable);
GroomingServices = new ConcurrentObservableCollection<ObservableGroomingService>(
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();
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
19 changes: 19 additions & 0 deletions GroomWise.WPF/Services/DialogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,23 @@ public void CreateAddCustomersDialog(object viewModel, INavigationService naviga
});
});
}

public void CreateAddServicesDialog(object viewModel, INavigationService navigationService)
{
Task.Run(async () =>
{
await App.Current.Dispatcher.InvokeAsync(() =>
{
if (!App.Current.Windows.OfType<AddServicesView>().Any())
{
new AddServicesView(viewModel)
{
ShowInTaskbar = false,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
Owner = (Window)navigationService.CurrentWindow!
}.Show();
}
});
});
}
}
2 changes: 1 addition & 1 deletion GroomWise.WPF/Views/Dialogs/AddAppointmentsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<russkyc:ModernComboBox
Margin="0,12,0,0"
CornerRadius="5"
DisplayMemberPath="ServiceName"
DisplayMemberPath="Type"
ItemsSource="{Binding GroomingServices.EditableCollectionView, UpdateSourceTrigger=PropertyChanged}"
Placeholder="Service"
SelectedValue="{Binding ActiveAppointment.Service, UpdateSourceTrigger=PropertyChanged}" />
Expand Down
101 changes: 101 additions & 0 deletions GroomWise.WPF/Views/Dialogs/AddServicesView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<russkyc:ModernWindow
x:Class="GroomWise.Views.Dialogs.AddServicesView"
xmlns="http:https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http:https://schemas.microsoft.com/winfx/2006/xaml"
xmlns:b="http:https://schemas.microsoft.com/xaml/behaviors"
xmlns:d="http:https://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http:https://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:russkyc="clr-namespace:org.russkyc.moderncontrols;assembly=Russkyc.ModernControls.WPF"
xmlns:viewModels="clr-namespace:GroomWise.Application.ViewModels;assembly=GroomWise.Application"
xmlns:wpf="clr-namespace:Material.Icons.WPF;assembly=Material.Icons.WPF"
Title="AddServicesView"
Width="600"
d:DataContext="{d:DesignInstance viewModels:GroomingServiceViewModel,
IsDesignTimeCreatable=True}"
FocusManager.FocusedElement="{Binding ElementName=ServiceNameBox}"
NoDecorations="True"
ResizeMode="NoResize"
SizeToContent="Height"
TitleBarHeight="0"
WindowStartupLocation="CenterOwner"
mc:Ignorable="d">
<Grid Style="{StaticResource FadeInAnimation}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock
Grid.Row="0"
Grid.Column="0"
Margin="20,16,0,12"
HorizontalAlignment="Left"
FontSize="16"
Text="New GroomingService" />
<StackPanel
Grid.Row="1"
Margin="20,0,16,20"
HorizontalAlignment="Stretch"
VerticalAlignment="Top">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="350" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<russkyc:ModernTextBox
Name="ServiceNameBox"
Grid.Column="0"
Margin="0,0,0,0"
CornerRadius="5"
HelperText="Max Length (200)"
Placeholder="Service Name"
Text="{Binding ActiveGroomingService.Type, UpdateSourceTrigger=PropertyChanged}" />
<russkyc:ModernTextBox
Grid.Column="1"
Margin="12,0,0,0"
CornerRadius="5"
HelperText="Max Length (200)"
Placeholder="Service Info"
Text="{Binding ActiveCustomer.ContactNumber, UpdateSourceTrigger=PropertyChanged}" />

</Grid>
<Grid Margin="0,12,0,0">
<russkyc:ModernTextBox
Margin="0,0,0,0"
AcceptsReturn="True"
CornerRadius="5"
HelperText="Max Length (200)"
Placeholder="Description"
Text="{Binding ActiveGroomingService.Description, UpdateSourceTrigger=PropertyChanged}" />
</Grid>

<StackPanel
Margin="0,24,0,0"
HorizontalAlignment="Right"
Orientation="Horizontal">
<russkyc:ModernButton
Margin="0,0,12,0"
HorizontalAlignment="Right"
Content="Cancel"
CornerRadius="5"
DefaultBackground="{DynamicResource bg-000}"
FontWeight="Medium"
Foreground="{DynamicResource fg-600}"
HoverBackground="{DynamicResource bg-000}"
PressedBackground="{DynamicResource bg-100}">
<b:Interaction.Triggers>
<b:EventTrigger EventName="Click">
<b:CallMethodAction MethodName="Close" TargetObject="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=russkyc:ModernWindow}}" />
</b:EventTrigger>
</b:Interaction.Triggers>
</russkyc:ModernButton>
<russkyc:ModernButton
HorizontalAlignment="Right"
Command="{Binding SaveServiceCommand}"
Content="Save Service"
CornerRadius="5"
FontWeight="Medium"
LeftCenterIcon="{wpf:MaterialIconExt Kind=ContentSave}" />
</StackPanel>
</StackPanel>
</Grid>
</russkyc:ModernWindow>
25 changes: 25 additions & 0 deletions GroomWise.WPF/Views/Dialogs/AddServicesView.xaml.cs
Original file line number Diff line number Diff line change
@@ -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<MainView>().FirstOrDefault();
parent.Focus();
base.OnClosing(e);
}
}
Loading

0 comments on commit f9860b5

Please sign in to comment.