From 225aa1499e37faf9d38257caabbadc68d78b427e Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 12:29:41 -0300 Subject: decompiler.com --- .../CentroDeCustoViewmodel.cs | 219 +++++++++++++++++++++ 1 file changed, 219 insertions(+) create mode 100644 Decompiler/Gestor.Application.ViewModels.Financeiro/CentroDeCustoViewmodel.cs (limited to 'Decompiler/Gestor.Application.ViewModels.Financeiro/CentroDeCustoViewmodel.cs') diff --git a/Decompiler/Gestor.Application.ViewModels.Financeiro/CentroDeCustoViewmodel.cs b/Decompiler/Gestor.Application.ViewModels.Financeiro/CentroDeCustoViewmodel.cs new file mode 100644 index 0000000..8f7427a --- /dev/null +++ b/Decompiler/Gestor.Application.ViewModels.Financeiro/CentroDeCustoViewmodel.cs @@ -0,0 +1,219 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Threading.Tasks; +using Gestor.Application.Servicos.Financeiro; +using Gestor.Application.Servicos.Generic; +using Gestor.Application.ViewModels.Generic; +using Gestor.Common.Validation; +using Gestor.Model.Common; +using Gestor.Model.Domain.Financeiro; +using Gestor.Model.Domain.Generic; + +namespace Gestor.Application.ViewModels.Financeiro; + +public class CentroDeCustoViewmodel : BaseFinanceiroViewModel +{ + private readonly CentroServico _centroServico; + + private ObservableCollection _centrosFiltrados = new ObservableCollection(); + + private bool _isExpanded; + + private Centro _selectedCentro; + + private bool _ativo; + + private long _ultimoId; + + public Centro CancelCentro; + + public List Centros { get; set; } + + public ObservableCollection CentrosFiltrados + { + get + { + return _centrosFiltrados; + } + set + { + _centrosFiltrados = value; + IsExpanded = value != null && value.Count > 0; + OnPropertyChanged("CentrosFiltrados"); + } + } + + public bool IsExpanded + { + get + { + return _isExpanded; + } + set + { + _isExpanded = value; + OnPropertyChanged("IsExpanded"); + } + } + + public Centro SelectedCentro + { + get + { + return _selectedCentro; + } + set + { + _selectedCentro = value; + if (((DomainBase)value).Id > 0) + { + _ultimoId = ((DomainBase)value).Id; + } + VerificarEnables(((DomainBase)value).Id); + OnPropertyChanged("SelectedCentro"); + } + } + + public bool Ativo + { + get + { + return _ativo; + } + set + { + _ativo = bool.Parse(value.ToString()); + OnPropertyChanged("Ativo"); + } + } + + public CentroDeCustoViewmodel() + { + _centroServico = new CentroServico(); + base.EnableMenu = true; + Seleciona(); + } + + private async void Seleciona() + { + Loading(isLoading: true); + await PermissaoTela((TipoTela)29); + await SelecionaCentro(); + await SelecionaCentro(CentrosFiltrados.FirstOrDefault()); + Loading(isLoading: false); + } + + private async Task SelecionaCentro(Centro centros) + { + if (centros == null) + { + Alterar(alterar: false); + base.EnableMenu = false; + base.EnableAlterar = false; + return; + } + Loading(isLoading: true); + List source = await new BaseServico().BuscarCentroAsync(); + DomainBase.Copy(CentrosFiltrados.First((Centro x) => ((DomainBase)x).Id == ((DomainBase)centros).Id), source.First((Centro x) => ((DomainBase)x).Id == ((DomainBase)centros).Id)); + SelectedCentro = CentrosFiltrados.First((Centro x) => ((DomainBase)x).Id == ((DomainBase)centros).Id); + Loading(isLoading: false); + } + + public void SelecionaCentroDeCusto(Centro centro) + { + SelectedCentro = CentrosFiltrados.First((Centro x) => ((DomainBase)x).Id == ((DomainBase)centro).Id); + } + + public void Incluir() + { + //IL_001a: Unknown result type (might be due to invalid IL or missing references) + //IL_001f: Unknown result type (might be due to invalid IL or missing references) + //IL_002b: Expected O, but got Unknown + Centro selectedCentro = SelectedCentro; + _ultimoId = ((selectedCentro != null) ? ((DomainBase)selectedCentro).Id : 0); + SelectedCentro = new Centro + { + Ativo = true + }; + Alterar(alterar: true); + } + + public async Task>> Validate() + { + List> errors = new List>(); + bool valida = true; + List list = await new BaseServico().BuscarCentroAsync(); + if (list.Count > 0) + { + list.ForEach(delegate(Centro x) + { + if (((DomainBase)x).Id != ((DomainBase)SelectedCentro).Id && x.Descricao == SelectedCentro.Descricao && x.IdEmpresa == SelectedCentro.IdEmpresa) + { + valida = false; + } + }); + } + if (!valida) + { + errors.Add(new KeyValuePair("Descricao", "UM CENTRO COM ESSE NOME JÁ EXISTE.")); + } + return errors; + } + + public async Task>> Salvar() + { + List> errorMessages = SelectedCentro.Validate(); + List> list = errorMessages; + list.AddRange(await Validate()); + if (errorMessages.Count > 0) + { + return errorMessages; + } + SelectedCentro = await _centroServico.Save(SelectedCentro); + if (!_centroServico.Sucesso) + { + return null; + } + await SelecionaCentro(); + await SelecionaCentro(CentrosFiltrados.First((Centro x) => ((DomainBase)x).Id == ((DomainBase)SelectedCentro).Id)); + Alterar(alterar: false); + ToggleSnackBar("CENTRO DE CUSTO SALVO COM SUCESSO"); + return null; + } + + public async void CancelarAlteracao() + { + Loading(isLoading: true); + Alterar(alterar: false); + if (((DomainBase)SelectedCentro).Id > 0) + { + await SelecionaCentro(); + } + await SelecionaCentro(((IEnumerable)CentrosFiltrados).FirstOrDefault((Func)((Centro x) => ((DomainBase)x).Id == _ultimoId))); + Loading(isLoading: false); + } + + private async Task SelecionaCentro() + { + Centros = (from x in await new BaseServico().BuscarCentroAsync() + orderby x.Ativo descending, x.Descricao, x.Descricao + select x).ToList(); + CentrosFiltrados = new ObservableCollection(Centros); + } + + public async Task> Filtrar(string value) + { + return await Task.Run(() => FiltrarCentro(value)); + } + + public List FiltrarCentro(string filter) + { + CentrosFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection(Centros) : new ObservableCollection(from x in Centros + where ValidationHelper.RemoveDiacritics(x.Descricao.Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter)) + orderby Ativo descending, x.Descricao + select x)); + return CentrosFiltrados.ToList(); + } +} -- cgit v1.2.3