93 lines
2.8 KiB
C#
93 lines
2.8 KiB
C#
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 SpnmtpsViewModel:ViewModelBase
|
|
{
|
|
#region Constructor
|
|
public SpnmtpsViewModel(ILimsService limsService, IDialogService dialogService)
|
|
{
|
|
_limsService = limsService;
|
|
_dialogService = dialogService;
|
|
_limsService.Spnmtps.SetChanged += OnSpnmtpsChanged;
|
|
LoadDataAsync();
|
|
}
|
|
#endregion //Constructor
|
|
|
|
#region Events
|
|
private async void OnSpnmtpsChanged()
|
|
{
|
|
await LoadDataAsync();
|
|
}
|
|
#endregion //Events
|
|
|
|
#region Fields
|
|
private readonly IDialogService _dialogService;
|
|
private readonly ILimsService _limsService;
|
|
private bool _isLoading;
|
|
private SpnmtpViewModel _currentSpnmtp;
|
|
#endregion //Fields
|
|
|
|
#region Properties
|
|
public ObservableCollection<SpnmtpViewModel> AllSpnmtps { get; set; } = new();
|
|
public SpnmtpViewModel CurrentSpnmtp
|
|
{
|
|
get => _currentSpnmtp;
|
|
set { _currentSpnmtp = value; OnPropertyChanged(); }
|
|
}
|
|
public bool IsLoading
|
|
{
|
|
get => _isLoading;
|
|
set { _isLoading = value; OnPropertyChanged(); }
|
|
}
|
|
#endregion //Properties
|
|
|
|
#region Methods
|
|
public async Task LoadDataAsync()
|
|
{
|
|
IsLoading = true;
|
|
|
|
try
|
|
{
|
|
// Параллельная загрузка данных из разных доменов через подсервисы
|
|
var spnmtpsTask = await _limsService.Spnmtps.GetAllAsync();
|
|
|
|
AllSpnmtps = new ObservableCollection<SpnmtpViewModel>(spnmtpsTask.Select(s => new SpnmtpViewModel(_limsService, s)));
|
|
OnPropertyChanged(nameof(AllSpnmtps));
|
|
}
|
|
finally
|
|
{
|
|
IsLoading = false;
|
|
}
|
|
}
|
|
private void Add()
|
|
{
|
|
_dialogService.ShowDialog(new SpnmtpViewModel(_limsService));
|
|
}
|
|
private void Edit()
|
|
{
|
|
_dialogService.ShowDialog(CurrentSpnmtp);
|
|
}
|
|
private async Task DelAsync()
|
|
{
|
|
await CurrentSpnmtp.Remove();
|
|
AllSpnmtps.Remove(CurrentSpnmtp);
|
|
OnPropertyChanged(nameof(AllSpnmtps));
|
|
}
|
|
#endregion //Methods
|
|
|
|
#region Commands
|
|
public ICommand AddCommand => new RelayCommand(p => Add());
|
|
public ICommand EditCommand => new RelayCommand(p => Edit(), p => CurrentSpnmtp != null);
|
|
public ICommand DelCommand => new AsyncRelayCommand(DelAsync, () => CurrentSpnmtp != null);
|
|
#endregion //Commands
|
|
|
|
}
|
|
}
|