Skip to content

Commit

Permalink
refactor: update ViewModel methods for better synchronization
Browse files Browse the repository at this point in the history
Changed GetNotifications to ReloadNotifications with public visibility in DashboardViewModel. Added ReloadAppointments and ReloadCustomers methods to AppointmentsViewModel and CustomersViewModel for better synchronization. Updated other ViewModels accordingly.

Signed-off-by: russkyc <[email protected]>
  • Loading branch information
russkyc committed Jun 26, 2023
1 parent c6e3c53 commit 97f4681
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,7 @@ void AddAppointment()
.AsChild()
.ShowDialog();
ClearFields();
BuilderServices.Resolve<IAppointmentsViewModel>().ReloadAppointments();
BuilderServices.Resolve<IDashboardViewModel>().ReloadNotifications();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,22 @@ void GetAppointments()
ref _appointments,

Check warning on line 43 in Russkyc.GroomWise/ViewModels/Appointments/AppointmentsViewModel.cs

View workflow job for this annotation

GitHub Actions / build (Debug)

The field GroomWise.ViewModels.Appointments.AppointmentsViewModel._appointments is annotated with

Check warning on line 43 in Russkyc.GroomWise/ViewModels/Appointments/AppointmentsViewModel.cs

View workflow job for this annotation

GitHub Actions / build (Release)

The field GroomWise.ViewModels.Appointments.AppointmentsViewModel._appointments is annotated with
_dbContext.AppointmentRepository
.GetAll()
.Where(appointment => appointment.Date.Value.Month >= DateTime.Now.Month)
.Where(appointment => appointment.Date!.Value.Month >= DateTime.Now.Month)
.OrderBy(appointment => appointment.Date)
.ToList()
);
command.Execute();
_logger.Log(this, "Synchronized appointments collection");
}

public void ReloadAppointments()
{
GetAppointments();
}

[RelayCommand]
void AddAppointment()
{
_addAppointmentsViewFactory
.Create()
.Show();
_addAppointmentsViewFactory.Create().Show();
}
}
16 changes: 9 additions & 7 deletions Russkyc.GroomWise/ViewModels/Customers/AddCustomersViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ public partial class AddCustomersViewModel : ViewModelBase, IAddCustomersViewMod
private readonly IFactory<DialogView> _dialogFactory;

[ObservableProperty]
private string _firstName;
private string? _firstName;

[ObservableProperty]
private string _middleName;
private string? _middleName;

[ObservableProperty]
private string _lastName;
private string? _lastName;

[ObservableProperty]
private string _primaryAddress;
private string? _primaryAddress;

[ObservableProperty]
private string _secondaryAddress;
private string? _secondaryAddress;

[ObservableProperty]
private string _contactNumber;
private string? _contactNumber;

[ObservableProperty]
private string _email;
private string? _email;

public AddCustomersViewModel(
ILogger logger,
Expand Down Expand Up @@ -89,6 +89,8 @@ void AddCustomer()
_dbContext.ContactInfoRepository.Add(contactInfo);
_dbContext.CustomerContactInfoRepository.Add(customerContactInfo);

BuilderServices.Resolve<ICustomersViewModel>().ReloadCustomers();

ClearFields();
}

Expand Down
6 changes: 3 additions & 3 deletions Russkyc.GroomWise/ViewModels/Customers/CustomersViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public partial class CustomersViewModel : ViewModelBase, ICustomersViewModel
private readonly IFactory<CustomerCardViewModel> _customerCardViewModelFactory;

[ObservableProperty]
private CustomerCardViewModel _customerInfo;
private CustomerCardViewModel? _customerInfo;

[ObservableProperty]
private SynchronizedObservableCollection<CustomerCardViewModel> _customers;
Expand All @@ -31,7 +31,7 @@ IFactory<AddCustomersView> addCustomersViewFactory
_addCustomersViewFactory = addCustomersViewFactory;

Customers = new SynchronizedObservableCollection<CustomerCardViewModel>();
GetCustomers();
ReloadCustomers();
}

[RelayCommand]
Expand All @@ -40,7 +40,7 @@ void GetCustomerInfo(CustomerCardViewModel customer)
CustomerInfo = customer;
}

void GetCustomers()
public void ReloadCustomers()
{
Task.Run(() =>
{
Expand Down
4 changes: 2 additions & 2 deletions Russkyc.GroomWise/ViewModels/Dashboard/DashboardViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ IDbContext dbContext
_dbContext = dbContext;

Appointments = new SynchronizedObservableCollection<Appointment>();
GetNotifications();
ReloadNotifications();
}

[RelayCommand]
Expand All @@ -49,7 +49,7 @@ public void Invalidate()
GetTime();
}

private void GetNotifications()
public void ReloadNotifications()
{
var command = new SynchronizeCollectionCommand<
Appointment,
Expand Down
17 changes: 17 additions & 0 deletions Russkyc.GroomWise/ViewModels/Employees/EmployeesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public partial class EmployeesViewModel : ViewModelBase, IEmployeesViewModel
[ObservableProperty]
private string? _filter;

[ObservableProperty]
private SynchronizedObservableCollection<Role> _roles;

[ObservableProperty]
private SynchronizedObservableCollection<EmployeeCardViewModel> _employees;

Expand All @@ -27,9 +30,23 @@ IFactory<EmployeeCardViewModel> employeeCardViewModelFactory
_dbContext = dbContext;
_employeeCardViewModelFactory = employeeCardViewModelFactory;

Roles = new SynchronizedObservableCollection<Role>();
Employees = new SynchronizedObservableCollection<EmployeeCardViewModel>();

GetEmployees();
GetRoles();
}

void GetRoles()
{
Task.Run(() =>
{
var command = new SynchronizeCollectionCommand<
Role,
SynchronizedObservableCollection<Role>
>(ref _roles, _dbContext.RoleRepository.GetAll().ToList());

Check warning on line 47 in Russkyc.GroomWise/ViewModels/Employees/EmployeesViewModel.cs

View workflow job for this annotation

GitHub Actions / build (Debug)

The field GroomWise.ViewModels.Employees.EmployeesViewModel._roles is annotated with

Check warning on line 47 in Russkyc.GroomWise/ViewModels/Employees/EmployeesViewModel.cs

View workflow job for this annotation

GitHub Actions / build (Release)

The field GroomWise.ViewModels.Employees.EmployeesViewModel._roles is annotated with
command.Execute();
});
}

void GetEmployees()
Expand Down

0 comments on commit 97f4681

Please sign in to comment.