public ActionResult Export() { ReportViewModel ReportModel = new ReportViewModel(); using (var db = HttpContext.GetOwinContext().Get<ApplicationDbContext>()) { var prettifiedNumbers = db.PrettifiedNumbers.ToList(); //Get Top Most used Prettified Numbers ReportModel.TopMostUsedPrettifiedNumbers = (from num in prettifiedNumbers group num by num.PrettifiedCategory into g orderby g.Count() descending select new { Category = g.Key }).Select(t => t.Category).ToList(); //Get Prettified Numbers Counts Per User ReportModel.PrettifiedNumbersByUsers = prettifiedNumbers.GroupBy(p => p.User).Select(result => new UserStats { Email = result.Key.Email, PrettifiedNumbersCount = result.Count() }).ToList(); } return View(ReportModel); }
public ActionResult ExportExcel() { ReportViewModel ReportModel = new ReportViewModel(); using (var db = HttpContext.GetOwinContext().Get<ApplicationDbContext>()) { var prettifiedNumbers = db.PrettifiedNumbers.ToList(); //Get Top Most used Prettified Numbers ReportModel.TopMostUsedPrettifiedNumbers = (from num in prettifiedNumbers group num by num.PrettifiedCategory into g orderby g.Count() descending select new { Category = g.Key }).Select(t => t.Category).ToList(); //Get Prettified Numbers Counts Per User ReportModel.PrettifiedNumbersByUsers = prettifiedNumbers.GroupBy(p => p.User).Select(result => new UserStats { Email = result.Key.Email, PrettifiedNumbersCount = result.Count() }).ToList(); } Response.AddHeader("content-disposition", "attachment; filename=PrettifierReport.xls"); Response.ContentType = "application/ms-excel"; return View("exportexcel", ReportModel); }