Skip to content

Commit

Permalink
feat: add customer management core, views. code refactoring and clean…
Browse files Browse the repository at this point in the history
…up. Update dependency injection to hopefully fix scoped resolving

Signed-off-by: russkyc <[email protected]>
  • Loading branch information
russkyc committed Jun 12, 2023
1 parent 6e48466 commit 476dbc0
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 31 deletions.
16 changes: 8 additions & 8 deletions Russkyc.GroomWise/Models/Abstractions/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public class Repository<T> : Interfaces.Repository.IRepository<T>
{
private readonly IDatabaseServiceAsync _databaseService;
private readonly object _collectionLock = new object();
public readonly Queue<Task> Changes;
private readonly Queue<Task> _changes;
private readonly List<T> _collection;

public Repository(IDatabaseServiceAsync databaseService)
{
Changes = new Queue<Task>();
_changes = new Queue<Task>();
_databaseService = databaseService;
_collection = Task.Run(databaseService.GetCollection<T>).Result.ToList();
}
Expand All @@ -25,7 +25,7 @@ public void Add(T entity)
lock (_collectionLock)
{
_collection.Add(entity);
Changes.Enqueue(new Task(() => _databaseService.Add(entity)));
_changes.Enqueue(new Task(() => _databaseService.Add(entity)));
}
}

Expand All @@ -35,7 +35,7 @@ public void AddRange(IEnumerable<T> entities)
{
var collection = entities as T[] ?? entities.ToArray();
_collection.AddRange(collection);
Changes.Enqueue(new Task(() => _databaseService.AddMultiple(collection.ToList())));
_changes.Enqueue(new Task(() => _databaseService.AddMultiple(collection.ToList())));
}
}

Expand Down Expand Up @@ -69,7 +69,7 @@ public bool Remove(T entity)
{
var result = _collection.Remove(entity);
if (result)
Changes.Enqueue(new Task(() => _databaseService.Delete<T>(t => entity == t)));
_changes.Enqueue(new Task(() => _databaseService.Delete<T>(t => entity == t)));
return result;
}
}
Expand All @@ -80,16 +80,16 @@ public int RemoveAll(Predicate<T> filter)
{
var result = _collection.RemoveAll(filter);
if (result > 0)
Changes.Enqueue(new Task(() => _databaseService.Delete<T>(t => filter(t))));
_changes.Enqueue(new Task(() => _databaseService.Delete<T>(t => filter(t))));
return result;
}
}

public void WriteToDb()
{
while (Changes.Count != 0)
while (_changes.Count != 0)
{
Changes.Dequeue().Start();
Task.Run(async () => await _changes.Dequeue());
}
}
}
2 changes: 1 addition & 1 deletion Russkyc.GroomWise/Russkyc.GroomWise.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<PackageReference Include="NETCore.Encrypt" Version="2.1.1" />
<PackageReference Include="Russkyc.Abstractions" Version="1.6.1" />
<PackageReference Include="Russkyc.AttachedUtilities.FilestreamExtensions" Version="1.1.1" />
<PackageReference Include="Russkyc.DependencyInjection" Version="0.9.8" />
<PackageReference Include="Russkyc.DependencyInjection" Version="0.9.10" />
<PackageReference Include="Russkyc.ModernControls.WPF" Version="1.9.18" />
<PackageReference Include="Russkyc.Services.HotKeyListener" Version="0.11.1" />
<PackageReference Include="Swordfish.NET.CollectionsV3" Version="3.3.12" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ IConnectionSourceProvider connectionSourceProvider
DbProvider.Sqlite
)
)
.UseAutoSyncStructure(true)
.UseLazyLoading(true)
.UseAutoSyncStructure(true)
.Build();
}

