summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.ViewModels.Financeiro/CentroDeCustoViewmodel.cs
diff options
context:
space:
mode:
authorLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 15:29:41 +0000
committerLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 15:29:41 +0000
commit225aa1499e37faf9d38257caabbadc68d78b427e (patch)
tree102bb7a40c58595348ae9d3c7076201759fe0720 /Decompiler/Gestor.Application.ViewModels.Financeiro/CentroDeCustoViewmodel.cs
parent1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (diff)
downloadgestor-225aa1499e37faf9d38257caabbadc68d78b427e.tar.gz
gestor-225aa1499e37faf9d38257caabbadc68d78b427e.zip
decompiler.com
Diffstat (limited to 'Decompiler/Gestor.Application.ViewModels.Financeiro/CentroDeCustoViewmodel.cs')
-rw-r--r--Decompiler/Gestor.Application.ViewModels.Financeiro/CentroDeCustoViewmodel.cs219
1 files changed, 219 insertions, 0 deletions
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<Centro> _centrosFiltrados = new ObservableCollection<Centro>();
+
+ private bool _isExpanded;
+
+ private Centro _selectedCentro;
+
+ private bool _ativo;
+
+ private long _ultimoId;
+
+ public Centro CancelCentro;
+
+ public List<Centro> Centros { get; set; }
+
+ public ObservableCollection<Centro> 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<Centro> source = await new BaseServico().BuscarCentroAsync();
+ DomainBase.Copy<Centro, Centro>(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<List<KeyValuePair<string, string>>> Validate()
+ {
+ List<KeyValuePair<string, string>> errors = new List<KeyValuePair<string, string>>();
+ bool valida = true;
+ List<Centro> 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<string, string>("Descricao", "UM CENTRO COM ESSE NOME JÁ EXISTE."));
+ }
+ return errors;
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Salvar()
+ {
+ List<KeyValuePair<string, string>> errorMessages = SelectedCentro.Validate();
+ List<KeyValuePair<string, string>> 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<Centro>)CentrosFiltrados).FirstOrDefault((Func<Centro, bool>)((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<Centro>(Centros);
+ }
+
+ public async Task<List<Centro>> Filtrar(string value)
+ {
+ return await Task.Run(() => FiltrarCentro(value));
+ }
+
+ public List<Centro> FiltrarCentro(string filter)
+ {
+ CentrosFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<Centro>(Centros) : new ObservableCollection<Centro>(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();
+ }
+}