コード例 #1
0
ファイル: HomeController.cs プロジェクト: alx-fad3/WebAdmin
        public async Task <ActionResult> Reports(string npf, string date1, string date2)
        {
            try
            {
                DateTime d1;
                DateTime.TryParse(date1, out d1);
                DateTime d2;
                DateTime.TryParse(date2, out d2);

                if (string.IsNullOrEmpty(npf))
                {
                    throw new Exception("Не указан фонд");
                }
                else if (npf == "halva")
                {
                    var relatedProductsList = await commander.GetRelatedProductsAsync(d1, d2);

                    string reportPath = $@"C:\inetpub\Download_Reports\halva_{DateTime.Now.ToString("yyyy-MM-dd")}.xlsx";
                    ViewBag.reportPath = ExcelFormer.RelatedProductListToExcel(relatedProductsList, reportPath);
                }
                else
                {
                    var agreementsList = await commander.GetAgreementsAsync(npf, d1, d2);

                    string reportPath = $@"C:\inetpub\Download_Reports\{npf}_{DateTime.Now.ToString("yyyy-MM-dd")}.xlsx";
                    ViewBag.reportPath = ExcelFormer.RelatedProductListToExcel(agreementsList, reportPath);
                }

                return(Download(ViewBag.reportPath));
            }
            catch (Exception ex)
            {
                ViewBag.error = ex.Message;
                return(View("Error"));
            }
        }