using Gestor.Model.Attributes; using Gestor.Model.Common; using Gestor.Model.Domain.Generic; using Gestor.Model.Helper; using Gestor.Model.Resources; using Gestor.Model.Validation; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Threading; namespace Gestor.Model.Domain.Seguros { public class Estipulante : EnderecoBase, IDomain, INotifyPropertyChanged { private bool _selecionado; private string _nome; private string _documento; private string _primeiroPrefixo; private string _primeiroTelefone; private string _segundoPrefixo; private string _segundoTelefone; private string _email; private string _observacao; [Log(true)] public bool Ativo { get; set; } [Log(true)] public string Documento { get { string str = this._documento; if (str == null) { return null; } return str.ToUpper().Trim(); } set { this._documento = value; } } [Log(true)] public string Email { get { string str = this._email; if (str == null) { return null; } return str.ToLower().Trim(); } set { this._email = value; } } public long IdEmpresa { get; set; } [Log(true)] [Name(true)] public string Nome { get { string str = this._nome; if (str != null) { return str.ToUpper(); } return null; } set { this._nome = value; } } [Log(true)] public string Observacao { get { string str = this._observacao; if (str != null) { return str.ToUpper(); } return null; } set { this._observacao = value; } } [Description("PREFIXO")] [Log(true)] public string PrimeiroPrefixo { get { string str = this._primeiroPrefixo; if (str == null) { return null; } return str.ToUpper().Trim(); } set { this._primeiroPrefixo = value; } } [Description("TELEFONE")] [Log(true)] public string PrimeiroTelefone { get { string str = this._primeiroTelefone; if (str == null) { return null; } return str.ToUpper().Trim(); } set { this._primeiroTelefone = value; } } [Description("TIPO TELEFONE")] [Log(true)] public TipoTelefone? PrimeiroTipo { get; set; } [Description("PREFIXO")] [Log(true)] public string SegundoPrefixo { get { string str = this._segundoPrefixo; if (str == null) { return null; } return str.ToUpper().Trim(); } set { this._segundoPrefixo = value; } } [Description("TELEFONE")] [Log(true)] public string SegundoTelefone { get { string str = this._segundoTelefone; if (str == null) { return null; } return str.ToUpper().Trim(); } set { this._segundoTelefone = value; } } [Description("TIPO TELEFONE")] [Log(true)] public TipoTelefone? SegundoTipo { get; set; } public bool Selecionado { get { return this._selecionado; } set { if (value == this._selecionado) { return; } this._selecionado = value; this.OnPropertyChanged("Selecionado"); } } [JsonIgnore] public Func>> ValidationEvent { get { Estipulante estipulante = this; return new Func>>(estipulante.Validate); } } public Estipulante() { } public List Log() { string description; string str; List tupleLists = new List(); TupleList tupleList = new TupleList(); ObservableCollection> observableCollection = new ObservableCollection>() { new Tuple("NOME", (string.IsNullOrWhiteSpace(this.Nome) ? "" : this.Nome), ""), new Tuple("CPF", (string.IsNullOrWhiteSpace(this.Documento) ? "" : this.Documento), ""), new Tuple("ATIVO", (this.Ativo ? "SIM" : "NÃO"), "") }; TipoTelefone? primeiroTipo = this.PrimeiroTipo; if (!primeiroTipo.HasValue) { description = ""; } else { primeiroTipo = this.PrimeiroTipo; if (primeiroTipo.HasValue) { description = primeiroTipo.GetValueOrDefault().GetDescription(); } else { description = null; } } observableCollection.Add(new Tuple("PRIMEIRO TIPO", description, "")); observableCollection.Add(new Tuple("PRIMEIRO PREFIXO", (string.IsNullOrWhiteSpace(this.PrimeiroPrefixo) ? "" : this.PrimeiroPrefixo), "")); observableCollection.Add(new Tuple("PRIMEIRO TELEFONE", (string.IsNullOrWhiteSpace(this.PrimeiroTelefone) ? "" : this.PrimeiroTelefone), "")); primeiroTipo = this.SegundoTipo; if (!primeiroTipo.HasValue) { str = ""; } else { primeiroTipo = this.SegundoTipo; if (primeiroTipo.HasValue) { str = primeiroTipo.GetValueOrDefault().GetDescription(); } else { str = null; } } observableCollection.Add(new Tuple("SEGUNDO TIPO", str, "")); observableCollection.Add(new Tuple("SEGUNDO PREFIXO", (string.IsNullOrWhiteSpace(this.SegundoPrefixo) ? "" : this.SegundoPrefixo), "")); observableCollection.Add(new Tuple("SEGUNDO TELEFONE", (string.IsNullOrWhiteSpace(this.SegundoTelefone) ? "" : this.SegundoTelefone), "")); observableCollection.Add(new Tuple("E-MAIL", (string.IsNullOrWhiteSpace(this.Email) ? "" : this.Email), "")); observableCollection.Add(new Tuple("CEP", (string.IsNullOrWhiteSpace(base.Cep) ? "" : base.Cep), "")); observableCollection.Add(new Tuple("ENDEREÇO", (string.IsNullOrWhiteSpace(base.Endereco) ? "" : base.Endereco), "")); observableCollection.Add(new Tuple("NÚMERO", (string.IsNullOrWhiteSpace(base.Numero) ? "" : base.Numero), "")); observableCollection.Add(new Tuple("COMPLEMENTO", (string.IsNullOrWhiteSpace(base.Complemento) ? "" : base.Complemento), "")); observableCollection.Add(new Tuple("BAIRRO", (string.IsNullOrWhiteSpace(base.Bairro) ? "" : base.Bairro), "")); observableCollection.Add(new Tuple("CIDADE", (string.IsNullOrWhiteSpace(base.Cidade) ? "" : base.Cidade), "")); observableCollection.Add(new Tuple("ESTADO", (string.IsNullOrWhiteSpace(base.Estado) ? "" : base.Estado), "")); tupleList.Tuples = observableCollection; tupleLists.Add(tupleList); return tupleLists; } protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChangedEventHandler propertyChangedEventHandler = this.PropertyChanged; if (propertyChangedEventHandler == null) { return; } propertyChangedEventHandler(this, new PropertyChangedEventArgs(propertyName)); } public List> Validate() { List> keyValuePairs = ValidationHelper.AddValue(); if (string.IsNullOrEmpty(this.Nome)) { keyValuePairs.AddValue("Nome", Messages.Obrigatorio, true); } else if (this.Nome.Length > 100) { keyValuePairs.AddValue("Nome", string.Format(Messages.MaiorQueLimite, 100), true); } if (!string.IsNullOrEmpty(this.Documento) && !this.Documento.ValidacaoDocumento()) { keyValuePairs.AddValue("Documento", Messages.Invalido, true); } if (!string.IsNullOrWhiteSpace(this.PrimeiroPrefixo) && !this.PrimeiroPrefixo.ValidacaoPrefixo()) { keyValuePairs.AddValue("PrimeiroPrefixo|PRIMEIRO DDD", Messages.Invalido, true); } if (!string.IsNullOrWhiteSpace(this.PrimeiroTelefone) && !this.PrimeiroTelefone.ValidacaoTelefone()) { keyValuePairs.AddValue("PrimeiroTelefone|PRIMEIRO TELEFONE", Messages.Invalido, true); } if (!string.IsNullOrWhiteSpace(this.SegundoPrefixo) && !this.SegundoPrefixo.ValidacaoPrefixo()) { keyValuePairs.AddValue("SegundoPrefixo|SEGUNDO DDD", Messages.Invalido, true); } if (!string.IsNullOrWhiteSpace(this.SegundoTelefone) && !this.SegundoTelefone.ValidacaoTelefone()) { keyValuePairs.AddValue("SegundoTelefone|SEGUNDO TELEFONE", Messages.Invalido, true); } if (!string.IsNullOrEmpty(this.Email) && this.Email.Length > 100) { keyValuePairs.AddValue("Email|E-MAIL", string.Format(Messages.MaiorQueLimite, 100), true); } if (!string.IsNullOrEmpty(this.Email) && !this.Email.ValidacaoEmail()) { keyValuePairs.AddValue("Email|E-MAIL", Messages.Invalido, true); } if (!string.IsNullOrEmpty(base.Cep) && !base.Cep.ValidacaoCep()) { keyValuePairs.AddValue("Cep|CEP", Messages.Invalido, true); } if (!string.IsNullOrEmpty(base.Estado) && !base.Estado.ValidacaoEstado()) { keyValuePairs.AddValue("Estado|ESTADO", Messages.Invalido, true); } return keyValuePairs; } public event PropertyChangedEventHandler PropertyChanged; } }