Skip to content

Commit

Permalink
feat: initiate edit customer dialog
Browse files Browse the repository at this point in the history
Signed-off-by: Russell Camo <[email protected]>
  • Loading branch information
russkyc committed Sep 1, 2023
1 parent d8fb1c1 commit eae079d
Show file tree
Hide file tree
Showing 15 changed files with 568 additions and 120 deletions.
66 changes: 57 additions & 9 deletions GroomWise.Application/ViewModels/CustomerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public partial class CustomerViewModel
[Property]
private ObservableCustomer _activeCustomer;

[Property]
private ObservableCustomer _selectedCustomer;

[Property]
private ConcurrentObservableCollection<ObservableCustomer> _customers;

Expand All @@ -58,6 +61,7 @@ private async Task CreateCustomer()
{
await Task.Run(() =>
{
ActiveCustomer = new();
DialogService.CreateAddCustomersDialog(this, NavigationService);
});
}
Expand Down Expand Up @@ -100,12 +104,30 @@ await Task.Run(() =>
});
}

[Command]
private async Task SelectCustomer(object param)
{
await Task.Run(() =>
{
if (param is ObservableCustomer customer)
{
SelectedCustomer = customer;
}
});
}

[Command]
private async Task AddCustomerPet()
{
ActiveCustomer.Pets.Insert(0, new ObservablePet());
}

[Command]
private async Task AddSelectedCustomerPet()
{
SelectedCustomer.Pets.Insert(0, new ObservablePet());
}

[Command]
private async Task RemoveCustomerPet(object param)
{
Expand All @@ -116,20 +138,42 @@ private async Task RemoveCustomerPet(object param)
}

[Command]
private async Task UpdateCustomer(object param)
private async Task RemoveSelectedCustomerPet(object param)
{
if (param is ObservableCustomer observableCustomer)
if (param is ObservablePet pet)
{
await Task.Run(
() =>
GroomWiseDbContext.Customers.Update(
observableCustomer.Id,
observableCustomer.ToEntity()
)
);
SelectedCustomer.Pets.Remove(pet);
GroomWiseDbContext.Customers.Update(SelectedCustomer.Id, SelectedCustomer.ToEntity());
}
}

[Command]
private async Task UpdateCustomer()
{
await Task.Run(() =>
{
var dialogResult = DialogService.Create(
"GroomWise",
$"Update {SelectedCustomer.FullName}?",
NavigationService
);
if (dialogResult is true)
{
GroomWiseDbContext.Customers.Update(
SelectedCustomer.Id,
SelectedCustomer.ToEntity()
);
DialogService.CloseDialogs(NavigationService);
}
});
}

[Command]
private async Task EditCustomer()
{
DialogService.CreateEditCustomersDialog(this, NavigationService);
}

[Command]
private async Task RemoveCustomer(object param)
{
Expand All @@ -144,6 +188,10 @@ await Task.Run(() =>
);
if (dialogResult is true)
{
if (observableCustomer == SelectedCustomer)
{
SelectedCustomer = null!;
}
GroomWiseDbContext.Customers.Delete(observableCustomer.Id);
EventAggregator.Publish(new DeleteCustomerEvent());
PopulateCollections();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public interface IDialogService
void CloseDialogs(INavigationService navigationService);
void CreateAddAppointmentsDialog(object viewModel, INavigationService navigationService);
void CreateAddCustomersDialog(object viewModel, INavigationService navigationService);
void CreateEditCustomersDialog(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,6 +91,25 @@ await App.Current.Dispatcher.InvokeAsync(() =>
});
});
}

public void CreateEditCustomersDialog(object viewModel, INavigationService navigationService)
{
Task.Run(async () =>
{
await App.Current.Dispatcher.InvokeAsync(() =>
{
if (!App.Current.Windows.OfType<EditCustomersView>().Any())
{
new EditCustomersView(viewModel)
{
ShowInTaskbar = false,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
Owner = (Window)navigationService.CurrentWindow!
}.Show();
}
});
});
}

