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.Runtime.CompilerServices; namespace Gestor.Model.Domain.Seguros { public class Repasse : DomainBase, IDomain { private string _incidenciaVendedor = ""; private string _pgtoVendedor = ""; public bool Ativo { get; set; } public BaseRepasse? Base { get; set; } public FormaRepasse? Forma { get; set; } public TipoIncidencia? Incidencia { get; set; } public string IncidenciaVendedor { get { string description = this.Incidencia.GetDescription(); string str = description; this._incidenciaVendedor = description; return str; } } public string PagtoVendedor { get { string description = this.Forma.GetDescription(); string str = description; this._pgtoVendedor = description; return str; } } public Gestor.Model.Domain.Seguros.Ramo Ramo { get; set; } public long? Seguradora { get; set; } public TipoRepasse? Tipo { get; set; } [JsonIgnore] public Func>> ValidationEvent { get { Repasse repasse = this; return new Func>>(repasse.Validate); } } public decimal ValorNovo { get; set; } public decimal ValorRenovacao { get; set; } public Gestor.Model.Domain.Seguros.Vendedor Vendedor { get; set; } public List Vinculo { get; set; } public Repasse() { } public List Log() { return new List() { new TupleList() { Tuples = new ObservableCollection>() { new Tuple("TIPO", this.Tipo.GetDescription(), ""), new Tuple("VALOR NOVO", string.Format("{0:##.00}", this.ValorNovo), ""), new Tuple("VALOR RENOVAÇÃO", string.Format("{0:##.00}", this.ValorRenovacao), ""), new Tuple("INCIDÊNCIA", this.Incidencia.GetDescription(), ""), new Tuple("FORMA PAGAMENTO", this.Forma.GetDescription(), ""), new Tuple("BASE PAGAMENTO", this.Base.GetDescription(), ""), new Tuple("ATIVO", (this.Ativo ? "SIM" : "NÃO"), "") } } }; } public List> Validate() { List> keyValuePairs = ValidationHelper.AddValue(); if (this.Vendedor == null) { keyValuePairs.AddValue("Vendedor", Messages.Obrigatorio, true); } if (TipoRepasse.CoCorretagem != this.Tipo.GetValueOrDefault() && this.ValorNovo == decimal.Zero) { keyValuePairs.AddValue("ValorNovo", Messages.Obrigatorio, true); } if (TipoRepasse.CoCorretagem != this.Tipo.GetValueOrDefault() && this.ValorRenovacao == decimal.Zero) { keyValuePairs.AddValue("ValorRenovacao", Messages.Obrigatorio, true); } if (!this.Tipo.HasValue) { keyValuePairs.AddValue("Tipo", Messages.Obrigatorio, true); } if (!this.Incidencia.HasValue && this.Forma.HasValue && this.Forma.GetValueOrDefault() == FormaRepasse.Recebimento) { keyValuePairs.AddValue("Incidencia", Messages.Obrigatorio, true); } if (!this.Forma.HasValue) { keyValuePairs.AddValue("Forma", Messages.Obrigatorio, true); } if (this.Forma.HasValue && this.Forma.GetValueOrDefault() != FormaRepasse.Recebimento) { if (!this.Base.HasValue) { keyValuePairs.AddValue("Base", Messages.Obrigatorio, true); } if (this.Forma.GetValueOrDefault() == FormaRepasse.Prazo && this.Base.GetValueOrDefault() != BaseRepasse.Vencimento) { keyValuePairs.AddValue("Base", Messages.Invalido, true); } } if (this.Forma.HasValue && this.Forma.GetValueOrDefault() == FormaRepasse.Recebimento && this.Base.HasValue) { keyValuePairs.AddValue("Base", Messages.Invalido, true); } return keyValuePairs; } } }