summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Application/ViewModels/Generic/ReordenarItensViewModel.cs
blob: f44c811868b7fadfd707fa9fb7e5a16246d026d4 (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
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 ReordenarItensViewModel : BaseSegurosViewModel
	{
		private readonly ItemServico _itemServico;

		private bool _carregando;

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

		public bool Carregando
		{
			get
			{
				return this._carregando;
			}
			set
			{
				this._carregando = value;
				base.OnPropertyChanged("Carregando");
			}
		}

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

		public ReordenarItensViewModel(List<long> ids)
		{
			this._itemServico = new ItemServico();
			this.CarregarItens(ids);
		}

		private async void CarregarItens(List<long> ids)
		{
			this.Carregando = true;
			this.Itens = await this._itemServico.BuscarItens(ids);
			this.Carregando = false;
		}

		public void ReordenarAutomaticamente()
		{
			foreach (Item iten in this.Itens)
			{
				iten.set_Ordem(new int?(this.Itens.IndexOf(iten) + 1));
			}
			this.Itens = new ObservableCollection<Item>(this.Itens);
		}
	}
}