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/Seguros/PerfilEmpresaViewModel.cs | 274 +++++++++++++++++++++ 1 file changed, 274 insertions(+) create mode 100644 Gestor.Application/ViewModels/Seguros/PerfilEmpresaViewModel.cs (limited to 'Gestor.Application/ViewModels/Seguros/PerfilEmpresaViewModel.cs') diff --git a/Gestor.Application/ViewModels/Seguros/PerfilEmpresaViewModel.cs b/Gestor.Application/ViewModels/Seguros/PerfilEmpresaViewModel.cs new file mode 100644 index 0000000..0c116ab --- /dev/null +++ b/Gestor.Application/ViewModels/Seguros/PerfilEmpresaViewModel.cs @@ -0,0 +1,274 @@ +using Gestor.Application.Helpers; +using Gestor.Application.Servicos.Generic; +using Gestor.Application.Servicos.Seguros; +using Gestor.Application.ViewModels.Generic; +using Gestor.Model.Domain.Generic; +using Gestor.Model.Domain.Seguros; +using Gestor.Model.Helper; +using Gestor.Model.Resources; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; +using System.Windows; + +namespace Gestor.Application.ViewModels.Seguros +{ + public class PerfilEmpresaViewModel : BaseViewModel + { + private readonly PerfilEmpresaServico _servico; + + private readonly Controle _controle; + + private Visibility _ativaCampos = Visibility.Collapsed; + + private string _equipamentoSeguranca = ""; + + private string _equipamentoIncendio = ""; + + private bool _enableIncluirPerfil; + + private string _dataConstrucao; + + public long CancelPerfil; + + private PerfilEmpresa _selectedPerfilEmpresa = new PerfilEmpresa(); + + public Visibility AtivaCampos + { + get + { + return this._ativaCampos; + } + set + { + this._ativaCampos = value; + base.OnPropertyChanged("AtivaCampos"); + } + } + + public string DataConstrucao + { + get + { + return this._dataConstrucao; + } + set + { + string str; + if (value != null) + { + str = value.Replace(" ", ""); + } + else + { + str = null; + } + this._dataConstrucao = str; + base.OnPropertyChanged("DataConstrucao"); + } + } + + public bool EnableIncluirPerfil + { + get + { + return this._enableIncluirPerfil; + } + set + { + this._enableIncluirPerfil = value; + base.OnPropertyChanged("EnableIncluirPerfil"); + } + } + + public string EquipamentoIncendio + { + get + { + return this._equipamentoIncendio; + } + set + { + this._equipamentoIncendio = value; + base.OnPropertyChanged("EquipamentoIncendio"); + } + } + + public string EquipamentoSeguranca + { + get + { + return this._equipamentoSeguranca; + } + set + { + this._equipamentoSeguranca = value; + base.OnPropertyChanged("EquipamentoSeguranca"); + } + } + + public PerfilEmpresa SelectedPerfilEmpresa + { + get + { + return this._selectedPerfilEmpresa; + } + set + { + long? nullable; + this._selectedPerfilEmpresa = value; + if (value != null && value.get_Id() > (long)0) + { + this.CancelPerfil = value.get_Id(); + } + if (value != null) + { + nullable = new long?(value.get_Id()); + } + else + { + nullable = null; + } + base.VerificarEnables(nullable); + base.OnPropertyChanged("SelectedPerfilEmpresa"); + } + } + + public PerfilEmpresaViewModel(Controle controle) + { + this._servico = new PerfilEmpresaServico(); + this._controle = controle; + this.Seleciona(controle.get_Id()); + } + + public void CancelarAlteracao() + { + base.Loading(true); + base.Alterar(false); + base.Loading(false); + } + + public async Task Excluir() + { + if (this.SelectedPerfilEmpresa != null && this.SelectedPerfilEmpresa.get_Id() != 0) + { + if (await base.ShowMessage("DESEJA EXCLUIR?", "SIM", "NÃO", false)) + { + base.Loading(true); + if (await this._servico.Delete(this.SelectedPerfilEmpresa)) + { + await this.SelecionaPerfil(this._controle.get_Id()); + base.Loading(false); + this.EnableIncluirPerfil = true; + this.AtivaCampos = Visibility.Collapsed; + this.DataConstrucao = null; + base.ToggleSnackBar("PERFIL EXCLUÍDO COM SUCESSO", true); + } + else + { + base.Loading(false); + } + } + } + } + + public void Incluir() + { + PerfilEmpresa perfilEmpresa = new PerfilEmpresa(); + perfilEmpresa.set_Controle(this._controle); + perfilEmpresa.set_Cliente(this._controle.get_Cliente()); + perfilEmpresa.set_ExclusivoDeposito(new bool?(false)); + perfilEmpresa.set_DivisaTerrenoBaldio(new bool?(false)); + perfilEmpresa.set_PatrimonioHistorio(new bool?(false)); + perfilEmpresa.set_PossuiTelhado(new bool?(false)); + perfilEmpresa.set_CaixasEletronicos(new bool?(false)); + perfilEmpresa.set_Isopainel(new bool?(false)); + perfilEmpresa.set_ConstrucaoReforma(new bool?(false)); + this.SelectedPerfilEmpresa = perfilEmpresa; + base.Alterar(true); + } + + public async Task>> Salvar() + { + List> keyValuePairs; + List> keyValuePairs1 = this.SelectedPerfilEmpresa.Validate(); + keyValuePairs1 = this.ValidateCampos(keyValuePairs1); + if (keyValuePairs1.Count <= 0) + { + if (this.DataConstrucao != null && this.DataConstrucao != "") + { + this.SelectedPerfilEmpresa.set_AnoConstrucao(new DateTime?(DateTime.Parse(string.Concat("01/01/", this.DataConstrucao)))); + } + this.SelectedPerfilEmpresa = await this._servico.Save(this.SelectedPerfilEmpresa); + if (this._servico.Sucesso) + { + await this.SelecionaPerfil(this._controle.get_Id()); + base.ToggleSnackBar("PERFIL SALVO COM SUCESSO", true); + base.Alterar(false); + keyValuePairs = null; + } + else + { + keyValuePairs = null; + } + } + else + { + keyValuePairs = keyValuePairs1; + } + return keyValuePairs; + } + + private async void Seleciona(long id) + { + base.Loading(true); + await base.PermissaoTela(32); + await this.SelecionaPerfil(id); + base.Loading(false); + } + + private async Task SelecionaPerfil(long id) + { + base.Loading(true); + this.SelectedPerfilEmpresa = await this._servico.BuscarPerfis(id); + if (this.SelectedPerfilEmpresa == null) + { + this.EnableIncluirPerfil = true; + this.EquipamentoSeguranca = ""; + this.EquipamentoIncendio = ""; + } + else + { + this.EquipamentoSeguranca = BindingEnumHelper.ConcatenarDescricoesEnum(this.SelectedPerfilEmpresa.get_EquipamentoSeguranca()); + this.EquipamentoIncendio = BindingEnumHelper.ConcatenarDescricoesEnum(this.SelectedPerfilEmpresa.get_EquipamentoIncendio()); + if (this.SelectedPerfilEmpresa.get_AnoConstrucao().HasValue) + { + DateTime? anoConstrucao = this.SelectedPerfilEmpresa.get_AnoConstrucao(); + this.DataConstrucao = anoConstrucao.Value.Year.ToString(); + } + } + base.Loading(false); + } + + private List> ValidateCampos(List> errorMessages) + { + int num; + int num1; + if (this.DataConstrucao == null) + { + ValidationHelper.AddValue(errorMessages, "ANO DA CONSTRUÇÃO", Messages.get_DataInvalida(), true); + } + if (!int.TryParse(this.DataConstrucao, out num)) + { + ValidationHelper.AddValue(errorMessages, "ANO DA CONSTRUÇÃO", Messages.get_DataInvalida(), true); + } + if (this.DataConstrucao != null && int.TryParse(this.DataConstrucao, out num1) && (int.Parse(this.DataConstrucao) <= 1755 || int.Parse(this.DataConstrucao) >= 9999)) + { + ValidationHelper.AddValue(errorMessages, "ANO DA CONSTRUÇÃO", Messages.get_DataInvalida(), true); + } + return errorMessages; + } + } +} \ No newline at end of file -- cgit v1.2.3