diff options
| author | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 17:17:46 +0000 |
|---|---|---|
| committer | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 17:17:46 +0000 |
| commit | 0440c722a221b8068bbf388c1c0c51f0faff0451 (patch) | |
| tree | 169cbf90c50ff7961db82ecb606c50c2a45a1688 /Gestor.Model/Gestor.Model.Domain.Seguros/Auto.cs | |
| parent | 225aa1499e37faf9d38257caabbadc68d78b427e (diff) | |
| download | gestor-0440c722a221b8068bbf388c1c0c51f0faff0451.tar.gz gestor-0440c722a221b8068bbf388c1c0c51f0faff0451.zip | |
Diffstat (limited to 'Gestor.Model/Gestor.Model.Domain.Seguros/Auto.cs')
| -rw-r--r-- | Gestor.Model/Gestor.Model.Domain.Seguros/Auto.cs | 540 |
1 files changed, 540 insertions, 0 deletions
diff --git a/Gestor.Model/Gestor.Model.Domain.Seguros/Auto.cs b/Gestor.Model/Gestor.Model.Domain.Seguros/Auto.cs new file mode 100644 index 0000000..ca973a4 --- /dev/null +++ b/Gestor.Model/Gestor.Model.Domain.Seguros/Auto.cs @@ -0,0 +1,540 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Globalization; +using System.Text.RegularExpressions; +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 Auto : DomainBase, IDomain +{ + private string _fipe; + + private string _chassi; + + private string _placa; + + private string _modelo; + + private string _anoFabricacao; + + private string _anoModelo; + + private string _renavam; + + private string _capacidade; + + private string _portas; + + private string _observacao; + + private string _regiaoCirculacao; + + private string _ci; + + private string _cepPernoite; + + private Categoria? _categoria; + + private bool _fabricanteBranco = true; + + private bool _chassiInvalido; + + public Item Item { get; set; } + + public Fabricante Fabricante { get; set; } + + public Combustivel? Combustivel { get; set; } + + public string Fipe + { + get + { + if (_fipe == null || !Regex.IsMatch(_fipe, "[0-9]+")) + { + return ""; + } + return _fipe.Trim(); + } + set + { + _fipe = value; + } + } + + public string Modelo + { + get + { + return _modelo?.ToUpper(); + } + set + { + _modelo = value; + } + } + + public Categoria? Categoria + { + get + { + return _categoria; + } + set + { + _categoria = value; + if (value.GetValueOrDefault() == Gestor.Model.Common.Categoria.Motocicleta) + { + Portas = "0"; + } + } + } + + public string Chassi + { + get + { + return _chassi?.ToUpper().Trim(); + } + set + { + _chassi = value; + } + } + + public string Placa + { + get + { + return _placa?.ToUpper().Trim(); + } + set + { + _placa = value; + } + } + + public string AnoFabricacao + { + get + { + return _anoFabricacao?.ToUpper().Trim(); + } + set + { + _anoFabricacao = value; + } + } + + public string AnoModelo + { + get + { + return _anoModelo?.ToUpper().Trim(); + } + set + { + _anoModelo = value; + } + } + + public string Renavam + { + get + { + return _renavam?.ToUpper().Trim(); + } + set + { + _renavam = value; + } + } + + public string Capacidade + { + get + { + return _capacidade?.ToUpper().Trim(); + } + set + { + _capacidade = value; + } + } + + public string Portas + { + get + { + return _portas?.ToUpper().Trim(); + } + set + { + _portas = value; + } + } + + public Cor? Cor { get; set; } + + public string Observacao + { + get + { + return _observacao?.ToUpper(); + } + set + { + _observacao = value; + } + } + + public string RegiaoCirculacao + { + get + { + if (_regiaoCirculacao == null || !Regex.IsMatch(_regiaoCirculacao, "[0-9]+")) + { + return ""; + } + return _regiaoCirculacao.FormataCep().Trim(); + } + set + { + _regiaoCirculacao = value; + } + } + + public UsoVeiculo? UsoVeiculo { get; set; } + + public TipoCobertura? TipoCobertura { get; set; } + + public TabelaReferencia? TabelaReferencia { get; set; } + + public int? Bonus { get; set; } + + public decimal PorcentagemReferencia { get; set; } + + public Correcao? Correcao { get; set; } + + public decimal ValorDeterminado { get; set; } + + public bool? Blindagem { get; set; } + + public string Ci + { + get + { + return _ci?.ToUpper(); + } + set + { + _ci = value; + } + } + + public string CepPernoite + { + get + { + if (_cepPernoite == null || !Regex.IsMatch(_cepPernoite, "[0-9]+")) + { + return string.Empty; + } + return _cepPernoite.FormataCep().Trim(); + } + set + { + _cepPernoite = value; + } + } + + public bool? ZeroKm { get; set; } + + public bool? Financiado { get; set; } + + public bool? Pcd { get; set; } + + public Isencao? Isencao { get; set; } + + public bool Excluido { get; set; } + + public Rastreador Rastreador { get; set; } + + public bool? KitGas { get; set; } + + [JsonIgnore] + public Func<List<KeyValuePair<string, string>>> ValidationEvent => Validate; + + public List<KeyValuePair<string, string>> Validate(bool chassiInvalido, bool fabricanteBranco) + { + _chassiInvalido = chassiInvalido; + _fabricanteBranco = fabricanteBranco; + return Validate(); + } + + public List<KeyValuePair<string, string>> Validate() + { + List<KeyValuePair<string, string>> list = ValidationHelper.AddValue(); + if (string.IsNullOrWhiteSpace(Chassi)) + { + list.AddValue("Chassi", Messages.Obrigatorio); + } + else if (!_chassiInvalido && !Chassi.ValidacaoChassi()) + { + list.AddValue("Chassi", Messages.Invalido); + } + if (!_fabricanteBranco && (Fabricante == null || Fabricante.Id == 0)) + { + list.AddValue("Fabricante", Messages.Obrigatorio); + } + if (string.IsNullOrWhiteSpace(Modelo)) + { + list.AddValue("Modelo", Messages.Obrigatorio); + } + else if (Modelo.Length > 250) + { + list.AddValue("Modelo", string.Format(Messages.MaiorQueLimite, 250)); + } + if (!Categoria.HasValue) + { + list.AddValue("Categoria", Messages.Obrigatorio); + } + if (!Combustivel.HasValue) + { + list.AddValue("Combustivel|COMBUSTÍVEL", Messages.Obrigatorio); + } + if (!ZeroKm.HasValue) + { + list.AddValue("ZeroKm|ZERO KM", Messages.Obrigatorio); + } + if (ZeroKm.HasValue && !ZeroKm.Value && string.IsNullOrWhiteSpace(Placa)) + { + list.AddValue("Placa", Messages.Obrigatorio); + } + else if (ZeroKm.HasValue && !ZeroKm.Value && !Placa.ValidacaoPlaca()) + { + list.AddValue("Placa", Messages.Invalido); + } + if (string.IsNullOrWhiteSpace(AnoFabricacao)) + { + list.AddValue("AnoFabricacao|ANO DE FABRICAÇÃO", Messages.Obrigatorio); + } + else if (!AnoFabricacao.ValidacaoFabricacao()) + { + list.AddValue("AnoFabricacao|ANO DE FABRICAÇÃO", Messages.Invalido); + } + if (string.IsNullOrWhiteSpace(AnoModelo)) + { + list.AddValue("AnoModelo|ANO DO MODELO", Messages.Obrigatorio); + } + else if (!AnoModelo.ValidacaoModelo()) + { + list.AddValue("AnoModelo|ANO DO MODELO", Messages.Invalido); + } + int result; + if (string.IsNullOrWhiteSpace(Portas)) + { + if (Categoria.GetValueOrDefault() == Gestor.Model.Common.Categoria.Motocicleta) + { + Portas = "0"; + } + else + { + list.AddValue("Portas", Messages.Obrigatorio); + } + } + else if (!int.TryParse(Portas, out result)) + { + list.AddValue("Portas", Messages.Invalido); + } + if (string.IsNullOrWhiteSpace(Capacidade)) + { + list.AddValue("Capacidade", Messages.Obrigatorio); + } + else if (!int.TryParse(Capacidade, out result)) + { + list.AddValue("Capacidade", Messages.Invalido); + } + if (!Financiado.HasValue) + { + list.AddValue("Financiado", Messages.Obrigatorio); + } + if (!string.IsNullOrWhiteSpace(Ci) && Ci.Length > 20) + { + list.AddValue("Ci|C.I.", string.Format(Messages.MaiorQueLimite, 20)); + } + if (string.IsNullOrWhiteSpace(Fipe)) + { + list.AddValue("Fipe|CÓDIGO FIPE", Messages.Obrigatorio); + } + else if (!Fipe.ValidaFipe()) + { + list.AddValue("Fipe|CÓDIGO FIPE", Messages.Invalido); + } + if (int.TryParse(Capacidade, out var result2) && result2 > 99) + { + list.AddValue("Capacidade", Messages.Invalido); + } + if (!UsoVeiculo.HasValue) + { + list.AddValue("UsoVeiculo", Messages.Obrigatorio); + } + if (!string.IsNullOrEmpty(Renavam) && Renavam.Replace(".", "").Length > 11) + { + list.AddValue("Renavam", Messages.Invalido); + } + return list; + } + + public static List<TupleList> Log(Item item) + { + List<TupleList> list = new List<TupleList>(); + TupleList tupleList = new TupleList(); + ObservableCollection<Tuple<string, string, string>> obj = new ObservableCollection<Tuple<string, string, string>> + { + new Tuple<string, string, string>("CÓDIGO FIPE", string.IsNullOrWhiteSpace(item.Auto.Fipe) ? "" : item.Auto.Fipe.ToUpper(), ""), + new Tuple<string, string, string>("CHASSI", string.IsNullOrWhiteSpace(item.Auto.Chassi) ? "" : item.Auto.Chassi.ToUpper(), ""), + new Tuple<string, string, string>("PLACA", string.IsNullOrWhiteSpace(item.Auto.Placa) ? "" : item.Auto.Placa.ToUpper(), ""), + new Tuple<string, string, string>("FABRICANTE", (item.Auto.Fabricante == null) ? "" : item.Auto.Fabricante.Descricao.ToUpper(), ""), + new Tuple<string, string, string>("MODELO", string.IsNullOrWhiteSpace(item.Auto.Modelo) ? "" : item.Auto.Modelo.ToUpper(), "") + }; + object item2; + if (item.Auto.UsoVeiculo.HasValue) + { + Auto auto = item.Auto; + if (auto == null) + { + item2 = null; + } + else + { + UsoVeiculo? usoVeiculo = auto.UsoVeiculo; + item2 = (usoVeiculo.HasValue ? usoVeiculo.GetValueOrDefault().GetDescription() : null); + } + } + else + { + item2 = ""; + } + obj.Add(new Tuple<string, string, string>("USO VEICULO", (string)item2, "")); + object item3; + if (item.Auto.Categoria.HasValue) + { + Categoria? categoria = item.Auto.Categoria; + item3 = (categoria.HasValue ? categoria.GetValueOrDefault().GetDescription() : null); + } + else + { + item3 = ""; + } + obj.Add(new Tuple<string, string, string>("CATEGORIA", (string)item3, "")); + object item4; + if (item.Auto.Combustivel.HasValue) + { + Combustivel? combustivel = item.Auto.Combustivel; + item4 = (combustivel.HasValue ? combustivel.GetValueOrDefault().GetDescription() : null); + } + else + { + item4 = ""; + } + obj.Add(new Tuple<string, string, string>("COMBUSTÍVEL", (string)item4, "")); + object item5; + if (item.Auto.Cor.HasValue) + { + Cor? cor = item.Auto.Cor; + item5 = (cor.HasValue ? cor.GetValueOrDefault().GetDescription() : null); + } + else + { + item5 = ""; + } + obj.Add(new Tuple<string, string, string>("COR", (string)item5, "")); + obj.Add(new Tuple<string, string, string>("RENAVAM", string.IsNullOrWhiteSpace(item.Auto.Renavam) ? "" : item.Auto.Renavam.ToUpper(), "")); + obj.Add(new Tuple<string, string, string>("ZERO KM", (!item.Auto.ZeroKm.HasValue) ? "" : (item.Auto.ZeroKm.Value ? "SIM" : "NÃO"), "")); + obj.Add(new Tuple<string, string, string>("ANO DE FABRICAÇÃO", string.IsNullOrWhiteSpace(item.Auto.AnoFabricacao) ? "" : item.Auto.AnoFabricacao.ToUpper(), "")); + obj.Add(new Tuple<string, string, string>("ANO DO MODELO", string.IsNullOrWhiteSpace(item.Auto.AnoModelo) ? "" : item.Auto.AnoModelo.ToUpper(), "")); + obj.Add(new Tuple<string, string, string>("PORTAS", string.IsNullOrWhiteSpace(item.Auto.Portas) ? "" : item.Auto.Portas, "")); + obj.Add(new Tuple<string, string, string>("CAPACIDADE", string.IsNullOrWhiteSpace(item.Auto.Capacidade) ? "" : item.Auto.Capacidade, "")); + obj.Add(new Tuple<string, string, string>("CEP DE CIRCULAÇÃO", string.IsNullOrWhiteSpace(item.Auto.RegiaoCirculacao) ? "" : item.Auto.RegiaoCirculacao.ToUpper(), "")); + obj.Add(new Tuple<string, string, string>("CEP PERNOITE", string.IsNullOrWhiteSpace(item.Auto.CepPernoite) ? "" : item.Auto.CepPernoite.ToUpper(), "")); + object item6; + if (item.Auto.Correcao.HasValue) + { + Correcao? correcao = item.Auto.Correcao; + item6 = (correcao.HasValue ? correcao.GetValueOrDefault().GetDescription() : null); + } + else + { + item6 = ""; + } + obj.Add(new Tuple<string, string, string>("CORREÇÃO", (string)item6, "")); + object item7; + if (item.Auto.TabelaReferencia.HasValue) + { + TabelaReferencia? tabelaReferencia = item.Auto.TabelaReferencia; + item7 = (tabelaReferencia.HasValue ? tabelaReferencia.GetValueOrDefault().GetDescription() : null); + } + else + { + item7 = ""; + } + obj.Add(new Tuple<string, string, string>("REFERÊNCIA", (string)item7, "")); + obj.Add(new Tuple<string, string, string>("PORCENTAGEM DE REFERÊNCIA", item.Auto.PorcentagemReferencia.ToString(new CultureInfo("pt-BR")), "")); + obj.Add(new Tuple<string, string, string>("C.I.", string.IsNullOrWhiteSpace(item.Auto.Ci) ? "" : item.Auto.Ci.ToUpper(), "")); + obj.Add(new Tuple<string, string, string>("FINANCEIRO/ALIENADO", (!item.Auto.Financiado.HasValue) ? "" : (item.Auto.Financiado.Value ? "SIM" : "NÃO"), "")); + obj.Add(new Tuple<string, string, string>("PCD", (!item.Auto.Pcd.HasValue) ? "" : (item.Auto.Pcd.Value ? "SIM" : "NÃO"), "")); + obj.Add(new Tuple<string, string, string>("BLINDAGEM", (!item.Auto.Blindagem.HasValue) ? "" : (item.Auto.Blindagem.Value ? "SIM" : "NÃO"), "")); + object item8; + if (item.Auto.Isencao.HasValue) + { + Isencao? isencao = item.Auto.Isencao; + item8 = (isencao.HasValue ? isencao.GetValueOrDefault().GetDescription() : null); + } + else + { + item8 = ""; + } + obj.Add(new Tuple<string, string, string>("ISENÇÃO", (string)item8, "")); + obj.Add(new Tuple<string, string, string>("BÔNUS", (!item.Auto.Bonus.HasValue) ? "" : item.Auto.Bonus.Value.ToString(), "")); + object item9; + if (item.Auto.TipoCobertura.HasValue) + { + TipoCobertura? tipoCobertura = item.Auto.TipoCobertura; + item9 = (tipoCobertura.HasValue ? tipoCobertura.GetValueOrDefault().GetDescription() : null); + } + else + { + item9 = ""; + } + obj.Add(new Tuple<string, string, string>("TIPO DE COBERTURA", (string)item9, "")); + obj.Add(new Tuple<string, string, string>("KIT GÁS", (!item.Auto.Pcd.HasValue) ? "" : (item.Auto.KitGas.Value ? "SIM" : "NÃO"), "")); + obj.Add(new Tuple<string, string, string>("OBSERVAÇÕES", string.IsNullOrWhiteSpace(item.Auto.Observacao) ? "" : item.Auto.Observacao.ToUpper(), "")); + tupleList.Tuples = obj; + list.Add(tupleList); + List<TupleList> list2 = list; + ObservableCollection<Tuple<string, string, string>> observableCollection = new ObservableCollection<Tuple<string, string, string>> + { + new Tuple<string, string, string>("COBERTURAS$", "", "") + }; + foreach (Cobertura cobertura in item.Coberturas) + { + observableCollection.Add(new Tuple<string, string, string>($" COBERTURA {item.Coberturas.IndexOf(cobertura) + 1}$", "", "")); + observableCollection.Add(new Tuple<string, string, string>(" OBSERVAÇÃO", string.IsNullOrWhiteSpace(cobertura.Observacao) ? "" : cobertura.Observacao.ToUpper(), "")); + observableCollection.Add(new Tuple<string, string, string>(" PRÊMIO", cobertura.Premio.ToString("C", new CultureInfo("pt-BR", useUserOverride: false)), "")); + observableCollection.Add(new Tuple<string, string, string>(" FRANQUIA", cobertura.Franquia.ToString("C", new CultureInfo("pt-BR", useUserOverride: false)), "")); + observableCollection.Add(new Tuple<string, string, string>(" L.M.I.", cobertura.Lmi.ToString("C", new CultureInfo("pt-BR", useUserOverride: false)), "")); + } + list2.Add(new TupleList + { + Tuples = observableCollection + }); + return list2; + } +} |