public reporteHeader GetHeader(int presupuestoId) { var header = new reporteHeader(); try { using (var ctx = new PresupuestoContext()) { header = (from p in ctx.SPPresupuesto join t in ctx.SPTipoPresupuesto on p.tipoId equals t.tipoId where p.Id == presupuestoId select new reporteHeader { nombre_presupuesto = "Presupuesto " + t.nombre, total = p.total_estimado, año = p.año, semana = p.semana, mes = p.mes }).SingleOrDefault(); } }catch (Exception e) { throw e; } return(header); }
public List <PrecioAnalisis> ConsultaPrecio(int id) { PresupuestoContext ctx = PresupuestoContext.DB; var lista = ctx.Database.SqlQuery <PrecioAnalisis>(SQL, id); return(lista.ToList()); }
public GraficasListDto GetPresupuestos() { var list = new GraficasListDto(); try { using (var ctx = new PresupuestoContext()) { list = (from t in ctx.SPTipoPresupuesto join p in ctx.SPPresupuesto on t.tipoId equals p.tipoId where t.tipoId == 1 select new { tipo = t.nombre, labels = (from dp in ctx.SPPresupuesto join ti in ctx.SPTipoPresupuesto on dp.tipoId equals ti.tipoId where dp.tipoId == p.tipoId select new Labels { label = "Semana " + dp.semana }).ToList(), data = (from dpt in ctx.SPPresupuesto join tit in ctx.SPTipoPresupuesto on dpt.tipoId equals tit.tipoId where dpt.tipoId == p.tipoId select new data { total = dpt.total_estimado }).ToList(), }).Select(x => new GraficasListDto { tipo = x.tipo, labels = x.labels, data = x.data }).SingleOrDefault(); } } catch (Exception e) { throw e; } return(list); }
static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += (o, e) => { PresupuestoContext.DB.Dispose(); Logger.Log.Close(); Console.WriteLine("Excepcion"); }; Logger.Log.Info("Inicializando..."); using (PresupuestoContext ctx = PresupuestoContext.DB) { if (ctx.Database.Exists()) { Console.WriteLine("La base esta...!!"); if (!ctx.ModoSeguro) { Console.WriteLine("MODO DE ESCRITURA INDISCRIMINADA..."); } } else { Console.WriteLine("La base no esta...."); Console.ReadLine(); Environment.Exit(-1); } var lista = ctx.Database.SqlQuery <PrecioCuidado>("select * from PreciosCuidados"); foreach (var x in lista) { Console.WriteLine($"{x.Analisis} -- {x.Precio}"); } // LINQ var os = ctx.ObrasSociales.Where(pepe => pepe.ID == 1).FirstOrDefault(); var xx = os.Precios.Average(p => p.Valor); Console.WriteLine(xx); foreach (var x in os.Precios) { Console.WriteLine($"Analisis: {x.Analisis.Nombre} -- Precio: {x.Valor}"); } var analisis = ctx.Analisis.Join(ctx.Precios, xxx => xxx.ID, pp => pp.Analisis.ID, (a, p) => new { a.Nombre, p.ObraSocial }).Where(hh => hh.ObraSocial.ID != 1).First(); //var os1 = ctx.ObrasSociales.Select(); /* * var ing = ctx.Pacientes.Where(p => p.DNI == 18339577).Single().Ingresos.Count; * * Listado resultado = new Listado { DNI = 18339577, Ingresos = ing}; * * var pp = ctx.Database.SqlQuery<Listado>("select DNI, count(*) as Ingresos from ....where DNI=@p0 group by DNI", 18339577).ToList(); */ /* * if (!ctx.ModoSeguro) * { * bool fValorPrevio = os.Activo; * os.Activo = !os.Activo; * ctx.SaveChanges(); * * Console.WriteLine($"==> Cambios realizados...{os.Nombre} paso de {fValorPrevio} a {os.Activo}"); * } */ Console.WriteLine(os.Nombre); Console.ReadLine(); } Logger.Log.Close(); }