summaryrefslogtreecommitdiff
path: root/Gestor.Model/Gestor.Model.Domain.Ferramentas/Credencial.cs
blob: b6ef66d52fbf14d119b5890db7a957e0b9862caa (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
198
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Text.RegularExpressions;
using Gestor.Model.Attributes;
using Gestor.Model.Common;
using Gestor.Model.Domain.Generic;
using Gestor.Model.Domain.Seguros;
using Gestor.Model.Helper;
using Gestor.Model.Resources;
using Newtonsoft.Json;

namespace Gestor.Model.Domain.Ferramentas;

public class Credencial : DomainBase, IDomain
{
	private string _descricao;

	private string _assinatura;

	private string _header;

	private string _cabecalho;

	public long IdEmpresa { get; set; }

	public long IdUsuario { get; set; }

	[Log(true)]
	public string Header
	{
		get
		{
			return _header;
		}
		set
		{
			_header = value;
		}
	}

	[Log(true)]
	[Description("DESCRIÇÃO")]
	public string Descricao
	{
		get
		{
			return _descricao?.ToUpper();
		}
		set
		{
			_descricao = value;
		}
	}

	[Log(true)]
	[Description("PORTA")]
	public int? Porta { get; set; }

	[Log(true)]
	[Description("E-MAIL")]
	public string Email { get; set; }

	[Log(true)]
	[Description("DOMÍNIO")]
	public string Dominio { get; set; }

	[Log(true)]
	[Description("SEGURO")]
	public bool Seguro { get; set; }

	[Log(true)]
	[Description("USUÁRIO")]
	public string Usuario { get; set; }

	[Log(true)]
	[Description("SENHA")]
	public string Senha { get; set; }

	[Log(true)]
	public TipoEmail Tipo { get; set; }

	public string Cabecalho
	{
		get
		{
			return _cabecalho;
		}
		set
		{
			_cabecalho = value ?? "";
		}
	}

	[Log(true)]
	[Description("ASSINATURA")]
	public string Assinatura
	{
		get
		{
			return _assinatura;
		}
		set
		{
			_assinatura = value ?? "";
		}
	}

	public string Replyto { get; set; }

	public bool Excluido { get; set; }

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

	public List<KeyValuePair<string, string>> Validate()
	{
		List<KeyValuePair<string, string>> list = ValidationHelper.AddValue();
		if (string.IsNullOrEmpty(Descricao))
		{
			list.AddValue("Descricao|DESCRIÇÃO", Messages.Obrigatorio);
		}
		else if (Descricao.Length > 50)
		{
			list.AddValue("Descricao|DESCRIÇÃO", string.Format(Messages.MaiorQueLimite, 50));
		}
		if (Tipo == TipoEmail.Outros)
		{
			if (!Porta.HasValue)
			{
				list.AddValue("Porta", Messages.Invalido);
			}
			if (string.IsNullOrWhiteSpace(Dominio))
			{
				list.AddValue("Dominio|DOMÍNIO", Messages.Obrigatorio);
			}
			else if (Dominio.Length > 80)
			{
				list.AddValue("Dominio|DOMÍNIO", string.Format(Messages.MaiorQueLimite, 80));
			}
			if (string.IsNullOrEmpty(Usuario))
			{
				list.AddValue("Usuario|USUÁRIO", Messages.Obrigatorio);
			}
			else if (Usuario.Length > 50)
			{
				list.AddValue("Usuario|USUÁRIO", string.Format(Messages.MaiorQueLimite, 50));
			}
			if (string.IsNullOrEmpty(Senha))
			{
				list.AddValue("Senha", Messages.Obrigatorio);
			}
			else if (Senha.Length > 50)
			{
				list.AddValue("Senha", string.Format(Messages.MaiorQueLimite, 50));
			}
		}
		if (string.IsNullOrWhiteSpace(Email))
		{
			list.AddValue("Email|E-MAIL", Messages.Obrigatorio);
		}
		else if (Email.Length > 80)
		{
			list.AddValue("Email|E-MAIL", string.Format(Messages.MaiorQueLimite, 80));
		}
		else if (!Email.ValidacaoEmail())
		{
			list.AddValue("Email|E-MAIL", Messages.Invalido);
		}
		if (!string.IsNullOrWhiteSpace(Replyto) && !Replyto.ValidacaoEmail())
		{
			list.AddValue("Replyto|RESPONDER PARA", Messages.Obrigatorio);
		}
		return list;
	}

	public List<TupleList> Log()
	{
		List<TupleList> list = new List<TupleList>();
		Assinatura = new Regex("<title>.*<\\/title>").Replace(Assinatura, "").Trim();
		Assinatura = new Regex("(<[^>]*>)|(p\\s?{[^}]*})|(\\r)|(\\n)").Replace(Assinatura, "").Trim();
		list.Add(new TupleList
		{
			Tuples = new ObservableCollection<Tuple<string, string, string>>
			{
				new Tuple<string, string, string>("DESCRIÇÃO", string.IsNullOrWhiteSpace(Descricao) ? "" : Descricao, ""),
				new Tuple<string, string, string>("PORTA", (!Porta.HasValue) ? "" : Porta?.ToString(), ""),
				new Tuple<string, string, string>("DOMÍNIO", string.IsNullOrWhiteSpace(Dominio) ? "" : Dominio, ""),
				new Tuple<string, string, string>("E-MAIL", string.IsNullOrWhiteSpace(Email) ? "" : Email, ""),
				new Tuple<string, string, string>("LOGIN", string.IsNullOrWhiteSpace(Usuario) ? "" : Usuario, ""),
				new Tuple<string, string, string>("CERTIFICADO DE SEGURANÇA", Seguro ? "SIM" : "NÃO", ""),
				new Tuple<string, string, string>("ASSINATURA", string.IsNullOrWhiteSpace(Assinatura) ? "" : Assinatura, "")
			}
		});
		return list;
	}
}