summaryrefslogtreecommitdiff
path: root/Gestor.Application/ViewModels/Ferramentas/IncluirRamoViewModel.cs
blob: 89f3758ec4332abe519b0113704e6d59a45ead74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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<Ramo> _ramosAdicionadas;

		private ObservableCollection<Ramo> _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<Ramo> Ramos
		{
			get
			{
				return this._ramos;
			}
			set
			{
				this._ramos = value;
				base.OnPropertyChanged("Ramos");
			}
		}

		public List<Ramo> 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<Ramo> ramos)
		{
			this.RamosAdicionadas = ramos;
		}

		public async void Pesquisar()
		{
			if (!string.IsNullOrWhiteSpace(this.Filtro) && this.Filtro.Length >= 3)
			{
				string str = Uri.EscapeDataString(this.Filtro);
				List<Ramo> ramos = await Connection.Get<List<Ramo>>(string.Concat("Ramos/search?ramo=", str), true, false);
				this.Ramos = new ObservableCollection<Ramo>(
					from x in ramos
					where this.RamosAdicionadas.All<Ramo>((Ramo y) => y.get_Id() != x.get_Id())
					select x);
			}
		}
	}
}