public IEnumerable <Object> GetReport(string id) { IQueryable <IGrouping <string, POZADAVKY> > grps; var poz = context.POZADAVKY; if (id == "dlebrokera") { grps = poz.GroupBy(p => p.broker_id.ToString()); } else if (id == "dleveku") { grps = poz.Select(p => new { Vek = EntityFunctions.DiffYears(p.KLIENTI.narozen, DateTime.Now), Pozadavek = p }) .GroupBy(itm => itm.Vek < 30 ? "0-29" : itm.Vek < 60 ? "30-59" : "59+", itm => itm.Pozadavek); } else if (id == "dlepujcky") { grps = poz.GroupBy(p => p.castka < 200000 ? "0-200 000" : p.castka < 300000 ? "200 000 - 300 000" : p.castka < 500000 ? "300 000 - 500 000" : "500 000+"); } else { return(new List <Object>()); } var stats = grps.Select(g => new { Group = g.Key, Total = g.Sum(p => p.castka), // nebo Average místo Sum Count = g.Count() }).ToList(); var labels = stats.Select(g => g.Group); var data1 = stats.Select(g => g.Total); var data2 = stats.Select(g => g.Count); var fn = HostingEnvironment.MapPath("~/App_Data/report_template.html"); var outFn = HostingEnvironment.MapPath("~/App_Data/report.html"); var html = File.ReadAllText(fn); //převede do jsona var labelsJson = JsonConvert.SerializeObject(labels); var dataJson = JsonConvert.SerializeObject(new List <Object> { data1, data2 }); html = html.Replace("$LABELS$", labelsJson); html = html.Replace("$DATA$", dataJson); File.WriteAllText(outFn, html); return(stats); }
public void DateTimeDiffYears() { DateTime date = stored.AddYears(-1); #if !EFOLD var q = this.Entities .Where(x => DbFunctions.DiffYears(date, x.DateTime) == 1); #else var q = this.Entities .Where(x => EntityFunctions.DiffYears(date, x.DateTime) == 1); #endif q.Should().NotBeEmpty(); }
public void DateTimeOffsetDiffYears() { DateTimeOffset offset = stored.AddYears(-1); #if !EFOLD var q = this.Entities .Where(x => DbFunctions.DiffYears(offset, x.Offset) == 1); #else var q = this.Entities .Where(x => EntityFunctions.DiffYears(offset, x.Offset) == 1); #endif q.Should().NotBeEmpty(); }
public ActionResult Index() { var liste = db.PERSONELs.Where(a => a.DOGUM_GUNU_TARIHI != null). OrderBy(a => EntityFunctions.DiffDays(DateTime.Today, EntityFunctions.AddYears(a.DOGUM_GUNU_TARIHI, EntityFunctions.DiffYears(a.DOGUM_GUNU_TARIHI, DateTime.Today) + ((a.DOGUM_GUNU_TARIHI.Month < DateTime.Today.Month || (a.DOGUM_GUNU_TARIHI.Day <= DateTime.Today.Day && a.DOGUM_GUNU_TARIHI.Month == DateTime.Today.Month)) ? 1 : 0)))).Take(3).ToList(); ViewData["yuksek"] = db.EGITIMs.Where(s => s.OGRETIM_TIPI == "Yüksek Lisans").Count(); ViewData["lisans"] = db.EGITIMs.Where(s => s.OGRETIM_TIPI == "Lisans").Count(); ViewData["onlisans"] = db.EGITIMs.Where(s => s.OGRETIM_TIPI == "Ön Lisans").Count(); ViewData["duyuru"] = db.DUYURUs.ToList(); return(View(liste)); }