File size: 1,025 Bytes
9ba9d1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using OilShopManagement.Services;

namespace OilShopManagement.Controllers;

[Authorize(Roles = "Admin")]
public class BackupController : Controller
{
    private readonly DatabaseBackupService _backup;

    public BackupController(DatabaseBackupService backup) => _backup = backup;

    public IActionResult Index()
    {
        var files = DatabaseBackupService.ListBackups();
        return View(files);
    }

    [HttpPost]
    public async Task<IActionResult> Create()
    {
        await _backup.TriggerAsync();
        TempData["Success"] = "تم إنشاء نسخة احتياطية بنجاح";
        return RedirectToAction(nameof(Index));
    }

    public IActionResult Download(string fileName)
    {
        var path = DatabaseBackupService.GetBackupPath(fileName);
        if (path == null) return NotFound();

        var bytes = System.IO.File.ReadAllBytes(path);
        return File(bytes, "application/json", fileName);
    }
}