Skip to content

Instantly share code, notes, and snippets.

@Renancp01 Renancp01/Fatura.cs Secret
Created Mar 22, 2018

Embed
What would you like to do?
public class Fatura
{
public Fatura()
{
FaturaId = Guid.NewGuid();
Cobrancas = new List<Cobranca>();
ValidationResult = new ValidationResult();
//Itens = new List<FaturaCobranca>();
}
public Guid? FaturaId { get; set; }
public Guid? ClienteId { get; set; }
//public Guid? CartaoId { get; set; }
public decimal Valor { get; set; }
public DateTime? DataCobranca { get; set; } // um nome melhor, pois trata-se da realização da efetivacao
public DateTime DataCadastro { get; set; }
public DateTime? DataModificacao { get; set; }
public DateTime? DataExclusao { get; set; }
public string Situacao { get; set; }
public ValidationResult ValidationResult { get; set; }
public bool IsValid()
{
//ValidationResult = new TransacaoEstaConsistenteValidation().Validate(this);
//return ValidationResult.IsValid;
return true;
}
//Relacionamentos
//public virtual ICollection<FaturaCobranca> Itens { get; set; }
public virtual ICollection<Cobranca> Cobrancas { get; set; }
public virtual ICollection<Transacao> Transacoes { get; set; }
}
public Fatura ObterPorClienteIdEDataVencimento(DateTime dataCobranca, Guid clienteId)
{
var cn = Db.Database.Connection;
const string sql = @"SELECT *
FROM dbo.Faturas
WHERE ClienteId = @clienteId
AND DataCobranca = CONVERT(DATE, @dataCobranca);
SELECT *
FROM dbo.Faturas
RIGHT JOIN dbo.Cobrancas
ON Cobrancas.FaturaId = Faturas.FaturaId
WHERE dbo.Faturas.ClienteId = @clienteId
AND dbo.Faturas.DataCobranca = CONVERT(DATE, @dataCobranca);";
using (var multi = cn.QueryMultiple(sql, new { clienteId, dataCobranca }, Db.Transaction?.UnderlyingTransaction))
{
var ret = multi.Read<Fatura>().SingleOrDefault();
if (ret != null)
{
ret.Cobrancas = multi.Read<Cobranca>().ToList();
}
return ret;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.