112 lines
3.4 KiB
C#
112 lines
3.4 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;
|
|
using System.IO;
|
|
|
|
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 = new DateTime(),
|
|
}).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);
|
|
}
|
|
|
|
|
|
public IActionResult OnGetDownloadFileLog(string path, string fileName)
|
|
{
|
|
if (!System.IO.File.Exists(path))
|
|
return NotFound();
|
|
|
|
var stream = new FileStream(
|
|
path,
|
|
FileMode.Open,
|
|
FileAccess.Read,
|
|
FileShare.ReadWrite // 🔑 کلید حل مشکل
|
|
);
|
|
|
|
return File(stream, "text/plain", fileName);
|
|
}
|
|
|
|
}
|
|
}
|