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.ComponentModel; using System.Runtime.CompilerServices; using System.Threading; namespace Gestor.Model.Domain.Seguros { public class TitularesVida : DomainBase, IDomain, INotifyPropertyChanged { private string _codigo; private string _fatura; private string _nome; private string _observacao; private string _matricula; private decimal? _premio; private decimal? _capital; private bool _selecionado; public decimal? Capital { get { return new decimal?(this._capital.GetValueOrDefault()); } set { this._capital = value; } } public string Codigo { get { string str = this._codigo; if (str != null) { return str.ToUpper(); } return null; } set { this._codigo = value; } } public string Cpf { get; set; } public TitularesVida Dependente { get; set; } public string Fatura { get { string str = this._fatura; if (str != null) { return str.ToUpper(); } return null; } set { this._fatura = value; } } public DateTime? Fim { get; set; } public long IdItem { get; set; } public DateTime? Inicio { get; set; } public string Matricula { get { string str = this._matricula; if (str != null) { return str.ToUpper(); } return null; } set { this._matricula = value; } } public DateTime? Nascimento { get; set; } public string Nome { get { string str = this._nome; if (str != null) { return str.ToUpper(); } return null; } set { this._nome = value; } } public string Observacao { get { string str = this._observacao; if (str != null) { return str.ToUpper(); } return null; } set { this._observacao = value; } } public decimal? Premio { get { return new decimal?(this._premio.GetValueOrDefault()); } set { this._premio = value; } } public bool Selecionado { get { return this._selecionado; } set { if (value == this._selecionado) { return; } this._selecionado = value; this.OnPropertyChanged("Selecionado"); } } public TipoTitular? Tipo { get; set; } [JsonIgnore] public Func>> ValidationEvent { get { TitularesVida titularesVida = this; return new Func>>(titularesVida.Validate); } } public TitularesVida() { } 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.IsNullOrWhiteSpace(this.Nome)) { keyValuePairs.AddValue("Nome", Messages.Obrigatorio, true); } else if (this.Nome.Length > 150) { keyValuePairs.AddValue("Nome", string.Format(Messages.MaiorQueLimite, 150), true); } if (!this.Inicio.HasValue) { keyValuePairs.AddValue("Inicio|INÍCIO", Messages.Obrigatorio, true); } else if (DateTime.Compare(this.Inicio.Value, new DateTime(1753, 1, 1)) < 0 || DateTime.Compare(this.Inicio.Value, new DateTime(9999, 12, 31)) > 0) { keyValuePairs.AddValue("Inicio|INÍCIO", string.Format(Messages.DataInvalida, Array.Empty()), true); } if (this.Fim.HasValue && (DateTime.Compare(this.Fim.Value, new DateTime(1753, 1, 1)) < 0 || DateTime.Compare(this.Fim.Value, new DateTime(9999, 12, 31)) > 0)) { keyValuePairs.AddValue("Fim", string.Format(Messages.DataInvalida, Array.Empty()), true); } if (this.Nascimento.HasValue && (DateTime.Compare(this.Nascimento.Value, new DateTime(1753, 1, 1)) < 0 || DateTime.Compare(this.Nascimento.Value, new DateTime(9999, 12, 31)) > 0)) { keyValuePairs.AddValue("Nascimento", string.Format(Messages.DataInvalida, Array.Empty()), true); } if ((!this.Nascimento.HasValue || Funcoes.GetAge(this.Nascimento.Value) >= 18) && !string.IsNullOrWhiteSpace(this.Cpf) && !this.Cpf.ValidacaoDocumento()) { keyValuePairs.AddValue("Cpf", Messages.Invalido, true); } if (!this.Tipo.HasValue) { keyValuePairs.AddValue("Tipo", Messages.Obrigatorio, true); } if (this.Tipo.GetValueOrDefault() == TipoTitular.Dependente && this.Dependente == null) { keyValuePairs.AddValue("Dependente", "OBRIGATÓRIO. PESQUISE POR UM DOS TITULARES\nQUE SEJA DO TIPO SÓCIO OU FUNCIONÁRIO", true); } return keyValuePairs; } public event PropertyChangedEventHandler PropertyChanged; } }