44 lines
1.4 KiB
C#
44 lines
1.4 KiB
C#
using Mesa_Backlog.Library;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using IO = System.IO;
|
|
|
|
namespace Mesa_Backlog.Pages;
|
|
|
|
public class UploadAndExtract : PageModel
|
|
{
|
|
|
|
[BindProperty]
|
|
public string? JSON { get; set; }
|
|
|
|
[BindProperty]
|
|
public IFormFile? FormFile { get; set; }
|
|
|
|
private readonly AppSettings _AppSettings;
|
|
private readonly IHostEnvironment _HostEnvironment;
|
|
|
|
public UploadAndExtract(IHostEnvironment hostEnvironment, AppSettings appSettings)
|
|
{
|
|
_AppSettings = appSettings;
|
|
_HostEnvironment = hostEnvironment;
|
|
}
|
|
|
|
public IActionResult OnPost()
|
|
{
|
|
string directory = Path.Combine(_HostEnvironment.ContentRootPath, ".vscode", "Uploads");
|
|
if (!Directory.Exists(directory))
|
|
_ = Directory.CreateDirectory(directory);
|
|
if (FormFile is not null)
|
|
{
|
|
string fileName = Path.Combine(directory, FormFile.FileName);
|
|
string copyFileName = Path.Combine(directory, $"{DateTime.Now.Ticks}{Path.GetExtension(fileName)}");
|
|
using FileStream fileStream = new(fileName, FileMode.Create);
|
|
FormFile.CopyTo(fileStream);
|
|
IO.File.Copy(fileName, copyFileName);
|
|
JSON = ExcelReader.GetJson(copyFileName, _AppSettings.Excel.Sheet);
|
|
IO.File.Delete(copyFileName);
|
|
}
|
|
return Page();
|
|
}
|
|
|
|
} |