Exemplo n.º 1
0
        public async Task <FileDto> SearchTendersToXLS(TenderSearchDto searchDto)
        {
            var currentUser = await _userService.GetCurrentUserAsync();

            var company = await _dataContext.Companies
                          .Include(c => c.Subscriptions)
                          .ThenInclude(s => s.Tariff)
                          .SingleOrDefaultAsync(c => c.Id == currentUser.Id);

            if (!company.Subscriptions?.Any(s => s.Active && s.EndDate > DateTime.Now.Date && s.Tariff.ExportToXL) ?? true)
            {
                throw new BusinessException("Выгрузка Exel не доступна. Продлить тариф можно в личном кабинете");
            }

            var query = await SearchTendersByPatternQuery(searchDto, auto : false);

            var results = await query.ToListAsync();

            using var stream = ExcelService.CreateTendersXLSXToStream(results);

            return(new FileDto()
            {
                Content = stream.ToArray(),
                ContentType = "application/vnd.ms-excel",
                Name = "Tenders.xlsx"
            });
        }