fixed export file path.

This commit is contained in:
DESKTOP-GENO133\IvanPlex 2024-02-09 14:55:29 -07:00
parent f34f3da587
commit b93b7f321e
2 changed files with 11 additions and 2 deletions

View File

@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Npgsql; using Npgsql;
using System.Data.Common; using System.Data.Common;
using System.IO.Compression;
using System.Xml.Linq; using System.Xml.Linq;
namespace CarCareTracker.Controllers namespace CarCareTracker.Controllers
@ -67,7 +68,10 @@ namespace CarCareTracker.Controllers
{ {
return Json(new OperationResponse { Success = false, Message = "Postgres connection not set up" }); return Json(new OperationResponse { Success = false, Message = "Postgres connection not set up" });
} }
var tempPath = $"temp/{Guid.NewGuid}.db"; var tempFolder = $"temp/{Guid.NewGuid()}";
var tempPath = $"{tempFolder}/cartracker.db";
var fullFolderPath = _fileHelper.GetFullFilePath(tempFolder, false);
Directory.CreateDirectory(fullFolderPath);
var fullFileName = _fileHelper.GetFullFilePath(tempPath, false); var fullFileName = _fileHelper.GetFullFilePath(tempPath, false);
try try
{ {
@ -393,10 +397,13 @@ namespace CarCareTracker.Controllers
}; };
} }
#endregion #endregion
return Json(new OperationResponse { Success = true, Message = $"/{tempPath}" }); var destFilePath = $"{fullFolderPath}.zip";
ZipFile.CreateFromDirectory(fullFolderPath, destFilePath);
return Json(new OperationResponse { Success = true, Message = $"/{tempFolder}.zip" });
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex.Message);
return Json(new OperationResponse { Success = false, Message = StaticHelper.GenericErrorMessage }); return Json(new OperationResponse { Success = false, Message = StaticHelper.GenericErrorMessage });
} }
} }

View File

@ -42,7 +42,9 @@
</div> </div>
<script> <script>
function exportFromPostgres(){ function exportFromPostgres(){
sloader.show();
$.get('/Migration/Export', function (data) { $.get('/Migration/Export', function (data) {
sloader.hide();
if (data.success) { if (data.success) {
window.location.href = data.message; window.location.href = data.message;
} else { } else {