Files
Backend-Api/ServiceHost/Areas/AdminNew/Pages/Company/FileBackup/Index.cshtml.cs
2025-04-19 18:56:51 +03:30

94 lines
3.0 KiB
C#

using _0_Framework.Application;
using _0_Framework.Infrastructure;
using _0_Framework.InfraStructure;
using backService;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Configuration.UserSecrets;
namespace ServiceHost.Areas.AdminNew.Pages.Company.FileBackup
{
[Authorize]
public class IndexModel : PageModel
{
private readonly IConfiguration _configuration;
private readonly IAuthHelper _authHelper;
public List<BackupViewModel> DbBackupList { get; set; }
public List<BackupViewModel> FastDbBackupList { get; set; }
public List<BackupViewModel> InsuranceBackupList { get; set; }
public IndexModel(IConfiguration configuration, IAuthHelper authHelper)
{
_configuration = configuration;
_authHelper = authHelper;
}
public IActionResult OnGet()
{
if (_authHelper.GetPermissions().Any(x => x == 2) || _authHelper.CurrentAccountId() == 322)
{
#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 FastDbBackupList
string? fastdbZipPath = _configuration["BackupOptions:FastDbBackupZipPath"];
string[] fastdbBackups = Directory.GetFiles(fastdbZipPath);
FastDbBackupList = fastdbBackups.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
return Page();
}
else
{
return Forbid();
}
}
public IActionResult OnGetDownloadFile(string path, string fileName)
{
byte[] fileContent = System.IO.File.ReadAllBytes(path);
return File(fileContent, "application/zip", fileName);
}
}
}