Feat : Not finished / Export implementation
continuous-integration/drone/push Build is passing Details

pull/37/head
Jade VAN BRABANDT 1 year ago
parent 528308d655
commit c9dc0c30a7

@ -11,6 +11,9 @@
<PackageReference Include="Blazorise.Bootstrap" Version="1.4.0" />
<PackageReference Include="Blazorise.DataGrid" Version="1.4.0" />
<PackageReference Include="Blazorise.Icons.FontAwesome" Version="1.4.0" />
<PackageReference Include="ChoETL" Version="1.2.1.64" />
<PackageReference Include="ChoETL.JSON" Version="1.2.1.64" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
</Project>

@ -1,13 +1,14 @@
@page "/chapters"
@using Blazor.Models
<h3>Liste</h3>
<DataGrid TItem="ChaptersModel"
Data="@chapters"
ReadData="@OnReadData"
TotalItems="@totalChapter"
PageSize="10"
ShowPager
Responsive>
<DataGridColumn TItem="ChaptersModel" Field="@nameof(ChaptersModel.Id)" Caption="#" />
<DataGridColumn TItem="ChaptersModel" Field="@nameof(ChaptersModel.Name)" Caption="Name" />
</DataGrid>
@page "/chapters"
@using Blazor.Models
<h3>Liste</h3>
<button type="button" class="btn btn-primary" @onclick="() => Export()"><i class="fa fa-trash"></i> Supprimer</button>
<DataGrid TItem="ChaptersModel"
Data="@chapters"
ReadData="@OnReadData"
TotalItems="@totalChapter"
PageSize="10"
ShowPager
Responsive>
<DataGridColumn TItem="ChaptersModel" Field="@nameof(ChaptersModel.Id)" Caption="#" />
<DataGridColumn TItem="ChaptersModel" Field="@nameof(ChaptersModel.Name)" Caption="Name" />
</DataGrid>

@ -1,7 +1,10 @@
using Blazor.Models;
using Blazored.LocalStorage;
using Blazorise.DataGrid;
using ChoETL;
using Microsoft.AspNetCore.Components;
using System.Reflection.Metadata;
using System.Text;
namespace Blazor.Pages;
public partial class Chapters
@ -58,4 +61,29 @@ public partial class Chapters
chapters = new List<ChaptersModel>(response); // an actual data for the current page
}
}
private async void Export()
{
StringBuilder sb = new StringBuilder();
HttpResponseMessage response = await Http.GetAsync("https://trusting-panini.87-106-126-109.plesk.page/api/chapters");
var json = await response.Content.ReadAsStringAsync();
using (var jsonFile = ChoJSONReader.LoadText(json))
{
using (var csvFile = new ChoCSVWriter(sb).WithFirstLineHeader())
{
csvFile.Write(json);
}
}
string path = @"C:\temp\file"; // path to file
using (FileStream fs = File.Create(path))
{
// writing data in string
byte[] info = new UTF8Encoding(true).GetBytes(sb.ToString());
fs.Write(info, 0, info.Length);
// writing data in bytes already
byte[] data = new byte[] { 0x0 };
fs.Write(data, 0, data.Length);
}
}
}
Loading…
Cancel
Save