new feature: json export

This commit is contained in:
Robert McRackan 2020-09-11 21:07:20 -04:00
parent 2795690199
commit b22c35f841
3 changed files with 15 additions and 10 deletions

View File

@ -138,6 +138,15 @@ namespace ApplicationServices
csv.WriteRecords(dtos);
}
public static void ToJson(string saveFilePath)
{
using var context = DbContexts.GetContext();
var dtos = context.GetLibrary_Flat_NoTracking().ToDtos();
var json = Newtonsoft.Json.JsonConvert.SerializeObject(dtos, Newtonsoft.Json.Formatting.Indented);
System.IO.File.WriteAllText(saveFilePath, json);
}
public static void ToXlsx(string saveFilePath)
{
using var context = DbContexts.GetContext();
@ -220,13 +229,5 @@ namespace ApplicationServices
public bool IsApproved { get; set; }
public string Comment { get; set; }
}
public static void ToJson(string saveFilePath)
{
using var context = DbContexts.GetContext();
var library = context.GetLibrary_Flat_NoTracking();
}
}
}

View File

@ -13,7 +13,7 @@
<!-- <PublishSingleFile>true</PublishSingleFile> -->
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<Version>4.0.4.4</Version>
<Version>4.0.5.3</Version>
</PropertyGroup>
<ItemGroup>

View File

@ -310,14 +310,18 @@ namespace LibationWinForms
var saveFileDialog = new SaveFileDialog
{
Title = "Where to export Library",
Filter = "CSV files (*.csv)|*.csv|All files (*.*)|*.*"
Filter = "CSV files (*.csv)|*.csv|JSON files (*.json)|*.json|All files (*.*)|*.*"
};
if (saveFileDialog.ShowDialog() != DialogResult.OK)
return;
// FilterIndex is 1-based, NOT 0-based
switch (saveFileDialog.FilterIndex)
{
case 2: // json
LibraryExporter.ToJson(saveFileDialog.FileName);
break;
case 1: // csv
default:
LibraryExporter.ToCsv(saveFileDialog.FileName);