Skip to content

Commit

Permalink
refactor: update appointment to use DateOnly & TimeOnly for appointme…
Browse files Browse the repository at this point in the history
…nt scheduling

Signed-off-by: Russell Camo <[email protected]>
  • Loading branch information
russkyc committed Sep 2, 2023
1 parent 7620d78 commit 748eabb
Show file tree
Hide file tree
Showing 14 changed files with 146 additions and 60 deletions.
24 changes: 16 additions & 8 deletions GroomWise.Application/Observables/ObservableAppointment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// 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.Domain.Entities;
using GroomWise.Domain.Enums;
using Lombok.NET;
using Swordfish.NET.Collections;
Expand All @@ -13,21 +12,30 @@ namespace GroomWise.Application.Observables;
[NotifyPropertyChanged]
public partial class ObservableAppointment
{
[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
private DateTime? _date;
[Property]
private Guid _id;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private DateOnly? _date;

[Property]
private TimeOnly? _startTime;

[Property]
private TimeOnly? _endTime;

[Property]
private AppointmentStatus? _status;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private ObservablePet? _pet;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private ObservableCustomer? _customer;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private ConcurrentObservableCollection<ObservableEmployee>? _employees = new();

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private ConcurrentObservableCollection<ObservableAppointmentService>? _services = new();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ namespace GroomWise.Application.Observables;
[NotifyPropertyChanged]
public partial class ObservableAppointmentService
{
[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private ObservableGroomingService _groomingService;
}
14 changes: 7 additions & 7 deletions GroomWise.Application/Observables/ObservableCustomer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ namespace GroomWise.Application.Observables;
[NotifyPropertyChanged]
public partial class ObservableCustomer
{
[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private Guid _id;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private string _fullName;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private string _address;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private string _contactNumber;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private string _email;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private ConcurrentObservableCollection<ObservableAppointment> _appointments = new();

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private ConcurrentObservableCollection<ObservablePet> _pets = new();
}
24 changes: 12 additions & 12 deletions GroomWise.Application/Observables/ObservableEmployee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,40 @@ namespace GroomWise.Application.Observables;
[NotifyPropertyChanged]
public partial class ObservableEmployee
{
[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private Guid _id;
public string FullName => $"{FirstName} {LastName}";

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private string? _prefix;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private string? _firstName;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private string? _middleName;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private string? _lastName;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private string? _suffix;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private string _address;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private string _contactNumber;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private string _email;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private IList<Pet>? _pets;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private IList<Appointment>? _appointments;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private IList<Role>? _roles;
}
10 changes: 5 additions & 5 deletions GroomWise.Application/Observables/ObservableGroomingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ namespace GroomWise.Application.Observables;
[NotifyPropertyChanged]
public partial class ObservableGroomingService
{
[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private Guid _id;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private string? _type;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private double _hourSpan;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private double _minuteSpan;

public TimeSpan TimeSpan
Expand All @@ -32,6 +32,6 @@ public TimeSpan TimeSpan
}
}

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private string? _description;
}
10 changes: 5 additions & 5 deletions GroomWise.Application/Observables/ObservablePet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ namespace GroomWise.Application.Observables;
[NotifyPropertyChanged]
public partial class ObservablePet
{
[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private Guid _id;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private string? _name;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private int? _age;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private string? _breed;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private string? _gender;

}
8 changes: 4 additions & 4 deletions GroomWise.Application/Observables/ObservableProduct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ namespace GroomWise.Application.Observables;
[NotifyPropertyChanged]
public partial class ObservableProduct
{
[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private Guid _id;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private string? _productName;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private string? _productDescription;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
[Property]
private int _quantity;
}
43 changes: 37 additions & 6 deletions GroomWise.Application/ViewModels/AppointmentViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,18 @@ public partial class AppointmentViewModel
partial void OnInitialize()
{
PopulateCollections();
ActiveAppointment = new ObservableAppointment { Date = DateTime.Today };
ActiveAppointment = new ObservableAppointment
{
Date = DateOnly.FromDateTime(DateTime.Today)
};
}

private async void PopulateCollections()
{
await Task.Run(() =>
{
var appointments = GroomWiseDbContext.Appointments
.GetMultiple(appointment => appointment.Date >= DateTime.Today)
.GetMultiple(appointment => appointment.Date >= DateOnly.FromDateTime(DateTime.Now))
.Select(AppointmentMapper.ToObservable)
.OrderBy(appointment => appointment.Date);
Expand Down Expand Up @@ -90,11 +93,36 @@ await Task.Run(() =>
DialogService.CreateAddAppointmentsDialog(this, NavigationService);
return;
}
ActiveAppointment = new ObservableAppointment { Date = DateTime.Today };
ActiveAppointment = new ObservableAppointment
{
Date = DateOnly.FromDateTime(DateTime.Today)
};
DialogService.CreateCustomerSelectionDialog(this, NavigationService);
});
}

[Command]
private async Task CancelAppointment(object param)
{
if (param is ObservableAppointment appointment)
{
await Task.Run(() =>
{
var dialogResult = DialogService.Create(
"Appointments",
$"Cancel {appointment.Customer.FullName.Split(" ")[0]}'s Appointment?",
NavigationService
);
if (dialogResult is true)
{
Appointments.Remove(appointment);
GroomWiseDbContext.Appointments.Delete(appointment.Id);
}
});
}
}

[Command]
private async Task SelectCustomer(object param)
{
Expand Down Expand Up @@ -141,8 +169,8 @@ ActiveAppointment.Services is null
}
var dialogResult = DialogService.Create(
"GroomWise",
"Create Appointment?",
"Appointments",
$"Book Appointment for {ActiveAppointment.Customer.FullName.Split(" ")[0]}?",
NavigationService
);
if (dialogResult is true)
Expand All @@ -153,7 +181,10 @@ ActiveAppointment.Services is null
EventAggregator.Publish(
new PublishNotificationEvent($"Appointment saved", NotificationType.Success)
);
ActiveAppointment = new ObservableAppointment { Date = DateTime.Today };
ActiveAppointment = new ObservableAppointment
{
Date = DateOnly.FromDateTime(DateTime.Today)
};
OnPropertyChanged(nameof(ActiveAppointment.Date));
PopulateCollections();
}
Expand Down
4 changes: 3 additions & 1 deletion GroomWise.Application/ViewModels/DashboardViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ private async void PopulateCollections()
await Task.Run(() =>
{
var appointments = GroomWiseDbContext.Appointments
.GetMultiple(appointment => appointment.Date == DateTime.Today)
.GetMultiple(
appointment => appointment.Date == DateOnly.FromDateTime(DateTime.Today)
)
.Select(AppointmentMapper.ToObservable)
.OrderBy(appointment => appointment.Date);
Appointments = new ConcurrentObservableCollection<ObservableAppointment>(appointments);
Expand Down
4 changes: 3 additions & 1 deletion GroomWise.Domain/Entities/Appointment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public class Appointment : IEntity
{
[BsonId]
public Guid Id { get; set; }
public DateTime? Date { get; set; }
public DateOnly? Date { get; set; }
public TimeOnly? StartTime { get; set; }
public TimeOnly? EndTime { get; set; }
public AppointmentStatus? Status { get; set; }
public Pet? Pet { get; set; }
public Customer? Customer { get; set; }
Expand Down
28 changes: 28 additions & 0 deletions GroomWise.WPF/Converters/DateOnlyToDateTimeConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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;
using System.Globalization;
using System.Windows.Data;

namespace GroomWise.Converters;

[ValueConversion(typeof(DateOnly), typeof(DateTime))]
public class DateOnlyToDateTimeConverter : IValueConverter
{
public static DateOnlyToDateTimeConverter Instance = new();

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var dt = (DateOnly)value;
return new DateTime(dt.Year, dt.Month, dt.Day);
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
var d = (DateTime)value;
return DateOnly.FromDateTime(d);
}
}
2 changes: 1 addition & 1 deletion GroomWise.WPF/Views/Dialogs/AddAppointmentsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
Margin="5"
VerticalAlignment="Top"
IsEditable="True"
SelectedDate="{Binding ActiveAppointment.Date, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
SelectedDate="{Binding ActiveAppointment.Date, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={x:Static converter:DateOnlyToDateTimeConverter.Instance}}" />
</Border>
<Grid Grid.Row="1" Grid.Column="1">
<Grid.RowDefinitions>
Expand Down
4 changes: 2 additions & 2 deletions GroomWise.WPF/Views/Dialogs/AddServicesView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
IsEditable="True"
IsSynchronizedWithCurrentItem="True"
Placeholder="Hours"
SelectedValue="{Binding ActiveGroomingService.HourSpan, UpdateSourceTrigger=PropertyChanged}">
Text="{Binding ActiveGroomingService.HourSpan, UpdateSourceTrigger=PropertyChanged}">
<ComboBoxItem>0</ComboBoxItem>
<ComboBoxItem>1</ComboBoxItem>
<ComboBoxItem>2</ComboBoxItem>
Expand All @@ -77,7 +77,7 @@
IsEditable="True"
IsSynchronizedWithCurrentItem="True"
Placeholder="Minutes"
SelectedValue="{Binding ActiveGroomingService.MinuteSpan, UpdateSourceTrigger=PropertyChanged}">
Text="{Binding ActiveGroomingService.MinuteSpan, UpdateSourceTrigger=PropertyChanged}">
<ComboBoxItem>0</ComboBoxItem>
<ComboBoxItem>5</ComboBoxItem>
<ComboBoxItem>10</ComboBoxItem>
Expand Down
Loading

0 comments on commit 748eabb

Please sign in to comment.