summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Application/ViewModels/Generic/SelecionarItensViewModel.cs
blob: 852bedd93d956c0cb8b7db1d1e5d318739437532 (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
using Gestor.Application.Servicos.Seguros.Itens;
using Gestor.Model.Domain.Seguros;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

namespace Gestor.Application.ViewModels.Generic
{
	public class SelecionarItensViewModel : BaseSegurosViewModel
	{
		private ItemServico _itemServico;

		private ObservableCollection<Item> _itens = new ObservableCollection<Item>();

		private bool? _allSelected;

		private bool _allSelectedChanging;

		public bool? AllSelected
		{
			get
			{
				return this._allSelected;
			}
			set
			{
				bool? nullable = value;
				bool? nullable1 = this._allSelected;
				if (nullable.GetValueOrDefault() == nullable1.GetValueOrDefault() & nullable.HasValue == nullable1.HasValue)
				{
					return;
				}
				this._allSelected = value;
				this.AllSelectedChanged();
				base.OnPropertyChanged("AllSelected");
			}
		}

		public ObservableCollection<Item> Itens
		{
			get
			{
				return this._itens;
			}
			set
			{
				this._itens = value;
				base.OnPropertyChanged("Itens");
			}
		}

		public SelecionarItensViewModel(long id)
		{
			this._itemServico = new ItemServico();
			this.CarregarItens(id);
		}

		private void AllSelectedChanged()
		{
			if (this._allSelectedChanging)
			{
				return;
			}
			try
			{
				this._allSelectedChanging = true;
				if (this.AllSelected.HasValue)
				{
					foreach (Item iten in this.Itens)
					{
						iten.set_Selecionado(this.AllSelected.Value);
					}
				}
			}
			finally
			{
				this._allSelectedChanging = false;
			}
		}

		private async void CarregarItens(long id)
		{
			this.Itens = await this._itemServico.BuscarItens(id, 0);
		}
	}
}