using System; using System.Collections.Generic; using System.Threading.Tasks; using System.Windows; using Gestor.Application.Helpers; using Gestor.Application.Servicos.Seguros; using Gestor.Application.ViewModels.Generic; using Gestor.Model.Common; using Gestor.Model.Domain.Generic; using Gestor.Model.Domain.Seguros; using Gestor.Model.Helper; using Gestor.Model.Resources; namespace Gestor.Application.ViewModels.Seguros; public class PerfilEmpresaViewModel : BaseViewModel { private readonly PerfilEmpresaServico _servico; private readonly Controle _controle; private Visibility _ativaCampos = (Visibility)2; private string _equipamentoSeguranca = ""; private string _equipamentoIncendio = ""; private bool _enableIncluirPerfil; private string _dataConstrucao; public long CancelPerfil; private PerfilEmpresa _selectedPerfilEmpresa = new PerfilEmpresa(); public Visibility AtivaCampos { get { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return _ativaCampos; } set { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) _ativaCampos = value; OnPropertyChanged("AtivaCampos"); } } public string EquipamentoSeguranca { get { return _equipamentoSeguranca; } set { _equipamentoSeguranca = value; OnPropertyChanged("EquipamentoSeguranca"); } } public string EquipamentoIncendio { get { return _equipamentoIncendio; } set { _equipamentoIncendio = value; OnPropertyChanged("EquipamentoIncendio"); } } public bool EnableIncluirPerfil { get { return _enableIncluirPerfil; } set { _enableIncluirPerfil = value; OnPropertyChanged("EnableIncluirPerfil"); } } public string DataConstrucao { get { return _dataConstrucao; } set { _dataConstrucao = value?.Replace(" ", ""); OnPropertyChanged("DataConstrucao"); } } public PerfilEmpresa SelectedPerfilEmpresa { get { return _selectedPerfilEmpresa; } set { _selectedPerfilEmpresa = value; if (value != null && ((DomainBase)value).Id > 0) { CancelPerfil = ((DomainBase)value).Id; } VerificarEnables((value != null) ? new long?(((DomainBase)value).Id) : null); OnPropertyChanged("SelectedPerfilEmpresa"); } } public PerfilEmpresaViewModel(Controle controle) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Expected O, but got Unknown _servico = new PerfilEmpresaServico(); _controle = controle; Seleciona(((DomainBase)controle).Id); } private async void Seleciona(long id) { Loading(isLoading: true); await PermissaoTela((TipoTela)32); await SelecionaPerfil(id); Loading(isLoading: false); } private async Task SelecionaPerfil(long id) { Loading(isLoading: true); SelectedPerfilEmpresa = await _servico.BuscarPerfis(id); if (SelectedPerfilEmpresa != null) { EquipamentoSeguranca = BindingEnumHelper.ConcatenarDescricoesEnum(SelectedPerfilEmpresa.EquipamentoSeguranca); EquipamentoIncendio = BindingEnumHelper.ConcatenarDescricoesEnum(SelectedPerfilEmpresa.EquipamentoIncendio); if (SelectedPerfilEmpresa.AnoConstrucao.HasValue) { DataConstrucao = SelectedPerfilEmpresa.AnoConstrucao.Value.Year.ToString(); } } else { EnableIncluirPerfil = true; EquipamentoSeguranca = ""; EquipamentoIncendio = ""; } Loading(isLoading: false); } public void Incluir() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Expected O, but got Unknown PerfilEmpresa selectedPerfilEmpresa = new PerfilEmpresa { Controle = _controle, Cliente = _controle.Cliente, ExclusivoDeposito = false, DivisaTerrenoBaldio = false, PatrimonioHistorio = false, PossuiTelhado = false, CaixasEletronicos = false, Isopainel = false, ConstrucaoReforma = false }; SelectedPerfilEmpresa = selectedPerfilEmpresa; Alterar(alterar: true); } public async Task>> Salvar() { List> errorMessages = SelectedPerfilEmpresa.Validate(); errorMessages = ValidateCampos(errorMessages); if (errorMessages.Count > 0) { return errorMessages; } if (DataConstrucao != null && DataConstrucao != "") { SelectedPerfilEmpresa.AnoConstrucao = DateTime.Parse("01/01/" + DataConstrucao); } SelectedPerfilEmpresa = await _servico.Save(SelectedPerfilEmpresa); if (!_servico.Sucesso) { return null; } await SelecionaPerfil(((DomainBase)_controle).Id); ToggleSnackBar("PERFIL SALVO COM SUCESSO"); Alterar(alterar: false); return null; } private List> ValidateCampos(List> errorMessages) { if (DataConstrucao == null) { ValidationHelper.AddValue(errorMessages, "ANO DA CONSTRUÇÃO", Messages.DataInvalida, true); } if (!int.TryParse(DataConstrucao, out var _)) { ValidationHelper.AddValue(errorMessages, "ANO DA CONSTRUÇÃO", Messages.DataInvalida, true); } if (DataConstrucao != null && int.TryParse(DataConstrucao, out var _) && (int.Parse(DataConstrucao) <= 1755 || int.Parse(DataConstrucao) >= 9999)) { ValidationHelper.AddValue(errorMessages, "ANO DA CONSTRUÇÃO", Messages.DataInvalida, true); } return errorMessages; } public void CancelarAlteracao() { Loading(isLoading: true); Alterar(alterar: false); Loading(isLoading: false); } public async Task Excluir() { if (SelectedPerfilEmpresa != null && ((DomainBase)SelectedPerfilEmpresa).Id != 0L && await ShowMessage("DESEJA EXCLUIR?", "SIM", "NÃO")) { Loading(isLoading: true); if (!(await _servico.Delete(SelectedPerfilEmpresa))) { Loading(isLoading: false); return; } await SelecionaPerfil(((DomainBase)_controle).Id); Loading(isLoading: false); EnableIncluirPerfil = true; AtivaCampos = (Visibility)2; DataConstrucao = null; ToggleSnackBar("PERFIL EXCLUÍDO COM SUCESSO"); } } }