예제 #1
0
        public ActionResult Download(DownloadReportModel model)
        {
            var session = Session["login"];

            if (session == null)
            {
                return(RedirectToAction("Login"));
            }
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            try
            {
                Response.ContentType = "application/vnd.ms-excel";
                Response.AddHeader("content-disposition", $"attachment; filename=Report {model.StartDate.ToShortDateString()} to {model.EndDate.ToShortDateString()} of {DateTime.Now.ToShortDateString()}.xls");
                Response.Clear();
                var result = _reportAppService.GetReportTransactional(model.StartDate, model.EndDate);
                Response.BinaryWrite(result.GetBuffer());
                Response.End();
            }
            catch (Exception exception)
            {
                ModelState.AddModelError("", exception.InnerException?.Message ?? exception.Message);
            }
            return(View(model));
        }