Esempio n. 1
0
        public virtual ActionResult GeneratePdf(GeneratePdfModel model)
        {
            if (model.Start == new DateTime() || model.End == new DateTime())
            {
                return(View(MVC.Admin.Views.Requests, new GeneratePdfModel()));
            }

            var status = new RequestStatus();

            switch (model.Status)
            {
            case "Confirmed":
                status = RequestStatus.Confirmed;
                break;

            case "Declined":
                status = RequestStatus.Declined;
                break;

            case "Cancelled":
                status = RequestStatus.Cancelled;
                break;

            default:
                status = RequestStatus.Pending;
                break;
            }

            var requests = RequestRepository
                           .Where(x => x.TimeStamp <model.End && x.TimeStamp> model.Start && x.Status == status);
            var start = model.Start.ToString("d");
            var end   = model.End.ToString("d");

            var stream = PdfHelper.BuildRequestsPdf(requests, start, end, status);

            Response.Clear();
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-length", stream.Length.ToString());
            Response.BinaryWrite(stream.ToArray());
            Response.Flush();
            stream.Close();
            Response.End();

            return(View(MVC.Admin.Views.Requests, new GeneratePdfModel()));
        }