public IActionResult List(ReportFilterForm form, string pdf, string excel) { if (!RoleIs(Role.Administrator, Role.Manager)) { return(Forbid()); } var registrations = _registrationService .AllInclude(x => x.Employee, x => x.Entrance.Building) .ForEmployee(form.EmployeeId) .ForPeriod(form.DateFrom, form.DateTo) .WithStrictScheduleRestriction(form.StrictSchedule) .WithLateness(_timeService, form.Lateness) .ToList(); var viewModel = GetViewModel(registrations, form); if (string.IsNullOrWhiteSpace(pdf) && string.IsNullOrWhiteSpace(excel)) { return(View(viewModel)); } viewModel.IsDocument = true; if (pdf != null) { var htmlContent = _htmlLayoutGenerator.RenderAsync($"Registration/{nameof(List)}", viewModel) .GetAwaiter().GetResult(); var file = _pdfGenerator.GenerateAsync(htmlContent).GetAwaiter().GetResult(); return(File(file, "application/json", $"Отчет_{_timeService.Now.ToShortDateString()}_{_timeService.Now.ToShortTimeString()}.pdf")); } else { var file = _excelGenerator.GenerateAsync(viewModel).GetAwaiter().GetResult(); return(File(file, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", $"Отчет_{_timeService.Now.ToShortDateString()}_{_timeService.Now.ToShortTimeString()}.xlsx")); } }