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 _itens = new ObservableCollection(); public bool Carregando { get { return this._carregando; } set { this._carregando = value; base.OnPropertyChanged("Carregando"); } } public ObservableCollection Itens { get { return this._itens; } set { this._itens = value; base.OnPropertyChanged("Itens"); } } public ReordenarItensViewModel(List ids) { this._itemServico = new ItemServico(); this.CarregarItens(ids); } private async void CarregarItens(List 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(this.Itens); } } }