viewmodel ins wpf gepackt, build failed
This commit is contained in:
87
DaSaSo.Wpf/ViewModel/ImpregnierungListViewModel.cs
Normal file
87
DaSaSo.Wpf/ViewModel/ImpregnierungListViewModel.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using DaSaSo.Domain.Model;
|
||||
using DaSaSo.Domain.Services;
|
||||
using DaSaSo.Wpf.ViewModel.Commands;
|
||||
using DaSaSo.Wpf.ViewModel.Interface;
|
||||
using Microsoft.Toolkit.Mvvm.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace DaSaSo.Wpf.ViewModel
|
||||
{
|
||||
public class ImpregnierungListViewModel : BaseViewModel
|
||||
{
|
||||
public ObservableCollection<Impregnation> Impregnations { get; }
|
||||
private readonly IDataService<Impregnation> _impregnationService;
|
||||
private Impregnation? _selectedImpregnation = null;
|
||||
public Impregnation? SelectedImpregnation
|
||||
{
|
||||
get => _selectedImpregnation;
|
||||
set
|
||||
{
|
||||
if(_selectedImpregnation != value)
|
||||
{
|
||||
_selectedImpregnation = value;
|
||||
OnPropertyChanged();
|
||||
OnPropertyChanged(nameof(CanSelectImpregnation));
|
||||
}
|
||||
}
|
||||
}
|
||||
public bool CanSelectImpregnation => SelectedImpregnation != null;
|
||||
public ICommand EditImpregnationCommand { get; set; }
|
||||
public ICommand AddImpregnationCommand { get; set; }
|
||||
bool _isLoading;
|
||||
|
||||
public bool IsLoading {
|
||||
get => _isLoading;
|
||||
set
|
||||
{
|
||||
if(_isLoading != value)
|
||||
{
|
||||
_isLoading = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ImpregnierungListViewModel(IDataService<Impregnation> impregnationService,IActualProject actualProject, IRenavigator editRenavigator)
|
||||
{
|
||||
IsLoading = true;
|
||||
Impregnations = new ObservableCollection<Impregnation>();
|
||||
_impregnationService = impregnationService;
|
||||
AddImpregnationCommand = new RelayCommand(() =>
|
||||
{
|
||||
Impregnation newImpregnation = new Impregnation()
|
||||
{
|
||||
Number = "Neu bitte Editieren!"
|
||||
};
|
||||
SelectedImpregnation = newImpregnation;
|
||||
Impregnations.Add(newImpregnation);
|
||||
OnPropertyChanged("Impregnations");
|
||||
});
|
||||
|
||||
//AddImpregnationCommand = //new AddImpregnationCommand(_impregnationService, editRenavigator);
|
||||
EditImpregnationCommand = new EditImpregnationCommand(_impregnationService, this,actualProject, editRenavigator);
|
||||
LoadImpregnations();
|
||||
|
||||
}
|
||||
|
||||
private async void LoadImpregnations()
|
||||
{
|
||||
var impregList = await _impregnationService.GetAll();
|
||||
InitCollection(Impregnations, impregList);
|
||||
IsLoading = false;
|
||||
}
|
||||
|
||||
private void InitCollection(ObservableCollection<Impregnation> target, IEnumerable<Impregnation> source)
|
||||
{
|
||||
target.Clear();
|
||||
foreach (var i in source)
|
||||
target.Add(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user