first edit
This commit is contained in:
91
XLIMS.SP/ViewModels/SpoisViewModel.cs
Normal file
91
XLIMS.SP/ViewModels/SpoisViewModel.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text;
|
||||
using System.Windows.Input;
|
||||
using XLIMS.CONTRACT;
|
||||
using XLIMS.MVVM.Base;
|
||||
|
||||
namespace XLIMS.SP.ViewModels
|
||||
{
|
||||
public class SpoisViewModel:ViewModelBase
|
||||
{
|
||||
#region Constructor
|
||||
public SpoisViewModel(ILimsService limsService,IDialogService dialogService)
|
||||
{
|
||||
_limsService = limsService;
|
||||
_dialogService = dialogService;
|
||||
_limsService.Spois.SetChanged += OnSpoisChanged;
|
||||
LoadDataAsync();
|
||||
}
|
||||
#endregion //Constructor
|
||||
|
||||
#region Events
|
||||
private async void OnSpoisChanged()
|
||||
{
|
||||
await LoadDataAsync();
|
||||
}
|
||||
#endregion //Events
|
||||
|
||||
#region Fields
|
||||
private readonly IDialogService _dialogService;
|
||||
private readonly ILimsService _limsService;
|
||||
private bool _isLoading;
|
||||
private SpoiViewModel _currentSpoi;
|
||||
#endregion //Fields
|
||||
|
||||
#region Properties
|
||||
public ObservableCollection<SpoiViewModel> AllSpois { get; set; } = new();
|
||||
public SpoiViewModel CurrentSpoi
|
||||
{
|
||||
get => _currentSpoi;
|
||||
set { _currentSpoi = value; OnPropertyChanged(); }
|
||||
}
|
||||
public bool IsLoading
|
||||
{
|
||||
get => _isLoading;
|
||||
set { _isLoading = value; OnPropertyChanged(); }
|
||||
}
|
||||
#endregion //Properties
|
||||
|
||||
#region Methods
|
||||
public async Task LoadDataAsync()
|
||||
{
|
||||
IsLoading = true;
|
||||
|
||||
try
|
||||
{
|
||||
// Параллельная загрузка данных из разных доменов через подсервисы
|
||||
var spoisTask = await _limsService.Spois.GetAllAsync();
|
||||
|
||||
AllSpois = new ObservableCollection<SpoiViewModel>(spoisTask.Select(s => new SpoiViewModel(_limsService, s)));
|
||||
OnPropertyChanged(nameof(AllSpois));
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsLoading = false;
|
||||
}
|
||||
}
|
||||
private void Add()
|
||||
{
|
||||
_dialogService.ShowDialog(new SpoiViewModel(_limsService));
|
||||
}
|
||||
private void Edit()
|
||||
{
|
||||
_dialogService.ShowDialog(CurrentSpoi);
|
||||
}
|
||||
private async Task DelAsync()
|
||||
{
|
||||
await CurrentSpoi.Remove();
|
||||
AllSpois.Remove(CurrentSpoi);
|
||||
OnPropertyChanged(nameof(AllSpois));
|
||||
}
|
||||
#endregion //Methods
|
||||
|
||||
#region Commands
|
||||
public ICommand AddCommand => new RelayCommand(p => Add());
|
||||
public ICommand EditCommand => new RelayCommand(p => Edit(), p => CurrentSpoi != null);
|
||||
public ICommand DelCommand => new AsyncRelayCommand(DelAsync, () => CurrentSpoi != null);
|
||||
#endregion //Commands
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user