using System.Collections.Generic; using System.Threading.Tasks; using Gestor.Application.Servicos.Financeiro; using Gestor.Application.Servicos.Generic; using Gestor.Application.ViewModels.Generic; using Gestor.Model.Common; using Gestor.Model.Domain.Financeiro; using Gestor.Model.Domain.Generic; namespace Gestor.Application.ViewModels.Financeiro; public class PlanoViewModel : BaseFinanceiroViewModel { private readonly PlanoServico _planoServico; private Plano _selectedPlano; public Plano Cancel; public Plano SelectedPlano { get { return _selectedPlano; } set { _selectedPlano = value; VerificarEnables((value != null) ? new long?(((DomainBase)value).Id) : null); OnPropertyChanged("SelectedPlano"); } } public PlanoViewModel(Plano plano) { _planoServico = new PlanoServico(); Seleciona(plano); } private async void Seleciona(Plano plano) { Loading(isLoading: true); await PermissaoTela((TipoTela)27); if (plano == null) { SelectedPlano = new Plano { Descricao = "", Ativo = true }; } else { SelectedPlano = plano; } Loading(isLoading: false); } public async Task>> Salvar() { List> errorMessages = SelectedPlano.Validate(); List> list = errorMessages; list.AddRange(await Validate()); if (errorMessages.Count > 0) { return errorMessages; } SelectedPlano = await _planoServico.Save(SelectedPlano); if (!_planoServico.Sucesso) { return null; } Alterar(alterar: false); ToggleSnackBar("PLANO SALVO COM SUCESSO"); return null; } public void Cancelar() { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown Loading(isLoading: true); if (((DomainBase)SelectedPlano).Id == 0L) { SelectedPlano = new Plano(); Alterar(alterar: false); Loading(isLoading: false); } else { Alterar(alterar: false); Loading(isLoading: false); } } public async Task>> Validate() { List> errors = new List>(); bool valida = true; List list = await new BaseServico().BuscarPlanoAsync(); if (list.Count > 0) { list.ForEach(delegate(Plano x) { if (((DomainBase)x).Id != ((DomainBase)SelectedPlano).Id && x.Descricao == SelectedPlano.Descricao) { valida = false; } }); } if (!valida) { errors.Add(new KeyValuePair("Descricao", "UM PLANO COM ESSE NOME JÁ EXISTE.")); } return errors; } 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_0012: Expected O, but got Unknown SelectedPlano = new Plano { Ativo = true }; Alterar(alterar: true); } }