public void CreateAddServicesDialog(object viewModel, INavigationService navigationService)
{
Expand Down
160 changes: 160 additions & 0 deletions GroomWise.WPF/Views/Dialogs/EditCustomersView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<russkyc:ModernWindow
x:Class="GroomWise.Views.Dialogs.EditCustomersView"
xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
xmlns:b="https://schemas.microsoft.com/xaml/behaviors"
xmlns:d="https://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:GroomWise.Views.Dialogs"
xmlns:mc="https://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:russkyc="clr-namespace:org.russkyc.moderncontrols;assembly=Russkyc.ModernControls.WPF"
xmlns:templates="clr-namespace:GroomWise.Views.Templates"
xmlns:viewModels="clr-namespace:GroomWise.Application.ViewModels;assembly=GroomWise.Application"
xmlns:wpf="clr-namespace:Material.Icons.WPF;assembly=Material.Icons.WPF"
Title="AddCustomersView"
Width="600"
d:DataContext="{d:DesignInstance viewModels:CustomerViewModel,
IsDesignTimeCreatable=True}"
FocusManager.FocusedElement="{Binding ElementName=FullNameTextBox}"
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="Edit Customer" />
<StackPanel
Grid.Row="1"
Margin="20,0,16,20"
HorizontalAlignment="Stretch"
VerticalAlignment="Top">
<Grid>
<russkyc:ModernTextBox
Name="FullNameTextBox"
Margin="0,0,0,0"
CornerRadius="5"
HelperText="Max Length (200)"
Placeholder="Full Name"
Text="{Binding SelectedCustomer.FullName, UpdateSourceTrigger=PropertyChanged}" />
</Grid>
<Grid Margin="0,12,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="350" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<russkyc:ModernTextBox
Grid.Column="0"
Margin="0,0,0,0"
CornerRadius="5"
HelperText="Max Length (200)"
Placeholder="Email"
Text="{Binding SelectedCustomer.Email, UpdateSourceTrigger=PropertyChanged}" />
<russkyc:ModernTextBox
Grid.Column="1"
Margin="12,0,0,0"
CornerRadius="5"
HelperText="Max Length (200)"
Placeholder="Contact Number"
Text="{Binding SelectedCustomer.ContactNumber, UpdateSourceTrigger=PropertyChanged}" />

</Grid>
<russkyc:ModernTextBox
Margin="0,12,0,0"
CornerRadius="5"
HelperText="Max Length (200)"
Placeholder="Primary Address"
Text="{Binding SelectedCustomer.Address, UpdateSourceTrigger=PropertyChanged}" />
<russkyc:ModernButton
Margin="0,12,0,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
Command="{Binding AddSelectedCustomerPetCommand}"
Content="Add Pet"
CornerRadius="5"
DefaultBackground="{DynamicResource bg-000}"
FontWeight="Medium"
Foreground="{DynamicResource fg-200}"
HoverBackground="{DynamicResource bg-000}"
LeftCenterIcon="{wpf:MaterialIconExt Kind=Add}"
PressedBackground="{DynamicResource bg-100}" />
<ItemsControl
MaxHeight="170"
Margin="0,10,0,0"
HorizontalAlignment="Stretch"
ItemsSource="{Binding SelectedCustomer.Pets.EditableCollectionView, UpdateSourceTrigger=PropertyChanged}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<templates:EditCustomerPetInfoCardTemplate />
</DataTemplate>
</ItemsControl.ItemTemplate>

<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel IsVirtualizing="True" VirtualizationMode="Recycling" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>

<ItemsControl.ItemContainerStyle>
<Style TargetType="{x:Type FrameworkElement}">
<Setter Property="Margin" Value="0,0,0,10" />
</Style>
</ItemsControl.ItemContainerStyle>

