using Entidades; using Microsoft.EntityFrameworkCore; namespace Modelo; public class RepositorioCanons: RepositorioBase { public ICollection? 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); } public bool CrearCanons(decimal aumento, long idcontrato) { //WIP var con = Context; aumento+=1; var cont = con.Contratos.Include(x=>x.Idcanons).FirstOrDefault(x=>x.Id == idcontrato); if (cont == null) return false; int exist = cont.Idcanons.Count(); if (exist+cont.MesesHastaAumento >= cont.MesesDurationContrato){ exist = cont.MesesDurationContrato-exist; } else{ exist = cont.MesesHastaAumento; } cont.Monto = cont.Monto * aumento; for (int i = 0; i < exist; i++){ Canon c = new Canon{ Fecha }; } } }