Expand Down
7 changes: 5 additions & 2 deletions Russkyc.GroomWise/Services/ServiceContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static IServicesContainer ConfigureServices()
.AddSingleton<IThemeManagerService, ThemeManagerService>()
.AddSingleton<IApplicationService, ApplicationService>()
// Add ViewModels
.AddSingleton<IAddCustomersViewModel, AddCustomersViewModel>()
.AddSingleton<IAppointmentsViewModel, AppointmentsViewModel>()
.AddSingleton<IAddAppointmentsViewModel, AddAppointmentsViewModel>()
.AddSingleton<IInventoryViewModel, InventoryViewModel>()
Expand All @@ -55,8 +56,11 @@ public static IServicesContainer ConfigureServices()
.AddSingleton<ILoginViewModel, LoginViewModel>()
.AddSingleton<IPetsViewModel, PetsViewModel>()
.AddSingleton<IMainViewModel, MainViewModel>()
// Add Dialogs
.AddSingleton<ILoginView, LoginView>()
.AddTransient<IAddCustomersView, AddCustomersView>()
.AddScoped<IAddAppointmentsView, AddAppointmentsView>()
// Add Views
.AddSingleton<IAddAppointmentsView, AddAppointmentsView>()
.AddSingleton<IAppointmentsView, AppointmentsView>()
.AddSingleton<IInventoryView, InventoryView>()
.AddSingleton<ICustomersView, CustomersView>()
Expand All @@ -65,7 +69,6 @@ public static IServicesContainer ConfigureServices()
.AddSingleton<ISettingsView, SettingsView>()
.AddSingleton<IServicesView, ServicesView>()
.AddSingleton<IReportsView, ReportsView>()
.AddSingleton<ILoginView, LoginView>()
.AddSingleton<IPetsView, PetsView>()
.AddSingleton<IMainView, MainView>()
// Build Container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ void AddAppointment()
{
BuilderServices.Resolve<IAddAppointmentsView>()
.AsChild()
.HideOnParentMouseDown()
.Show();
}
}
11 changes: 10 additions & 1 deletion Russkyc.GroomWise/ViewModels/Customers/CustomersViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void GetCustomerInfo(CustomerCardViewModel customer)
{
CustomerInfo = customer;
}

void GetCustomers()
{
Task.Run(() =>
Expand Down Expand Up @@ -99,4 +99,13 @@ void GetCustomers()
command.Execute();
});
}

