summaryrefslogtreecommitdiff
path: root/Gestor.Model/Gestor.Model.Domain.Seguros/TitularesVida.cs
blob: 6ec26affd8a49967047821d29187f15e5e105be8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Gestor.Model.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 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 bool Selecionado
	{
		get
		{
			return _selecionado;
		}
		set
		{
			if (value != _selecionado)
			{
				_selecionado = value;
				OnPropertyChanged("Selecionado");
			}
		}
	}

	public long IdItem { get; set; }

	public string Codigo
	{
		get
		{
			return _codigo?.ToUpper();
		}
		set
		{
			_codigo = value;
		}
	}

	public DateTime? Inicio { get; set; }

	public DateTime? Fim { get; set; }

	public string Fatura
	{
		get
		{
			return _fatura?.ToUpper();
		}
		set
		{
			_fatura = value;
		}
	}

	public string Nome
	{
		get
		{
			return _nome?.ToUpper();
		}
		set
		{
			_nome = value;
		}
	}

	public string Observacao
	{
		get
		{
			return _observacao?.ToUpper();
		}
		set
		{
			_observacao = value;
		}
	}

	public DateTime? Nascimento { get; set; }

	public string Cpf { get; set; }

	public string Matricula
	{
		get
		{
			return _matricula?.ToUpper();
		}
		set
		{
			_matricula = value;
		}
	}

	public decimal? Premio
	{
		get
		{
			return _premio.GetValueOrDefault();
		}
		set
		{
			_premio = value;
		}
	}

	public decimal? Capital
	{
		get
		{
			return _capital.GetValueOrDefault();
		}
		set
		{
			_capital = value;
		}
	}

	public TipoTitular? Tipo { get; set; }

	public TitularesVida Dependente { get; set; }

	[JsonIgnore]
	public Func<List<KeyValuePair<string, string>>> ValidationEvent => Validate;

	public event PropertyChangedEventHandler PropertyChanged;

	protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
	{
		this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
	}

	public List<KeyValuePair<string, string>> Validate()
	{
		List<KeyValuePair<string, string>> list = ValidationHelper.AddValue();
		if (string.IsNullOrWhiteSpace(Nome))
		{
			list.AddValue("Nome", Messages.Obrigatorio);
		}
		else if (Nome.Length > 150)
		{
			list.AddValue("Nome", string.Format(Messages.MaiorQueLimite, 150));
		}
		if (!Inicio.HasValue)
		{
			list.AddValue("Inicio|INÍCIO", Messages.Obrigatorio);
		}
		else if (DateTime.Compare(Inicio.Value, new DateTime(1753, 1, 1)) < 0 || DateTime.Compare(Inicio.Value, new DateTime(9999, 12, 31)) > 0)
		{
			list.AddValue("Inicio|INÍCIO", string.Format(Messages.DataInvalida));
		}
		if (Fim.HasValue && (DateTime.Compare(Fim.Value, new DateTime(1753, 1, 1)) < 0 || DateTime.Compare(Fim.Value, new DateTime(9999, 12, 31)) > 0))
		{
			list.AddValue("Fim", string.Format(Messages.DataInvalida));
		}
		if (Nascimento.HasValue && (DateTime.Compare(Nascimento.Value, new DateTime(1753, 1, 1)) < 0 || DateTime.Compare(Nascimento.Value, new DateTime(9999, 12, 31)) > 0))
		{
			list.AddValue("Nascimento", string.Format(Messages.DataInvalida));
		}
		if ((!Nascimento.HasValue || Funcoes.GetAge(Nascimento.Value) >= 18) && !string.IsNullOrWhiteSpace(Cpf) && !Cpf.ValidacaoDocumento())
		{
			list.AddValue("Cpf", Messages.Invalido);
		}
		if (!Tipo.HasValue)
		{
			list.AddValue("Tipo", Messages.Obrigatorio);
		}
		if (Tipo.GetValueOrDefault() == TipoTitular.Dependente && Dependente == null)
		{
			list.AddValue("Dependente", "OBRIGATÓRIO. PESQUISE POR UM DOS TITULARES\nQUE SEJA DO TIPO SÓCIO OU FUNCIONÁRIO");
		}
		return list;
	}
}