// GET: BillReports/ALSR
        public ActionResult ALSR()
        {
            var reportService = new BillsAlsrReportsService();
            var reports       = reportService.GetAll();

            return(View(reports));
        }
        // GET: BillReports/DownloadAlsr/5
        public ActionResult DownloadAlsr(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var reportService = new BillsAlsrReportsService();
            var report        = reportService.GetById(id.Value);

            return(File(report.Pdf, "application/pdf", report.Filename));
        }
        public async Task <ActionResult> GenerateALSR(AlsrReportSelectBillReviewsViewModel model)
        {
            if (ModelState.IsValid)
            {
                var selectedIds = model.getSelectedIds();

                if (selectedIds.Count() == 0)
                {
                    Danger("No Bills were selected for inclusion in the report.");
                    return(View());
                }

                var selectedBillReviews = from x in db.BillReviews
                                          .Include(r => r.Bill)
                                          .Include(r => r.CreatedByUser)
                                          .Include(r => r.Recommendation)
                                          where selectedIds.Contains(x.ID)
                                          select x;

                var report = new BillsAlsrReport();
                report.BudgetPeriodID        = (await db.AppGlobalSettings.FirstOrDefaultAsync()).BudgetPeriodID;
                report.BudgetSessionID       = (await db.AppGlobalSettings.FirstOrDefaultAsync()).BudgetSessionID;
                report.CreatedAt             = DateTime.Now;
                report.GovOfficeDeliveryDate = model.GovOfficeDeliveryDate;

                var user = await ReturnCurrentUserAsync();

                report.DeptID            = user.DeptID;
                report.DivID             = user.DivID;
                report.ApplicationUserID = user.Id;

                //var snapshots = new List<AlsrBillReviewSnapshot>();
                foreach (BillReview r in selectedBillReviews.ToList())
                {
                    var s = new AlsrBillReviewSnapshot()
                    {
                        ActivelyTracking           = r.ActivelyTracking,
                        ApplicationUserID          = r.ApplicationUserID,
                        BillID                     = r.BillID,
                        BillReviewRecommendationID = r.BillReviewRecommendationID,
                        BillVersionID              = r.BillVersionID,
                        CapturedFromBillReviewID   = r.ID,
                        CapturedFromRowVersion     = r.RowVersion,
                        Comments                   = r.Comments,
                        CreatedAt                  = r.CreatedAt,
                        CreatedAtApprovalLevel     = r.CreatedAtApprovalLevel,
                        DeptID                     = r.DeptID,
                        DivID = r.DivID,
                        FiscalImpactFuture      = r.FiscalImpactFuture,
                        FiscalImpactYr1         = r.FiscalImpactYr1,
                        FiscalImpactYr2         = r.FiscalImpactYr2,
                        FiscalNoteSubmitted     = r.FiscalNoteSubmitted,
                        InformationToBeProvided = r.InformationToBeProvided,
                        Notes             = r.Notes,
                        PolicyImpact      = r.PolicyImpact,
                        RequiresTestimony = r.RequiresTestimony,
                        Timestamp         = DateTime.Now
                                            //SupercedesPreviousSnapshotID = ()
                    };
                    report.AlsrBillReviewSnapshots.Add(s);
                }

                db.BillsAlsrReports.Add(report);
                await db.SaveChangesAsync();

                var reportService = new BillsAlsrReportsService();
                var readReport    = reportService.GetById(report.ID);
                readReport.Pdf = await CreateAlsrPdf(report.ID);

                readReport.Filename = string.Format("ALSR_{0}_{1}.pdf", readReport.Dept.Description, readReport.CreatedAt);
                reportService.Update(readReport);
                //await db.SaveChangesAsync();

                Success("ALSR Report created successfully");
                return(RedirectToAction("ALSR"));
            }
            Danger("Invalid model state");
            return(View());
        }