summaryrefslogtreecommitdiff
path: root/Gestor.Model/Gestor.Model.Domain.Ferramentas/Tarefa.cs
blob: 51bb764aee882d8b111f8014a67a02a4672c2c47 (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
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text.RegularExpressions;
using Gestor.Model.Common;
using Gestor.Model.Domain.Generic;
using Gestor.Model.Domain.Seguros;
using Gestor.Model.Helper;
using Gestor.Model.Resources;
using Gestor.Model.Validation;
using Newtonsoft.Json;

namespace Gestor.Model.Domain.Ferramentas;

public class Tarefa : DomainBase, IDomain
{
	public bool Aberto { get; set; }

	public string Cliente { get; set; }

	public long IdCliente { get; set; }

	public Trilha Trilha { get; set; }

	public Fase Fase { get; set; }

	public TipoDeTarefa TipoDeTarefa { get; set; }

	public TipoTarefa Entidade { get; set; }

	public long IdEntidade { get; set; }

	public Usuario UsuarioCadastro { get; set; }

	public Usuario Usuario { get; set; }

	public List<Usuario> UsuariosVinculados { get; set; }

	public DateTime Agendamento { get; set; }

	public DateTime? Conclusao { get; set; }

	public string Titulo { get; set; }

	public string Anotacoes { get; set; }

	public string AnotacoesInternas { get; set; }

	public string Descricao { get; set; }

	public string DescricaoInterna { get; set; }

	public string Referencia { get; set; }

	public StatusTarefa Status { get; set; }

	public Documento Documento { get; set; }

	public CategoriaTarefa Categoria { get; set; }

	public bool? Restrito { get; set; }

	public List<ResponsavelTarefa> Responsaveis { get; set; }

	public bool HabilitarPublica { get; set; }

	public bool Publica { get; set; }

	public bool AgendamentoRetroativo { 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 (Entidade != TipoTarefa.Notas)
		{
			if (IdEntidade == 0L && Trilha == null)
			{
				list.AddValue("IdEntidade", Messages.Obrigatorio);
			}
			if (!AgendamentoRetroativo && Status != StatusTarefa.Realizado && Agendamento < Funcoes.GetNetworkTime().AddMinutes(-15.0) && Trilha == null)
			{
				list.AddValue("Agendamento", Messages.Invalido);
			}
		}
		if (Usuario == null)
		{
			list.AddValue("Usuario|RESPONSÁVEL", Messages.Obrigatorio);
		}
		if (string.IsNullOrWhiteSpace(Titulo))
		{
			list.AddValue("Titulo|TÍTULO", Messages.Obrigatorio);
		}
		if (DateTime.Compare(Agendamento, new DateTime(1753, 1, 1)) < 0 || DateTime.Compare(Agendamento, new DateTime(9999, 12, 31)) > 0)
		{
			list.AddValue("Agendamento", string.Format(Messages.DataInvalida));
		}
		if (Conclusao.HasValue && (DateTime.Compare(Conclusao.Value, new DateTime(1753, 1, 1)) < 0 || DateTime.Compare(Conclusao.Value, new DateTime(9999, 12, 31)) > 0))
		{
			list.AddValue("Conclusao|CONCLUSÃO", string.Format(Messages.DataInvalida));
		}
		if (Status == StatusTarefa.Realizado && !Conclusao.HasValue)
		{
			list.AddValue("Conclusao|CONCLUSÃO", Messages.Obrigatorio);
		}
		return list;
	}

	public List<TupleList> Log()
	{
		Descricao = new Regex("<title>.*<\\/title>").Replace(Descricao, "").Trim();
		Descricao = new Regex("(<[^>]*>)|(p\\s?{[^}]*})|(\\r)|(\\n)").Replace(Descricao, "").Trim();
		return new List<TupleList>
		{
			new TupleList
			{
				Tuples = new ObservableCollection<Tuple<string, string, string>>
				{
					new Tuple<string, string, string>("TÍTULO", string.IsNullOrWhiteSpace(Titulo) ? "" : Titulo, ""),
					new Tuple<string, string, string>("AGENDAMENTO", Agendamento.ToShortDateString(), ""),
					new Tuple<string, string, string>("HORA", Agendamento.ToShortTimeString(), ""),
					new Tuple<string, string, string>("RESPONSÁVEL", string.IsNullOrWhiteSpace(Usuario.Nome) ? "" : Usuario.Nome, ""),
					new Tuple<string, string, string>("STATUS", Status.GetDescription(), ""),
					new Tuple<string, string, string>("TIPO DE TAREFA", TipoDeTarefa?.Nome, ""),
					new Tuple<string, string, string>("ANOTAÇÕES", string.IsNullOrWhiteSpace(Descricao) ? "" : Descricao, "")
				}
			}
		};
	}
}