using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Threading.Tasks; using Gestor.Application.Servicos.Seguros; using Gestor.Application.ViewModels.Generic; using Gestor.Model.Common; using Gestor.Model.Domain.Generic; using Gestor.Model.Domain.Seguros; namespace Gestor.Application.ViewModels.Drawer; public class ExpedicaoViewModel : BaseSegurosViewModel { private readonly ExpedicaoServico _servico; private readonly Documento _documento; private bool _carregando; private Expedicao _selectedExpedicao = new Expedicao(); private ObservableCollection _expedicoes = new ObservableCollection(); public bool Carregando { get { return _carregando; } set { _carregando = value; base.EnableMenu = !value; OnPropertyChanged("Carregando"); } } public Expedicao SelectedExpedicao { get { return _selectedExpedicao; } set { _selectedExpedicao = value; VerificarEnables((value != null) ? new long?(((DomainBase)value).Id) : null); OnPropertyChanged("SelectedExpedicao"); } } public ObservableCollection Expedicoes { get { return _expedicoes; } set { _expedicoes = value; OnPropertyChanged("Expedicoes"); } } public ExpedicaoViewModel(Documento documento) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown _servico = new ExpedicaoServico(); _documento = documento; Seleciona(documento); } private async void Seleciona(Documento documento) { Carregando = true; await PermissaoTela((TipoTela)46); await Carregar(documento); if (Expedicoes.Count > 0) { SelectedExpedicao = Expedicoes.First(); } else { SelectedExpedicao = new Expedicao(); Alterar(alterar: false); base.EnableMenu = false; } Carregando = false; } private async Task Carregar(Documento documento) { Expedicoes = new ObservableCollection(await _servico.BuscarExpedicoes(documento)); } public void Incluir() { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown SelectedExpedicao = new Expedicao { Apolice = _documento }; Alterar(alterar: true); } public async Task>> Salvar() { SelectedExpedicao = await _servico.Save(SelectedExpedicao); if (!_servico.Sucesso) { return null; } long id = ((DomainBase)SelectedExpedicao).Id; await Carregar(SelectedExpedicao.Apolice); SelectedExpedicao = ((IEnumerable)Expedicoes).FirstOrDefault((Func)((Expedicao x) => ((DomainBase)x).Id == id)); Alterar(alterar: false); return null; } public async void CancelarAlteracao() { Carregando = true; long id = ((DomainBase)SelectedExpedicao).Id; await Carregar(SelectedExpedicao.Apolice); SelectedExpedicao = (Expedicao)((Expedicoes.Count > 0 && id > 0) ? ((IEnumerable)Expedicoes).FirstOrDefault((Func)((Expedicao x) => ((DomainBase)x).Id == id)) : ((Expedicoes.Count > 0 && id == 0L) ? ((object)Expedicoes.First()) : ((object)new Expedicao()))); Alterar(alterar: false); Carregando = false; } public async Task Excluir() { if (SelectedExpedicao == null || ((DomainBase)SelectedExpedicao).Id == 0L) { return false; } if (!(await ShowMessage("DESEJA EXCLUIR?", "SIM", "NÃO"))) { return false; } Carregando = true; if (!(await _servico.Delete(SelectedExpedicao))) { Carregando = false; return false; } int num = Expedicoes.IndexOf(SelectedExpedicao); Expedicoes.Remove(SelectedExpedicao); if (Expedicoes.Count > 0) { SelectedExpedicao = ((num < Expedicoes.Count) ? Expedicoes.ElementAt(num) : Expedicoes.Last()); } else { SelectedExpedicao = new Expedicao(); } Carregando = false; return true; } }