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.Seguros; public class PerfilViewModel : BaseViewModel { private readonly PerfilServico _servico; private readonly Controle _controle; public long CancelPerfil; private Perfil _selectedPerfil = new Perfil(); private ObservableCollection _perfis; public Perfil SelectedPerfil { get { return _selectedPerfil; } set { _selectedPerfil = value; if (value != null && ((DomainBase)value).Id > 0) { CancelPerfil = ((DomainBase)value).Id; } VerificarEnables((value != null) ? new long?(((DomainBase)value).Id) : null); OnPropertyChanged("SelectedPerfil"); } } public ObservableCollection Perfis { get { return _perfis; } set { _perfis = value; OnPropertyChanged("Perfis"); } } public PerfilViewModel(Controle controle) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown _servico = new PerfilServico(); _controle = controle; Seleciona(((DomainBase)controle).Id); } private async void Seleciona(long id) { Loading(isLoading: true); await PermissaoTela((TipoTela)32); await SelecionaPerfis(id, 0L); Loading(isLoading: false); } private async Task SelecionaPerfis(long id, long perfilId = 0L) { Loading(isLoading: true); Perfis = new ObservableCollection(await _servico.BuscarPerfis(id)); SelectedPerfil = (Perfil)((perfilId == 0L) ? ((object)Perfis.FirstOrDefault()) : ((object)Perfis.First((Perfil x) => ((DomainBase)x).Id == perfilId))); Loading(isLoading: false); } public void Incluir() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Expected O, but got Unknown Perfil selectedPerfil = new Perfil { Controle = _controle, Cliente = _controle.Cliente, UsoProfissional = false, AntiFurto = (Antifurto)0, Isencao = false, SeguroVida = false, EstenderCobertura = false }; SelectedPerfil = selectedPerfil; Alterar(alterar: true); } public async Task>> Salvar() { List> list = SelectedPerfil.Validate(); if (list.Count > 0) { return list; } SelectedPerfil = await _servico.Save(SelectedPerfil); if (!_servico.Sucesso) { return null; } await SelecionaPerfis(((DomainBase)_controle).Id, ((DomainBase)SelectedPerfil).Id); ToggleSnackBar("PERFIL SALVO COM SUCESSO"); Alterar(alterar: false); return null; } public void CancelarAlteracao() { Loading(isLoading: true); if (CancelPerfil > 0) { SelectedPerfil = ((IEnumerable)Perfis).FirstOrDefault((Func)((Perfil x) => ((DomainBase)x).Id == CancelPerfil)); } Alterar(alterar: false); Loading(isLoading: false); } public async Task Excluir() { if (SelectedPerfil == null || ((DomainBase)SelectedPerfil).Id == 0L || !(await ShowMessage("DESEJA EXCLUIR?", "SIM", "NÃO"))) { return; } Loading(isLoading: true); bool isLast = SelectedPerfil == Perfis.Last(); if (!(await _servico.Delete(SelectedPerfil))) { Loading(isLoading: false); return; } if (isLast) { int num = Perfis.IndexOf(SelectedPerfil); if (num <= 0) { await SelecionaPerfis(((DomainBase)_controle).Id, 0L); } else { await SelecionaPerfis(((DomainBase)_controle).Id, ((DomainBase)Perfis[num - 1]).Id); } } else if (Perfis.Count > 0) { await SelecionaPerfis(((DomainBase)_controle).Id, ((DomainBase)Perfis[Perfis.IndexOf(SelectedPerfil) + 1]).Id); } Loading(isLoading: false); ToggleSnackBar("PERFIL EXCLUÍDO COM SUCESSO"); } }