46 lines
1.1 KiB
C#
46 lines
1.1 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 AddZoneWindowViewModel : ViewModelBase
|
|
{
|
|
private readonly IServiceProvider _serviceProvider;
|
|
[ObservableProperty] List<Zone> _zones;
|
|
[ObservableProperty] string _zoneName;
|
|
|
|
public AddZoneWindowViewModel(IServiceProvider serviceProvider)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
}
|
|
|
|
[RelayCommand]
|
|
public void AddZone()
|
|
{
|
|
var zone = new Zone
|
|
{
|
|
Name = ZoneName
|
|
};
|
|
|
|
using (var rep = _serviceProvider.GetRequiredService<ZoneRepository>())
|
|
rep.Add(zone);
|
|
CloseWindow();
|
|
}
|
|
|
|
[RelayCommand]
|
|
public void CloseWindow()
|
|
{
|
|
close();
|
|
}
|
|
|
|
private Action close;
|
|
public void SetClose(Action close)
|
|
{
|
|
this.close = close;
|
|
}
|
|
} |