public async Task <IActionResult> ExportCodes() { var vendorCodeType = await _vendorCodeService.GetTypeAllAsync(); if (vendorCodeType?.FirstOrDefault() == null) { AlertDanger = "You must create a vendor code type before you can export codes."; return(RedirectToAction(nameof(Index))); } string date = _dateTimeProvider.Now.ToString("yyyyMMdd", CultureInfo.InvariantCulture); string codeFileName = vendorCodeType .First() .Description .Replace(" ", "", StringComparison.OrdinalIgnoreCase); return(File(await _vendorCodeService.ExportVendorCodesAsync(vendorCodeType.First().Id), "text/plain", FileUtility.EnsureValidFilename($"{date}-{codeFileName}.txt"))); }