summaryrefslogtreecommitdiff
path: root/Gestor.Model/Gestor.Model.Domain.Seguros/ClienteEndereco.cs
blob: c2086beea36a7cdcf7721b4e25dace6a0a2df659 (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
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<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(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;
	}
}