45 lines
1.5 KiB
C#
45 lines
1.5 KiB
C#
using Entidades;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Modelo;
|
|
|
|
public class RepositorioCanons: RepositorioBase<RepositorioCanons> {
|
|
public ICollection<Canon>? ObtenerCanonsPorContrato(int id) {
|
|
var con = Context;
|
|
var l = con.Contratos.Include(x=>x.Idcanons).FirstOrDefault(x => x.Id == id);
|
|
if (l == null) return null;
|
|
return l.Idcanons;
|
|
}
|
|
public Canon? ObtenerCanonContrato(DateTime f, long idcont) {
|
|
var con = Context;
|
|
Canon? cc = null;
|
|
|
|
var c = con.Canons.FirstOrDefault(x => x.Idrecibo == null &&
|
|
x.Fecha == f );
|
|
if (c == null) return null;
|
|
//no deberia de tener que usar un foreach pero entity por algun motivo mapeo
|
|
//la entidad como muchos a muchos. no hay forma de que un canon tenga multiples
|
|
//contratos por como lo codifique pero igualmente
|
|
foreach (var i in c.Idcontratos) {
|
|
foreach (var j in i.Idcanons) {
|
|
if (j.Fecha == f) {
|
|
cc = j;
|
|
}
|
|
}
|
|
}
|
|
return cc;
|
|
}
|
|
|
|
public bool SetRecibo(Canon c, Recibo re) {
|
|
var con = Context;
|
|
var cc = con.Canons.FirstOrDefault(x=>x.Id == c.Id);
|
|
if (cc == null) return false;
|
|
|
|
re.Id = (con.Recibos.Any()?con.Recibos.Max(x=>x.Id):0)+1;
|
|
con.Recibos.Add(re);
|
|
cc.Idrecibo = re.Id;
|
|
cc.Pagado = 1;
|
|
|
|
return Guardar(con);
|
|
}
|
|
} |