using Gestor.Model.Common; using Gestor.Model.Domain.Generic; using Gestor.Model.Helper; using Gestor.Model.Resources; using Gestor.Model.Validation; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Globalization; using System.Runtime.CompilerServices; namespace Gestor.Model.Domain.Seguros { public class Aeronautico : DomainBase, IDomain { private string _fabricante; private string _modelo; private string _serie; private string _prefixo; private string _marinaAero; private string _certificado; private string _casco; private string _navegacao; private string _observacao; public string Casco { get { string str = this._casco; if (str != null) { return str.ToUpper(); } return null; } set { this._casco = value; } } public string Certificado { get { string str = this._certificado; if (str != null) { return str.ToUpper(); } return null; } set { this._certificado = value; } } public int? Fabricacao { get; set; } public string Fabricante { get { string str = this._fabricante; if (str != null) { return str.ToUpper(); } return null; } set { this._fabricante = value; } } public Gestor.Model.Domain.Seguros.Item Item { get; set; } public string MarinaAero { get { string str = this._marinaAero; if (str != null) { return str.ToUpper(); } return null; } set { this._marinaAero = value; } } public string Modelo { get { string str = this._modelo; if (str != null) { return str.ToUpper(); } return null; } set { this._modelo = value; } } public string Navegacao { get { string str = this._navegacao; if (str != null) { return str.ToUpper(); } return null; } set { this._navegacao = value; } } public string Observacao { get { string str = this._observacao; if (str != null) { return str.ToUpper(); } return null; } set { this._observacao = value; } } public int? Passageiros { get; set; } public long? Peso { get; set; } public string Prefixo { get { string str = this._prefixo; if (str != null) { return str.ToUpper(); } return null; } set { this._prefixo = value; } } public string Serie { get { string str = this._serie; if (str != null) { return str.ToUpper(); } return null; } set { this._serie = value; } } public TipoAeronautico Tipo { get; set; } public int? Tripulantes { get; set; } [JsonIgnore] public Func>> ValidationEvent { get { Aeronautico aeronautico = this; return new Func>>(aeronautico.Validate); } } public DateTime? Vistoria { get; set; } public Aeronautico() { } public static List Log(Gestor.Model.Domain.Seguros.Item item) { string str; string str1; string str2; string str3; string shortDateString; List tupleLists = new List(); TupleList tupleList = new TupleList(); ObservableCollection> observableCollection = new ObservableCollection>() { new Tuple("TIPO DE AERONAVE", item.Aeronautico.Tipo.GetDescription(), ""), new Tuple("FABRICANTE", (string.IsNullOrWhiteSpace(item.Aeronautico.Fabricante) ? "" : item.Aeronautico.Fabricante.ToUpper()), ""), new Tuple("MODELO", (string.IsNullOrWhiteSpace(item.Aeronautico.Modelo) ? "" : item.Aeronautico.Modelo.ToUpper()), ""), new Tuple("REGISTRO", (string.IsNullOrWhiteSpace(item.Aeronautico.Serie) ? "" : item.Aeronautico.Serie.ToUpper()), ""), new Tuple("PREFIXO", (string.IsNullOrWhiteSpace(item.Aeronautico.Prefixo) ? "" : item.Aeronautico.Prefixo.ToUpper()), "") }; int? fabricacao = item.Aeronautico.Fabricacao; if (!fabricacao.HasValue) { str = ""; } else { fabricacao = item.Aeronautico.Fabricacao; if (fabricacao.HasValue) { str = fabricacao.GetValueOrDefault().ToString(); } else { str = null; } } observableCollection.Add(new Tuple("ANO DE FABRICAÇÃO", str, "")); fabricacao = item.Aeronautico.Tripulantes; if (!fabricacao.HasValue) { str1 = ""; } else { fabricacao = item.Aeronautico.Tripulantes; if (fabricacao.HasValue) { str1 = fabricacao.GetValueOrDefault().ToString(); } else { str1 = null; } } observableCollection.Add(new Tuple("TRIPULANTES", str1, "")); fabricacao = item.Aeronautico.Passageiros; if (!fabricacao.HasValue) { str2 = ""; } else { fabricacao = item.Aeronautico.Passageiros; if (fabricacao.HasValue) { str2 = fabricacao.GetValueOrDefault().ToString(); } else { str2 = null; } } observableCollection.Add(new Tuple("PASSAGEIROS", str2, "")); observableCollection.Add(new Tuple("AERÓDROMO", (string.IsNullOrWhiteSpace(item.Aeronautico.MarinaAero) ? "" : item.Aeronautico.MarinaAero.ToUpper()), "")); long? peso = item.Aeronautico.Peso; if (!peso.HasValue) { str3 = ""; } else { peso = item.Aeronautico.Peso; if (peso.HasValue) { str3 = peso.GetValueOrDefault().ToString(); } else { str3 = null; } } observableCollection.Add(new Tuple("PESO", str3, "")); observableCollection.Add(new Tuple("NAVEGAÇÃO", (string.IsNullOrWhiteSpace(item.Aeronautico.Navegacao) ? "" : item.Aeronautico.Navegacao.ToUpper()), "")); observableCollection.Add(new Tuple("CERTIFICADO", (string.IsNullOrWhiteSpace(item.Aeronautico.Certificado) ? "" : item.Aeronautico.Certificado.ToUpper()), "")); observableCollection.Add(new Tuple("MATERIAL DO CASCO", (string.IsNullOrWhiteSpace(item.Aeronautico.Casco) ? "" : item.Aeronautico.Casco.ToUpper()), "")); DateTime? vistoria = item.Aeronautico.Vistoria; if (!vistoria.HasValue) { shortDateString = ""; } else { vistoria = item.Aeronautico.Vistoria; if (vistoria.HasValue) { shortDateString = vistoria.GetValueOrDefault().ToShortDateString(); } else { shortDateString = null; } } observableCollection.Add(new Tuple("VALIDADE DA VISTORIA", shortDateString, "")); observableCollection.Add(new Tuple("OBSERVAÇÃO", (string.IsNullOrWhiteSpace(item.Aeronautico.Observacao) ? "" : item.Aeronautico.Observacao.ToUpper()), "")); tupleList.Tuples = observableCollection; tupleLists.Add(tupleList); List tupleLists1 = tupleLists; ObservableCollection> observableCollection1 = new ObservableCollection>() { new Tuple("COBERTURAS$", "", "") }; foreach (Cobertura cobertura in item.Coberturas) { observableCollection1.Add(new Tuple(string.Format(" COBERTURA {0}$", item.Coberturas.IndexOf(cobertura) + 1), "", "")); observableCollection1.Add(new Tuple(" OBSERVAÇÃO", (string.IsNullOrWhiteSpace(cobertura.Observacao) ? "" : cobertura.Observacao.ToUpper()), "")); decimal premio = cobertura.Premio; observableCollection1.Add(new Tuple(" PRÊMIO", premio.ToString("C", new CultureInfo("pt-BR", false)), "")); premio = cobertura.Franquia; observableCollection1.Add(new Tuple(" FRANQUIA", premio.ToString("C", new CultureInfo("pt-BR", false)), "")); premio = cobertura.Lmi; observableCollection1.Add(new Tuple(" L.M.I.", premio.ToString("C", new CultureInfo("pt-BR", false)), "")); } tupleLists1.Add(new TupleList() { Tuples = observableCollection1 }); return tupleLists1; } public List> Validate() { List> keyValuePairs = ValidationHelper.AddValue(); if (string.IsNullOrWhiteSpace(this.Fabricante)) { keyValuePairs.AddValue("Fabricante", Messages.Obrigatorio, true); } else if (this.Fabricante != null && this.Fabricante.Length > 60) { keyValuePairs.AddValue("Fabricante", string.Format(Messages.MaiorQueLimite, 60), true); } if ((int)this.Tipo == 0) { keyValuePairs.AddValue("Tipo", Messages.Obrigatorio, true); } if (string.IsNullOrWhiteSpace(this.Modelo)) { keyValuePairs.AddValue("Modelo", Messages.Obrigatorio, true); } else if (this.Modelo.Length > 60) { keyValuePairs.AddValue("Modelo", string.Format(Messages.MaiorQueLimite, 60), true); } if (this.Vistoria.HasValue && (DateTime.Compare(this.Vistoria.Value, new DateTime(1753, 1, 1)) < 0 || DateTime.Compare(this.Vistoria.Value, new DateTime(9999, 12, 31)) > 0)) { keyValuePairs.AddValue("Vistoria", string.Format(Messages.DataInvalida, Array.Empty()), true); } if (string.IsNullOrWhiteSpace(this.Serie)) { keyValuePairs.AddValue("Serie", Messages.Obrigatorio, true); } else if (this.Serie.Length > 30) { keyValuePairs.AddValue("Serie", string.Format(Messages.MaiorQueLimite, 30), true); } if (string.IsNullOrWhiteSpace(this.Prefixo)) { keyValuePairs.AddValue("Prefixo", Messages.Obrigatorio, true); } else if (this.Prefixo.Length > 30) { keyValuePairs.AddValue("Prefixo", string.Format(Messages.MaiorQueLimite, 30), true); } if (!this.Fabricacao.HasValue) { keyValuePairs.AddValue("Fabricacao", Messages.Obrigatorio, true); } else if (!this.Fabricacao.Value.ToString().ValidacaoFabricacao()) { keyValuePairs.AddValue("Fabricacao", Messages.Invalido, true); } if (!this.Tripulantes.HasValue) { keyValuePairs.AddValue("Tripulantes", Messages.Obrigatorio, true); } if (!this.Passageiros.HasValue) { keyValuePairs.AddValue("Passageiros", Messages.Obrigatorio, true); } if (string.IsNullOrWhiteSpace(this.MarinaAero)) { keyValuePairs.AddValue("MarinaAero", Messages.Obrigatorio, true); } else if (this.MarinaAero.Length > 60) { keyValuePairs.AddValue("MarinaAero", string.Format(Messages.MaiorQueLimite, 60), true); } if (!string.IsNullOrWhiteSpace(this.Certificado) && this.Certificado.Length > 60) { keyValuePairs.AddValue("Certificado", string.Format(Messages.MaiorQueLimite, 60), true); } if (string.IsNullOrWhiteSpace(this.Casco) && this.Tipo.Categoria() == "Aero") { keyValuePairs.AddValue("Casco", Messages.Obrigatorio, true); } else if (this.Tipo.Categoria() != "Aero" && this.Casco != null && this.Casco.Length > 60) { keyValuePairs.AddValue("Casco", string.Format(Messages.MaiorQueLimite, 60), true); } if (!string.IsNullOrWhiteSpace(this.Navegacao) && this.Tipo.Categoria() != "Aero" && this.Navegacao.Length > 60) { keyValuePairs.AddValue("Navegacao", string.Format(Messages.MaiorQueLimite, 60), true); } if (!this.Vistoria.HasValue && this.Tipo.Categoria() == "Aero") { keyValuePairs.AddValue("Vistoria", Messages.Obrigatorio, true); } if (!this.Peso.HasValue && this.Tipo.Categoria() == "Aero") { keyValuePairs.AddValue("Peso", Messages.Obrigatorio, true); } return keyValuePairs; } } }