[RelayCommand]
void AddCustomer()
{
BuilderServices.Resolve<IAddCustomersView>()
.AsChild()
.Show();
}

}
8 changes: 4 additions & 4 deletions Russkyc.GroomWise/Views/Dialogs/AddAppointmentsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
TitleBarHeight="0"
WindowStartupLocation="CenterOwner"
mc:Ignorable="d">
<Grid Style="{StaticResource FadeInAnimation}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300" />
<ColumnDefinition Width="*" />
Expand All @@ -30,10 +30,10 @@
</Grid.RowDefinitions>
<TextBlock Grid.Row="0"
Grid.Column="0"
Margin="20,16,0,12"
Margin="20,16,0,16"
HorizontalAlignment="Left"
FontSize="16"
Text="New Appointment" />
Text="Appointment Information" />
<Border Grid.Row="1"
Grid.Column="0"
MinHeight="290"
Expand Down Expand Up @@ -63,7 +63,7 @@
Text="{Binding Description, UpdateSourceTrigger=PropertyChanged}" />
<russkyc:ModernComboBox Margin="0,12,0,0"
CornerRadius="5"
DisplayMemberPath="ServiceName"
DisplayMemberPath="GroomingServiceServiceName"
ItemsSource="{Binding Services.EditableCollectionView, UpdateSourceTrigger=PropertyChanged}"
Placeholder="Service"
SelectedValue="{Binding Service.ServiceDescription, UpdateSourceTrigger=PropertyChanged}" />
Expand Down
118 changes: 106 additions & 12 deletions Russkyc.GroomWise/Views/Dialogs/AddCustomersView.xaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,106 @@
<Window x:Class="GroomWise.Views.Dialogs.AddCustomersView"
xmlns="http:https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http:https://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http:https://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:GroomWise.Views.Dialogs"
xmlns:mc="http:https://schemas.openxmlformats.org/markup-compatibility/2006"
Title="AddCustomersView"
Width="800"
Height="450"
mc:Ignorable="d">
<Grid />
</Window>
<russkyc:ModernWindow x:Class="GroomWise.Views.Dialogs.AddCustomersView"
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:icons="clr-namespace:Material.Icons.WPF;assembly=Material.Icons.WPF"
xmlns:mc="http:https://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:russkyc="clr-namespace:org.russkyc.moderncontrols;assembly=Russkyc.ModernControls.WPF"
Title="AddCustomersView"
Width="600"
Height="450"
NoDecorations="True"
ResizeMode="NoResize"
SizeToContent="Height"
TitleBarHeight="0"
WindowStartupLocation="CenterOwner"
mc:Ignorable="d">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0"
Margin="20,16,0,17"
HorizontalAlignment="Left"
FontSize="16"
Text="Customer Information" />
<StackPanel Grid.Row="1"
Margin="20,0,16,20"
HorizontalAlignment="Stretch"
VerticalAlignment="Top">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="150" />
<ColumnDefinition Width="150" />
</Grid.ColumnDefinitions>
<russkyc:ModernTextBox Grid.Column="0"
Margin="0,0,0,0"
CornerRadius="5"
HelperText="Max Length (200)"
Placeholder="First Name"
Text="{Binding Title, UpdateSourceTrigger=PropertyChanged}" />
<russkyc:ModernTextBox Grid.Column="1"
Margin="12,0,0,0"
CornerRadius="5"
HelperText="Max Length (200)"
Placeholder="Middle Name"
Text="{Binding Description, UpdateSourceTrigger=PropertyChanged}" />
<russkyc:ModernTextBox Grid.Column="2"
Margin="12,0,0,0"
CornerRadius="5"
HelperText="Max Length (200)"
Placeholder="Last Name"
Text="{Binding Description, UpdateSourceTrigger=PropertyChanged}" />
</Grid>
<russkyc:ModernTextBox Margin="0,12,0,0"
CornerRadius="5"
HelperText="Max Length (200)"
Placeholder="Street Address"
Text="{Binding Description, UpdateSourceTrigger=PropertyChanged}" />
<Grid Margin="0,12,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<russkyc:ModernTextBox Grid.Column="0"
CornerRadius="5"
HelperText="Max Length (200)"
Placeholder="City"
Text="{Binding Description, UpdateSourceTrigger=PropertyChanged}" />
<russkyc:ModernTextBox Grid.Column="1"
Margin="12,0,0,0"
CornerRadius="5"
HelperText="Max Length (200)"
Placeholder="ZIP Code"
Text="{Binding 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="Hide" TargetObject="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=russkyc:ModernWindow}}" />
</b:EventTrigger>
</b:Interaction.Triggers>
</russkyc:ModernButton>
<russkyc:ModernButton HorizontalAlignment="Right"
Command="{Binding AddAppointmentCommand}"
Content="Save Appointment"
CornerRadius="5"
FontWeight="Medium"
LeftCenterIcon="{icons:MaterialIconExt Kind=ContentSave}" />
</StackPanel>
</StackPanel>
</Grid>
</russkyc:ModernWindow>
3 changes: 2 additions & 1 deletion Russkyc.GroomWise/Views/Dialogs/AddCustomersView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ namespace GroomWise.Views.Dialogs;

public partial class AddCustomersView : IAddCustomersView
{
public AddCustomersView()
public AddCustomersView(IAddCustomersViewModel viewModel)
{
InitializeComponent();
DataContext = viewModel;
}

public void ClearFields()
Expand Down
1 change: 1 addition & 0 deletions Russkyc.GroomWise/Views/Pages/CustomersView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
Text="{Binding Filter, UpdateSourceTrigger=PropertyChanged}" />
<russkyc:ModernButton Grid.Column="3"
HorizontalAlignment="Right"
Command="{Binding AddCustomerCommand}"
Content="Add Customer"
CornerRadius="5"
FontWeight="Medium"
Expand Down

0 comments on commit 476dbc0

Please sign in to comment.