Files
Backend-Api/ServiceHost/Areas/AdminNew/Pages/Index.cshtml.cs
2024-08-24 19:13:34 +03:30

54 lines
1.9 KiB
C#

using _0_Framework.Application;
using backService;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace ServiceHost.Areas.AdminNew.Pages
{
public class IndexModel : PageModel
{
private readonly IConfiguration _configuration;
public List<BackupViewModel> DbBackupList { get; set; }
public List<BackupViewModel> InsuranceBackupList { get; set; }
public IndexModel(IWebHostEnvironment webHostEnvironment, IConfiguration configuration)
{
_configuration = configuration;
}
public void OnGet()
{
#region DbBackupLoad
string? dbZipPath = _configuration["BackupOptions:DbBackupZipPath"];
string[] dbBackups = Directory.GetFiles(dbZipPath);
DbBackupList = dbBackups.Select(x => new BackupViewModel()
{
FileName = Path.GetFileName(x),
FullPath = x,
CreationDate = Path.GetFileName(x).ExtractTimeFromDbbackup(),
}).OrderByDescending(x => x.CreationDate).ToList();
#endregion
#region InsurancBackupLoad
string? insuranceZipPath = _configuration["BackupOptions:InsuranceListZipPath"];
string[] insuranceBackups = Directory.GetFiles(insuranceZipPath);
InsuranceBackupList = insuranceBackups.Select(x => new BackupViewModel()
{
FileName = Path.GetFileName(x),
FullPath = x,
CreationDate = Path.GetFileName(x).ExtractTimeFromInsurancebackup(),
}).OrderByDescending(x => x.CreationDate).ToList();
#endregion
}
public IActionResult OnGetDownloadFile(string path, string fileName)
{
byte[] fileContent = System.IO.File.ReadAllBytes(path);
return File(fileContent, "application/zip", fileName);
}
}
}