summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Application/ViewModels/Financeiro/CentroDeCustoViewmodel.cs
diff options
context:
space:
mode:
authorLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 13:38:18 +0000
committerLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 13:38:18 +0000
commit1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (patch)
treee1c3b20ea08f0cf71122a1e73f0d395f8fd83874 /Codemerx/Gestor.Application/ViewModels/Financeiro/CentroDeCustoViewmodel.cs
parent674ca83ba9243a9e95a7568c797668dab6aee26a (diff)
downloadgestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.tar.gz
gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.zip
chore: location
Diffstat (limited to 'Codemerx/Gestor.Application/ViewModels/Financeiro/CentroDeCustoViewmodel.cs')
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Financeiro/CentroDeCustoViewmodel.cs255
1 files changed, 255 insertions, 0 deletions
diff --git a/Codemerx/Gestor.Application/ViewModels/Financeiro/CentroDeCustoViewmodel.cs b/Codemerx/Gestor.Application/ViewModels/Financeiro/CentroDeCustoViewmodel.cs
new file mode 100644
index 0000000..ef57541
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Financeiro/CentroDeCustoViewmodel.cs
@@ -0,0 +1,255 @@
+using Gestor.Application.Servicos.Financeiro;
+using Gestor.Application.Servicos.Generic;
+using Gestor.Application.ViewModels.Generic;
+using Gestor.Common.Validation;
+using Gestor.Model.Domain.Financeiro;
+using Gestor.Model.Domain.Generic;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Diagnostics;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Threading.Tasks;
+
+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 bool Ativo
+ {
+ get
+ {
+ return this._ativo;
+ }
+ set
+ {
+ this._ativo = bool.Parse(value.ToString());
+ base.OnPropertyChanged("Ativo");
+ }
+ }
+
+ public List<Centro> Centros
+ {
+ get;
+ set;
+ }
+
+ public ObservableCollection<Centro> CentrosFiltrados
+ {
+ get
+ {
+ return this._centrosFiltrados;
+ }
+ set
+ {
+ this._centrosFiltrados = value;
+ this.IsExpanded = (value != null ? value.Count > 0 : false);
+ base.OnPropertyChanged("CentrosFiltrados");
+ }
+ }
+
+ public bool IsExpanded
+ {
+ get
+ {
+ return this._isExpanded;
+ }
+ set
+ {
+ this._isExpanded = value;
+ base.OnPropertyChanged("IsExpanded");
+ }
+ }
+
+ public Centro SelectedCentro
+ {
+ get
+ {
+ return this._selectedCentro;
+ }
+ set
+ {
+ this._selectedCentro = value;
+ if (value.get_Id() > (long)0)
+ {
+ this._ultimoId = value.get_Id();
+ }
+ base.VerificarEnables(new long?(value.get_Id()));
+ base.OnPropertyChanged("SelectedCentro");
+ }
+ }
+
+ public CentroDeCustoViewmodel()
+ {
+ this._centroServico = new CentroServico();
+ base.EnableMenu = true;
+ this.Seleciona();
+ }
+
+ public async void CancelarAlteracao()
+ {
+ base.Loading(true);
+ base.Alterar(false);
+ if (this.SelectedCentro.get_Id() > (long)0)
+ {
+ await this.SelecionaCentro();
+ }
+ await this.SelecionaCentro(this.CentrosFiltrados.FirstOrDefault<Centro>((Centro x) => x.get_Id() == this._ultimoId));
+ base.Loading(false);
+ }
+
+ public async Task<List<Centro>> Filtrar(string value)
+ {
+ List<Centro> centros = await Task.Run<List<Centro>>(() => this.FiltrarCentro(value));
+ return centros;
+ }
+
+ public List<Centro> FiltrarCentro(string filter)
+ {
+ this.CentrosFiltrados = (string.IsNullOrWhiteSpace(filter) ? new ObservableCollection<Centro>(this.Centros) : new ObservableCollection<Centro>(
+ from x in this.Centros
+ where ValidationHelper.RemoveDiacritics(x.get_Descricao().Trim()).ToUpper().Contains(ValidationHelper.RemoveDiacritics(filter))
+ orderby this.Ativo descending, x.get_Descricao()
+ select x));
+ return this.CentrosFiltrados.ToList<Centro>();
+ }
+
+ public void Incluir()
+ {
+ long id;
+ Centro selectedCentro = this.SelectedCentro;
+ if (selectedCentro != null)
+ {
+ id = selectedCentro.get_Id();
+ }
+ else
+ {
+ id = (long)0;
+ }
+ this._ultimoId = id;
+ Centro centro = new Centro();
+ centro.set_Ativo(true);
+ this.SelectedCentro = centro;
+ base.Alterar(true);
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Salvar()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs;
+ List<KeyValuePair<string, string>> keyValuePairs1 = this.SelectedCentro.Validate();
+ List<KeyValuePair<string, string>> keyValuePairs2 = keyValuePairs1;
+ keyValuePairs2.AddRange(await this.Validate());
+ keyValuePairs2 = null;
+ if (keyValuePairs1.Count <= 0)
+ {
+ this.SelectedCentro = await this._centroServico.Save(this.SelectedCentro);
+ if (this._centroServico.Sucesso)
+ {
+ await this.SelecionaCentro();
+ await this.SelecionaCentro(this.CentrosFiltrados.First<Centro>((Centro x) => x.get_Id() == this.SelectedCentro.get_Id()));
+ base.Alterar(false);
+ base.ToggleSnackBar("CENTRO DE CUSTO SALVO COM SUCESSO", true);
+ keyValuePairs = null;
+ }
+ else
+ {
+ keyValuePairs = null;
+ }
+ }
+ else
+ {
+ keyValuePairs = keyValuePairs1;
+ }
+ keyValuePairs1 = null;
+ return keyValuePairs;
+ }
+
+ private async void Seleciona()
+ {
+ base.Loading(true);
+ await base.PermissaoTela(29);
+ await this.SelecionaCentro();
+ await this.SelecionaCentro(this.CentrosFiltrados.FirstOrDefault<Centro>());
+ base.Loading(false);
+ }
+
+ private async Task SelecionaCentro(Centro centros)
+ {
+ if (centros != null)
+ {
+ base.Loading(true);
+ List<Centro> centros1 = await (new BaseServico()).BuscarCentroAsync();
+ DomainBase.Copy<Centro, Centro>(this.CentrosFiltrados.First<Centro>((Centro x) => x.get_Id() == centros.get_Id()), centros1.First<Centro>((Centro x) => x.get_Id() == centros.get_Id()));
+ this.SelectedCentro = this.CentrosFiltrados.First<Centro>((Centro x) => x.get_Id() == centros.get_Id());
+ base.Loading(false);
+ }
+ else
+ {
+ base.Alterar(false);
+ base.EnableMenu = false;
+ base.EnableAlterar = false;
+ }
+ }
+
+ private async Task SelecionaCentro()
+ {
+ List<Centro> centros = await (new BaseServico()).BuscarCentroAsync();
+ CentroDeCustoViewmodel list = this;
+ List<Centro> centros1 = centros;
+ IOrderedEnumerable<Centro> ativo =
+ from x in centros1
+ orderby x.get_Ativo() descending
+ select x;
+ IOrderedEnumerable<Centro> centros2 = ativo.ThenBy<Centro, string>((Centro x) => x.get_Descricao());
+ list.Centros = centros2.ThenBy<Centro, string>((Centro x) => x.get_Descricao()).ToList<Centro>();
+ this.CentrosFiltrados = new ObservableCollection<Centro>(this.Centros);
+ }
+
+ public void SelecionaCentroDeCusto(Centro centro)
+ {
+ this.SelectedCentro = this.CentrosFiltrados.First<Centro>((Centro x) => x.get_Id() == centro.get_Id());
+ }
+
+ public async Task<List<KeyValuePair<string, string>>> Validate()
+ {
+ List<KeyValuePair<string, string>> keyValuePairs = new List<KeyValuePair<string, string>>();
+ bool flag = true;
+ List<Centro> centros = await (new BaseServico()).BuscarCentroAsync();
+ if (centros.Count > 0)
+ {
+ centros.ForEach((Centro x) => {
+ if (x.get_Id() == this.SelectedCentro.get_Id())
+ {
+ return;
+ }
+ if (x.get_Descricao() == this.SelectedCentro.get_Descricao() && x.get_IdEmpresa() == this.SelectedCentro.get_IdEmpresa())
+ {
+ flag = false;
+ }
+ });
+ }
+ if (!flag)
+ {
+ keyValuePairs.Add(new KeyValuePair<string, string>("Descricao", "UM CENTRO COM ESSE NOME JÁ EXISTE."));
+ }
+ List<KeyValuePair<string, string>> keyValuePairs1 = keyValuePairs;
+ keyValuePairs = null;
+ return keyValuePairs1;
+ }
+ }
+} \ No newline at end of file