51 lines
1.2 KiB
C#
51 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using BathHouseManagmet.Database;
|
|
using BathHouseManagmet.Models;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace BathHouseManagmet.ViewModels;
|
|
|
|
public partial class AddClientWindowViewModel : ViewModelBase
|
|
{
|
|
private readonly IServiceProvider _serviceProvider;
|
|
[ObservableProperty] List<Client> _clients;
|
|
[ObservableProperty] string _clientName;
|
|
[ObservableProperty] string _clientSurname;
|
|
[ObservableProperty] string _clientEmail;
|
|
|
|
|
|
public AddClientWindowViewModel(IServiceProvider serviceProvider)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
}
|
|
|
|
[RelayCommand]
|
|
public void AddClient()
|
|
{
|
|
var client = new Client
|
|
{
|
|
Name = _clientName,
|
|
Surname = _clientSurname,
|
|
Email = _clientEmail
|
|
};
|
|
|
|
using (var rep = _serviceProvider.GetRequiredService<ClientRepository>())
|
|
rep.Add(client);
|
|
CloseWindow();
|
|
}
|
|
|
|
[RelayCommand]
|
|
public void CloseWindow()
|
|
{
|
|
close();
|
|
}
|
|
|
|
private Action close;
|
|
public void SetClose(Action close)
|
|
{
|
|
this.close = close;
|
|
}
|
|
} |