From 674ca83ba9243a9e95a7568c797668dab6aee26a Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 10:35:25 -0300 Subject: feat: upload files --- .../ViewModels/Financeiro/PlanoViewModel.cs | 147 +++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 Gestor.Application/ViewModels/Financeiro/PlanoViewModel.cs (limited to 'Gestor.Application/ViewModels/Financeiro/PlanoViewModel.cs') diff --git a/Gestor.Application/ViewModels/Financeiro/PlanoViewModel.cs b/Gestor.Application/ViewModels/Financeiro/PlanoViewModel.cs new file mode 100644 index 0000000..e62f957 --- /dev/null +++ b/Gestor.Application/ViewModels/Financeiro/PlanoViewModel.cs @@ -0,0 +1,147 @@ +using Gestor.Application.Servicos.Financeiro; +using Gestor.Application.Servicos.Generic; +using Gestor.Application.ViewModels.Generic; +using Gestor.Model.Domain.Financeiro; +using Gestor.Model.Domain.Generic; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; + +namespace Gestor.Application.ViewModels.Financeiro +{ + public class PlanoViewModel : BaseFinanceiroViewModel + { + private readonly PlanoServico _planoServico; + + private Plano _selectedPlano; + + public Plano Cancel; + + public Plano SelectedPlano + { + get + { + return this._selectedPlano; + } + set + { + long? nullable; + this._selectedPlano = value; + if (value != null) + { + nullable = new long?(value.get_Id()); + } + else + { + nullable = null; + } + base.VerificarEnables(nullable); + base.OnPropertyChanged("SelectedPlano"); + } + } + + public PlanoViewModel(Plano plano) + { + this._planoServico = new PlanoServico(); + this.Seleciona(plano); + } + + public void Cancelar() + { + base.Loading(true); + if (this.SelectedPlano.get_Id() != 0) + { + base.Alterar(false); + base.Loading(false); + return; + } + this.SelectedPlano = new Plano(); + base.Alterar(false); + base.Loading(false); + } + + public void Incluir() + { + Plano plano = new Plano(); + plano.set_Ativo(true); + this.SelectedPlano = plano; + base.Alterar(true); + } + + public async Task>> Salvar() + { + List> keyValuePairs; + List> keyValuePairs1 = this.SelectedPlano.Validate(); + List> keyValuePairs2 = keyValuePairs1; + keyValuePairs2.AddRange(await this.Validate()); + keyValuePairs2 = null; + if (keyValuePairs1.Count <= 0) + { + this.SelectedPlano = await this._planoServico.Save(this.SelectedPlano); + if (this._planoServico.Sucesso) + { + base.Alterar(false); + base.ToggleSnackBar("PLANO SALVO COM SUCESSO", true); + keyValuePairs = null; + } + else + { + keyValuePairs = null; + } + } + else + { + keyValuePairs = keyValuePairs1; + } + keyValuePairs1 = null; + return keyValuePairs; + } + + private async void Seleciona(Plano plano) + { + base.Loading(true); + await base.PermissaoTela(27); + if (plano != null) + { + this.SelectedPlano = plano; + } + else + { + Plano plano1 = new Plano(); + plano1.set_Descricao(""); + plano1.set_Ativo(true); + this.SelectedPlano = plano1; + } + base.Loading(false); + } + + public async Task>> Validate() + { + List> keyValuePairs = new List>(); + bool flag = true; + List planos = await (new BaseServico()).BuscarPlanoAsync(); + if (planos.Count > 0) + { + planos.ForEach((Plano x) => { + if (x.get_Id() == this.SelectedPlano.get_Id()) + { + return; + } + if (x.get_Descricao() == this.SelectedPlano.get_Descricao()) + { + flag = false; + } + }); + } + if (!flag) + { + keyValuePairs.Add(new KeyValuePair("Descricao", "UM PLANO COM ESSE NOME JÁ EXISTE.")); + } + List> keyValuePairs1 = keyValuePairs; + keyValuePairs = null; + return keyValuePairs1; + } + } +} \ No newline at end of file -- cgit v1.2.3