-
-
Save Renancp01/66e5d10a66c97b1bf791bae044bffdab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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