using System; using System.Collections.Generic; using System.ComponentModel; using System.Runtime.CompilerServices; using Gestor.Model.Attributes; using Gestor.Model.Domain.Generic; using Gestor.Model.Helper; using Gestor.Model.Resources; using Newtonsoft.Json; namespace Gestor.Model.Domain.Seguros; public class ClienteEndereco : EnderecoBase, IDomain, INotifyPropertyChanged { private bool _selecionado; private string _observacao; public bool Selecionado { get { return _selecionado; } set { if (value != _selecionado) { _selecionado = value; OnPropertyChanged("Selecionado"); } } } [Log(true)] public string Observacao { get { return _observacao?.ToUpper(); } set { _observacao = value; } } public Cliente Cliente { get; set; } public int? Ordem { 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.IsNullOrWhiteSpace(base.Cep)) { list.AddValue("Cep", Messages.Obrigatorio); } else if (!base.Cep.ValidacaoCep()) { list.AddValue("Cep", Messages.Invalido); } if (string.IsNullOrWhiteSpace(base.Endereco)) { list.AddValue("Endereco", Messages.Obrigatorio); } else if (base.Endereco.Length > 150) { list.AddValue("Endereco", string.Format(Messages.MaiorQueLimite, 150)); } if (string.IsNullOrWhiteSpace(base.Numero)) { list.AddValue("Numero", Messages.Obrigatorio); } else if (base.Numero.Length > 6) { list.AddValue("Numero", string.Format(Messages.MaiorQueLimite, 6)); } if (!string.IsNullOrWhiteSpace(base.Complemento) && base.Complemento.Length > 45) { list.AddValue("Complemento", string.Format(Messages.MaiorQueLimite, 45)); } if (string.IsNullOrWhiteSpace(base.Bairro)) { list.AddValue("Bairro", Messages.Obrigatorio); } else if (base.Bairro.Length > 100) { list.AddValue("Bairro", string.Format(Messages.MaiorQueLimite, 100)); } if (string.IsNullOrWhiteSpace(base.Cidade)) { list.AddValue("Cidade", Messages.Obrigatorio); } else if (base.Cidade.Length > 50) { list.AddValue("Cidade", string.Format(Messages.MaiorQueLimite, 50)); } if (string.IsNullOrWhiteSpace(base.Estado)) { list.AddValue("Estado", Messages.Obrigatorio); } else if (!base.Estado.ValidacaoEstado()) { list.AddValue("Estado", Messages.Invalido); } if (!string.IsNullOrWhiteSpace(Observacao) && Observacao.Length > 255) { list.AddValue("Observacao", string.Format(Messages.MaiorQueLimite, 255)); } return list; } }