コード例 #1
0
        public ActionResult View(string dateBegin, string dateEnd, string employeeFilter, string command)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("View"));
            }

            if (!string.IsNullOrEmpty(dateBegin) && !string.IsNullOrEmpty(dateEnd))
            {
                _erService.DateBegin = Convert.ToDateTime(dateBegin);
                _erService.DateEnd   = Convert.ToDateTime(dateEnd).AddDays(1);
            }

            _erService.EmployeeFilter = employeeFilter;

            EmployeeReportViewModel model;

            if (command == "Загрузить Excel")
            {
                var excelCreator = new ExcelCreator();
                model = _erService.GetData();
                var fullPath = excelCreator.CreateFile(model);
                return(File(new FileStream(fullPath, FileMode.Open), "application/vnd.ms-excel", "Отчёт по сотрудникам.xlsx"));
            }

            model = _erService.GetData();
            return(View(model));
        }