<ItemsControl.Template>
<ControlTemplate TargetType="ItemsControl">
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ScrollViewer
Padding="{TemplateBinding Padding}"
CanContentScroll="True"
Focusable="False"
VerticalScrollBarVisibility="Auto">
<ItemsPresenter />
</ScrollViewer>
</Border>
</ControlTemplate>
</ItemsControl.Template>
</ItemsControl>
<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 UpdateCustomerCommand}"
Content="Save Changes"
CornerRadius="5"
FontWeight="Medium"
LeftCenterIcon="{wpf:MaterialIconExt Kind=ContentSave}" />
</StackPanel>
</StackPanel>
</Grid>
</russkyc:ModernWindow>
15 changes: 15 additions & 0 deletions GroomWise.WPF/Views/Dialogs/EditCustomersView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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.

namespace GroomWise.Views.Dialogs;

public partial class EditCustomersView
{
public EditCustomersView(object vm)
{
DataContext = vm;
InitializeComponent();
}
}
19 changes: 13 additions & 6 deletions GroomWise.WPF/Views/Pages/CustomersView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:d="https://schemas.microsoft.com/expression/blend/2008"
xmlns:icons="clr-namespace:Material.Icons.WPF;assembly=Material.Icons.WPF"
xmlns:mc="https://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:observables="clr-namespace:GroomWise.Application.Observables;assembly=GroomWise.Application"
xmlns:russkyc="clr-namespace:org.russkyc.moderncontrols;assembly=Russkyc.ModernControls.WPF"
xmlns:templates="clr-namespace:GroomWise.Views.Templates"
xmlns:viewModels="clr-namespace:GroomWise.Application.ViewModels;assembly=GroomWise.Application"
Expand All @@ -22,8 +23,8 @@
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="300" />
</Grid.ColumnDefinitions>
<Grid
Grid.Row="0"
Expand Down Expand Up @@ -60,9 +61,19 @@
IconSize="18"
LeftIcon="{icons:MaterialIconExt Kind=AddBold}" />
</Grid>
<ItemsControl
<ContentControl
Grid.Row="1"
Grid.Column="0"
Content="{Binding SelectedCustomer, UpdateSourceTrigger=PropertyChanged}">
<ContentControl.Resources>
<DataTemplate DataType="{x:Type observables:ObservableCustomer}">
<templates:CustomerInfoCardTemplate Margin="0,0,16,0" />
</DataTemplate>
</ContentControl.Resources>
</ContentControl>
<ItemsControl
Grid.Row="1"
Grid.Column="1"
ItemsSource="{Binding Customers.EditableCollectionView, UpdateSourceTrigger=PropertyChanged}">
<ItemsControl.ItemTemplate>
<DataTemplate>
Expand Down Expand Up @@ -98,10 +109,6 @@
</ControlTemplate>
</ItemsControl.Template>
</ItemsControl>
<templates:CustomerInfoCardTemplate
Grid.Row="1"
Grid.Column="1"
Margin="16,0,0,0" />
</Grid>
</Grid>
</UserControl>
2 changes: 2 additions & 0 deletions GroomWise.WPF/Views/Pages/DashboardView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,10 @@
</Grid>
<Border
Grid.Row="1"
Grid.RowSpan="2"
Grid.Column="1"
Margin="16,0,0,0"
VerticalAlignment="Top"
Background="{DynamicResource bg-100}"
CornerRadius="10">
<Grid MinHeight="300" HorizontalAlignment="Stretch">
Expand Down
6 changes: 0 additions & 6 deletions GroomWise.WPF/Views/Pages/PetsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>

<ItemsControl.ItemContainerStyle>
<Style TargetType="{x:Type FrameworkElement}">
<Setter Property="Margin" Value="0,0,0,10" />
</Style>
</ItemsControl.ItemContainerStyle>

<ItemsControl.Template>
<ControlTemplate TargetType="ItemsControl">
<Border
Expand Down
Loading

0 comments on commit eae079d

Please sign in to comment.