50 lines
1.2 KiB
C#
50 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 AddPositionWindowViewModel : ViewModelBase
|
|
{
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
[ObservableProperty] private string _positionName;
|
|
[ObservableProperty] private List<Position> _positions;
|
|
|
|
public AddPositionWindowViewModel(IServiceProvider serviceProvider)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
|
|
using (var rep = serviceProvider.GetRequiredService<PositionRepository>())
|
|
Positions = new List<Position>(rep.GetPage());
|
|
}
|
|
|
|
[RelayCommand]
|
|
public void AddPosition()
|
|
{
|
|
var pos = new Position()
|
|
{
|
|
Name = PositionName
|
|
};
|
|
|
|
using (var rep = _serviceProvider.GetRequiredService<PositionRepository>())
|
|
rep.Add(pos);
|
|
CloseWindow();
|
|
}
|
|
|
|
[RelayCommand]
|
|
public void CloseWindow()
|
|
{
|
|
close();
|
|
}
|
|
|
|
private Action close;
|
|
public void SetClose(Action close)
|
|
{
|
|
this.close = close;
|
|
}
|
|
} |