using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Text; using System.Windows.Input; using XLIMS.CONTRACT; using XLIMS.DATA.Models; using XLIMS.MVVM.Base; namespace XLIMS.DEV.ViewModels { public class DeviceViewModel : ViewModelBase { #region Constructor public DeviceViewModel(ILimsService limsService,Spoi spoi, Tip tip = null) { _limsService = limsService; if (tip != null) _tip = tip; else _tip = new Tip() {IdspoiNavigation=spoi }; LoadSpnmtpAsync(); } #endregion //Constructor #region Events #endregion //Events #region Fields private readonly ILimsService _limsService; private readonly Tip _tip; private Spnmtp _currentSpnmtp; #endregion //Fields #region Properties public ObservableCollection AllSpnmtps { get; set; } = new(); public Spnmtp CurrentSpnmtp { get=> _currentSpnmtp; set { _currentSpnmtp = value; if (_currentSpnmtp != null) _tip.IdspnmtpNavigation = _currentSpnmtp; OnPropertyChanged(); } } public string? Tp { get => _tip.Tp; set { _tip.Tp = value; OnPropertyChanged(); } } public int Id => _tip.Id; #endregion //Properties #region Methods public async Task LoadSpnmtpAsync() { try { // Параллельная загрузка данных из разных доменов через подсервисы var spnmtpsTask = await _limsService.Spnmtps.GetAllAsync(); AllSpnmtps = new ObservableCollection(spnmtpsTask); OnPropertyChanged(nameof(AllSpnmtps)); } finally { } } private async Task SaveAsync() { if (_tip.Id == 0) await _limsService.Tips.AddAsync(_tip); else await _limsService.Tips.UpdateAsync(_tip); } public async Task Remove() { await _limsService.Tips.RemoveAsync(_tip); } #endregion //Methods #region Commands public ICommand SaveCommand => new AsyncRelayCommand(SaveAsync); #endregion //Commands } }