summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.ViewModels.Generic/ReordenarItensViewModel.cs
blob: 27ca9c24179a08f9435fe7ec9f8f5684b1f33fba (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
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Gestor.Application.Servicos.Seguros.Itens;
using Gestor.Model.Domain.Seguros;

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 _carregando;
		}
		set
		{
			_carregando = value;
			OnPropertyChanged("Carregando");
		}
	}

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

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

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

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