using System.Collections.ObjectModel; using Gestor.Application.Servicos.Seguros.Itens; using Gestor.Model.Common; using Gestor.Model.Domain.Seguros; namespace Gestor.Application.ViewModels.Generic; public class SelecionarItensViewModel : BaseSegurosViewModel { private ItemServico _itemServico; private ObservableCollection _itens = new ObservableCollection(); private bool? _allSelected; private bool _allSelectedChanging; public ObservableCollection Itens { get { return _itens; } set { _itens = value; OnPropertyChanged("Itens"); } } public bool? AllSelected { get { return _allSelected; } set { if (value != _allSelected) { _allSelected = value; AllSelectedChanged(); OnPropertyChanged("AllSelected"); } } } public SelecionarItensViewModel(long id) { _itemServico = new ItemServico(); CarregarItens(id); } private async void CarregarItens(long id) { Itens = await _itemServico.BuscarItens(id, (StatusItem)0); } private void AllSelectedChanged() { if (_allSelectedChanging) { return; } try { _allSelectedChanging = true; if (!AllSelected.HasValue) { return; } foreach (Item iten in Itens) { iten.Selecionado = AllSelected.Value; } } finally { _allSelectedChanging = false; } } }