using Gestor.Application.Helpers; using Gestor.Application.ViewModels.Generic; using Gestor.Model.Domain.Generic; using Gestor.Model.Domain.Seguros; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; using System.Runtime.CompilerServices; using System.Threading.Tasks; namespace Gestor.Application.ViewModels.Ferramentas { public class IncluirRamoViewModel : BaseSegurosViewModel { private Ramo _selectedRamo; private Ramo _adicionarRamo; private List _ramosAdicionadas; private ObservableCollection _ramos; private string _filtro; public Ramo AdicionarRamo { get { return this._adicionarRamo; } set { this._adicionarRamo = value; base.OnPropertyChanged("AdicionarRamo"); } } public string Filtro { get { return this._filtro; } set { this._filtro = value; base.OnPropertyChanged("Filtro"); } } public ObservableCollection Ramos { get { return this._ramos; } set { this._ramos = value; base.OnPropertyChanged("Ramos"); } } public List RamosAdicionadas { get { return this._ramosAdicionadas; } set { this._ramosAdicionadas = value; base.OnPropertyChanged("RamosAdicionadas"); } } public Ramo SelectedRamo { get { return this._selectedRamo; } set { this._selectedRamo = value; base.OnPropertyChanged("SelectedRamo"); } } public IncluirRamoViewModel(List ramos) { this.RamosAdicionadas = ramos; } public async void Pesquisar() { if (!string.IsNullOrWhiteSpace(this.Filtro) && this.Filtro.Length >= 3) { string str = Uri.EscapeDataString(this.Filtro); List ramos = await Connection.Get>(string.Concat("Ramos/search?ramo=", str), true, false); this.Ramos = new ObservableCollection( from x in ramos where this.RamosAdicionadas.All((Ramo y) => y.get_Id() != x.get_Id()) select x); } } } }