summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Application/ViewModels/Ferramentas/IncluirSeguradoraViewModel.cs
blob: ebeed4032cec1e218d31d2a0db78edb6cf1f9e53 (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 IncluirSeguradoraViewModel : BaseSegurosViewModel
	{
		private Seguradora _selectedSeguradora;

		private Seguradora _adicionarSeguradora;

		private List<Seguradora> _seguradorasAdicionadas;

		private ObservableCollection<Seguradora> _seguradoras;

		private string _filtro;

		public Seguradora AdicionarSeguradora
		{
			get
			{
				return this._adicionarSeguradora;
			}
			set
			{
				this._adicionarSeguradora = value;
				base.OnPropertyChanged("AdicionarSeguradora");
			}
		}

		public string Filtro
		{
			get
			{
				return this._filtro;
			}
			set
			{
				this._filtro = value;
				base.OnPropertyChanged("Filtro");
			}
		}

		public ObservableCollection<Seguradora> Seguradoras
		{
			get
			{
				return this._seguradoras;
			}
			set
			{
				this._seguradoras = value;
				base.OnPropertyChanged("Seguradoras");
			}
		}

		public List<Seguradora> SeguradorasAdicionadas
		{
			get
			{
				return this._seguradorasAdicionadas;
			}
			set
			{
				this._seguradorasAdicionadas = value;
				base.OnPropertyChanged("SeguradorasAdicionadas");
			}
		}

		public Seguradora SelectedSeguradora
		{
			get
			{
				return this._selectedSeguradora;
			}
			set
			{
				this._selectedSeguradora = value;
				base.OnPropertyChanged("SelectedSeguradora");
			}
		}

		public IncluirSeguradoraViewModel(List<Seguradora> seguradoras)
		{
			this.SeguradorasAdicionadas = seguradoras;
		}

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