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