mirror of
https://github.com/hargata/lubelog.git
synced 2025-12-10 00:46:08 -06:00
add method to write to temp
This commit is contained in:
parent
50f4308417
commit
a90b8bdf93
@ -321,13 +321,13 @@ namespace CarCareTracker.Controllers
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public IActionResult ExportTranslation(IFormFile file)
|
public IActionResult ExportTranslation(IFormFile file)
|
||||||
{
|
{
|
||||||
var translationData = new Dictionary<string, string>();
|
var result = string.Empty;
|
||||||
using (var sReader = new StreamReader(file.OpenReadStream()))
|
using (var sReader = new StreamReader(file.OpenReadStream()))
|
||||||
{
|
{
|
||||||
|
var fileName = $"{Guid.NewGuid()}.json";
|
||||||
var sData = sReader.ReadToEnd();
|
var sData = sReader.ReadToEnd();
|
||||||
translationData = JsonSerializer.Deserialize<Dictionary<string, string>>(sData);
|
result = _fileHelper.WriteFileToTemp(fileName, sData);
|
||||||
}
|
}
|
||||||
var result = _translationHelper.ExportTranslation(translationData);
|
|
||||||
return Json(result);
|
return Json(result);
|
||||||
}
|
}
|
||||||
[Authorize(Roles = nameof(UserData.IsRootUser))]
|
[Authorize(Roles = nameof(UserData.IsRootUser))]
|
||||||
|
|||||||
@ -24,6 +24,7 @@ namespace CarCareTracker.Helper
|
|||||||
bool WidgetsExist();
|
bool WidgetsExist();
|
||||||
bool SaveWidgets(string widgetsData);
|
bool SaveWidgets(string widgetsData);
|
||||||
bool DeleteWidgets();
|
bool DeleteWidgets();
|
||||||
|
string WriteFileToTemp(string fileName, string data);
|
||||||
}
|
}
|
||||||
public class FileHelper : IFileHelper
|
public class FileHelper : IFileHelper
|
||||||
{
|
{
|
||||||
@ -514,5 +515,25 @@ namespace CarCareTracker.Helper
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public string WriteFileToTemp(string fileName, string data)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//check if temp folder exists
|
||||||
|
var tempFolder = GetFullFilePath("/temp", false);
|
||||||
|
if (!Directory.Exists(tempFolder))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(tempFolder);
|
||||||
|
}
|
||||||
|
var tempFileName = $"/temp/{fileName}";
|
||||||
|
var fullTempFileName = GetFullFilePath(tempFileName, false);
|
||||||
|
File.WriteAllText(fullTempFileName, data);
|
||||||
|
return tempFileName;
|
||||||
|
} catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex.Message);
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,6 @@ namespace CarCareTracker.Helper
|
|||||||
string Translate(string userLanguage, string text);
|
string Translate(string userLanguage, string text);
|
||||||
Dictionary<string, string> GetTranslations(string userLanguage);
|
Dictionary<string, string> GetTranslations(string userLanguage);
|
||||||
OperationResponse SaveTranslation(string userLanguage, Dictionary<string, string> translations);
|
OperationResponse SaveTranslation(string userLanguage, Dictionary<string, string> translations);
|
||||||
string ExportTranslation(Dictionary<string, string> translations);
|
|
||||||
}
|
}
|
||||||
public class TranslationHelper : ITranslationHelper
|
public class TranslationHelper : ITranslationHelper
|
||||||
{
|
{
|
||||||
@ -167,31 +166,5 @@ namespace CarCareTracker.Helper
|
|||||||
return OperationResponse.Failed();
|
return OperationResponse.Failed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public string ExportTranslation(Dictionary<string, string> translations)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var tempFileName = $"/temp/{Guid.NewGuid()}.json";
|
|
||||||
string uploadDirectory = _fileHelper.GetFullFilePath("temp/", false);
|
|
||||||
if (!Directory.Exists(uploadDirectory))
|
|
||||||
{
|
|
||||||
Directory.CreateDirectory(uploadDirectory);
|
|
||||||
}
|
|
||||||
var saveFilePath = _fileHelper.GetFullFilePath(tempFileName, false);
|
|
||||||
//standardize translation format for export only.
|
|
||||||
Dictionary<string, string> sortedTranslations = new Dictionary<string, string>();
|
|
||||||
foreach (var translation in translations.OrderBy(x => x.Key))
|
|
||||||
{
|
|
||||||
sortedTranslations.Add(translation.Key, translation.Value);
|
|
||||||
};
|
|
||||||
File.WriteAllText(saveFilePath, JsonSerializer.Serialize(sortedTranslations, new JsonSerializerOptions { WriteIndented = true }));
|
|
||||||
return tempFileName;
|
|
||||||
}
|
|
||||||
catch(Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex.Message);
|
|
||||||
return string.Empty;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -184,6 +184,22 @@ namespace CarCareTracker.Models
|
|||||||
Action = $"{userName} {GetFriendlyActionType(actionType)} Description: {planRecord.Description}"
|
Action = $"{userName} {GetFriendlyActionType(actionType)} Description: {planRecord.Description}"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
public static WebHookPayload FromInspectionRecord(InspectionRecord inspectionRecord, string actionType, string userName)
|
||||||
|
{
|
||||||
|
Dictionary<string, string> payloadDictionary = new Dictionary<string, string>();
|
||||||
|
payloadDictionary.Add("user", userName);
|
||||||
|
payloadDictionary.Add("description", inspectionRecord.Description);
|
||||||
|
payloadDictionary.Add("vehicleId", inspectionRecord.VehicleId.ToString());
|
||||||
|
payloadDictionary.Add("cost", inspectionRecord.Cost.ToString("F2"));
|
||||||
|
return new WebHookPayload
|
||||||
|
{
|
||||||
|
Type = actionType,
|
||||||
|
Data = payloadDictionary,
|
||||||
|
VehicleId = inspectionRecord.VehicleId.ToString(),
|
||||||
|
Username = userName,
|
||||||
|
Action = $"{userName} {GetFriendlyActionType(actionType)} Description: {inspectionRecord.Description}"
|
||||||
|
};
|
||||||
|
}
|
||||||
public static WebHookPayload FromReminderRecord(ReminderRecord reminderRecord, string actionType, string userName)
|
public static WebHookPayload FromReminderRecord(ReminderRecord reminderRecord, string actionType, string userName)
|
||||||
{
|
{
|
||||||
Dictionary<string, string> payloadDictionary = new Dictionary<string, string>();
|
Dictionary<string, string> payloadDictionary = new Dictionary<string, string>();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user