using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Globalization; using System.Runtime.CompilerServices; using Gestor.Model.Attributes; using Gestor.Model.Common; using Gestor.Model.Domain.Common; using Gestor.Model.Domain.Generic; using Gestor.Model.Helper; using Gestor.Model.Resources; using Gestor.Model.Validation; using Newtonsoft.Json; namespace Gestor.Model.Domain.Seguros; public class Vendedor : EnderecoBase, IDomain, INotifyPropertyChanged { private bool _selecionado; private string _nome; private string _documento; private string _conta; private string _agencia; private string _observacao; private string _titularConta; private string _documentoTitular; public bool Selecionado { get { return _selecionado; } set { if (value != _selecionado) { _selecionado = value; OnPropertyChanged("Selecionado"); } } } public Controle Controle { get; set; } public long IdEmpresa { get; set; } [Log(true)] [Name(true)] public string Nome { get { return _nome?.ToUpper(); } set { _nome = value; } } public TipoIncidenciaDesconto TipoIncidenciaDesconto { get; set; } public decimal? Desconto { get; set; } public string Documento { get { return _documento?.ToUpper().Trim(); } set { _documento = value; } } public string TitularConta { get { return _titularConta?.ToUpper(); } set { _titularConta = value; } } public string TitularDocumento { get { return _documentoTitular?.ToUpper().Trim(); } set { _documentoTitular = value; } } public Banco Banco { get; set; } public TipoConta TipoConta { get; set; } public string Conta { get { return _conta?.ToUpper().Trim(); } set { _conta = value; } } public string Agencia { get { return _agencia?.ToUpper().Trim(); } set { _agencia = value; } } public bool Corretora { get; set; } public bool Ativo { get; set; } public string Observacao { get { return _observacao?.ToUpper(); } set { _observacao = value; } } public List Telefones { get; set; } [JsonIgnore] public Func>> ValidationEvent => Validate; public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } public List> Validate() { List> list = ValidationHelper.AddValue(); if (string.IsNullOrEmpty(Nome)) { list.AddValue("Nome", Messages.Obrigatorio); } if (!string.IsNullOrWhiteSpace(Documento) && !Documento.ValidacaoDocumento()) { list.AddValue("Documento", Messages.Invalido); } if (!string.IsNullOrWhiteSpace(TitularDocumento) && !TitularDocumento.ValidacaoDocumento()) { list.AddValue("TitularDocumento", Messages.Invalido); } if (Telefones == null) { return list; } foreach (VendedorTelefone telefone in Telefones) { list.AddRange(telefone.Validate()); } return list; } public List Log() { List list = new List { new TupleList { Tuples = new ObservableCollection> { new Tuple("NOME", string.IsNullOrWhiteSpace(Nome) ? "" : Nome, ""), new Tuple("CPF", string.IsNullOrWhiteSpace(Documento) ? "" : Documento, ""), new Tuple("ATIVO", Ativo ? "SIM" : "NÃO", ""), new Tuple("BANCO", (Banco == null) ? "" : Banco.Nome, ""), new Tuple("AGÊNCIA", string.IsNullOrWhiteSpace(Agencia) ? "" : Agencia, ""), new Tuple("CONTA CORRENTE/POUPANÇA", string.IsNullOrWhiteSpace(Conta) ? "" : Conta, ""), new Tuple("TITULAR DA CONTA", string.IsNullOrWhiteSpace(TitularConta) ? "" : TitularConta, ""), new Tuple("DOCUMENTO TITULAR DA CONTA", string.IsNullOrWhiteSpace(TitularDocumento) ? "" : TitularDocumento, ""), new Tuple("TIPO CONTA", string.IsNullOrWhiteSpace(TipoConta.GetDescription()) ? "" : TipoConta.GetDescription(), ""), new Tuple("DESCONTO", (!Desconto.HasValue) ? "" : (Desconto / (decimal?)100)?.ToString("P", new CultureInfo("pt-BR", useUserOverride: false)), "") } } }; ObservableCollection> observableCollection = new ObservableCollection> { new Tuple("CONTATOS$", "", "") }; if (Telefones != null && Telefones.Count != 0) { foreach (VendedorTelefone telefone in Telefones) { observableCollection.Add(new Tuple($" CONTATO {Telefones.IndexOf(telefone) + 1}$", "", "")); observableCollection.Add(new Tuple(" NOME", string.IsNullOrWhiteSpace(telefone.Nome) ? "" : telefone.Nome, "")); object item; if (telefone.Tipo.HasValue) { TipoTelefone? tipo = telefone.Tipo; item = (tipo.HasValue ? tipo.GetValueOrDefault().GetDescription() : null); } else { item = ""; } observableCollection.Add(new Tuple(" TIPO DE TELEFONE", (string)item, "")); observableCollection.Add(new Tuple(" PREFIXO", string.IsNullOrWhiteSpace(telefone.Prefixo) ? "" : telefone.Prefixo, "")); observableCollection.Add(new Tuple(" NÚMERO DE TELEFONE", string.IsNullOrWhiteSpace(telefone.Numero) ? "" : telefone.Numero, "")); observableCollection.Add(new Tuple(" E-MAIL", string.IsNullOrWhiteSpace(telefone.Email) ? "" : telefone.Email, "")); } list.Add(new TupleList { Tuples = observableCollection }); } return list; } }