Maxence GUITARD 1 year ago
commit 4ad1d0aaaa

@ -1,4 +1,5 @@
<Router AppAssembly="@typeof(App).Assembly"> <CascadingBlazoredModal>
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData"> <Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" /> <RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" /> <FocusOnNavigate RouteData="@routeData" Selector="h1" />
@ -9,4 +10,5 @@
<p role="alert">Sorry, there's nothing at this address.</p> <p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView> </LayoutView>
</NotFound> </NotFound>
</Router> </Router>
</CascadingBlazoredModal>

@ -6,14 +6,32 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Content Remove="Pages\_Layout.cshtml" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Blazored.LocalStorage" Version="4.4.0" /> <PackageReference Include="Blazored.LocalStorage" Version="4.4.0" />
<PackageReference Include="Blazored.Modal" Version="7.1.0" />
<PackageReference Include="Blazorise.Bootstrap" Version="1.4.0" /> <PackageReference Include="Blazorise.Bootstrap" Version="1.4.0" />
<PackageReference Include="Blazorise.DataGrid" Version="1.4.0" /> <PackageReference Include="Blazorise.DataGrid" Version="1.4.0" />
<PackageReference Include="Blazorise.Icons.FontAwesome" 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.NETStandard" Version="1.2.1.64" />
<PackageReference Include="ChoETL.JSON" Version="1.2.1.64" /> <PackageReference Include="ChoETL.NETStandard" Version="1.2.1.64" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
</ItemGroup>
<ItemGroup>
<UpToDateCheckInput Remove="Pages\_Layout.cshtml" />
</ItemGroup>
<ItemGroup>
<_ContentIncludedByDefault Remove="Pages\_Layout.cshtml" />
</ItemGroup>
<ItemGroup>
<None Include="Pages\_Layout.cshtml" />
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -0,0 +1,12 @@
@page "/DeleteConfirmation"
<div class="simple-form">
<p>
Are you sure you want to delete @chapter.Name ?
</p>
<button @onclick="ConfirmDelete" class="btn btn-primary">Delete</button>
<button @onclick="Cancel" class="btn btn-secondary">Cancel</button>
</div>

@ -0,0 +1,38 @@
using Blazor.Services;
using Blazored.Modal.Services;
using Blazored.Modal;
using Microsoft.AspNetCore.Components;
using Blazor.ViewClasses;
namespace Blazor.Modals
{
public partial class DeleteConfirmation
{
[CascadingParameter]
public BlazoredModalInstance ModalInstance { get; set; }
[Inject]
public IDataService DataService { get; set; }
[Parameter]
public int Id { get; set; }
private Chapter chapter = new Chapter();
protected override async Task OnInitializedAsync()
{
// Get the chapter
chapter = await DataService.GetById(Id);
}
void ConfirmDelete()
{
ModalInstance.CloseAsync(ModalResult.Ok(true));
}
void Cancel()
{
ModalInstance.CancelAsync();
}
}
}

@ -1,6 +1,7 @@
@page "/chapters" @page "/chapters"
@using Blazor.ViewClasses; @using Blazor.ViewClasses;
@using Blazorise.DataGrid @using Blazorise.DataGrid
@using Blazored.Modal;
<h3>Chapters</h3> <h3>Chapters</h3>
<div> <div>
@ -24,6 +25,7 @@
<DataGridColumn TItem="Chapter" Field="@nameof(Chapter.Id)" Caption="Action"> <DataGridColumn TItem="Chapter" Field="@nameof(Chapter.Id)" Caption="Action">
<DisplayTemplate> <DisplayTemplate>
<a href="editChapter/@(context.Id)" class="btn btn-primary"><i class="fa fa-edit"></i> Editer</a> <a href="editChapter/@(context.Id)" class="btn btn-primary"><i class="fa fa-edit"></i> Editer</a>
<button type="button" class="btn btn-primary" @onclick="() => OnDelete(context.Id)"><i class="fa fa-trash"></i> Supprimer</button>
</DisplayTemplate> </DisplayTemplate>
</DataGridColumn> </DataGridColumn>
</DataGrid> </DataGrid>

@ -1,20 +1,29 @@
using Blazored.LocalStorage; using Blazored.LocalStorage;
using Blazorise;
using Blazor.Services; using Blazor.Services;
using Blazor.Modals;
using Blazored.Modal;
using Blazored.Modal.Services;
using Blazor.ViewClasses;
using System.Text;
using Microsoft.JSInterop;
using Microsoft.AspNetCore.Components;
using Blazorise.DataGrid; using Blazorise.DataGrid;
using ChoETL; using ChoETL;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using System.Text;
using Blazor.ViewClasses;
namespace Blazor.Pages; namespace Blazor.Pages;
public partial class Chapters public partial class Chapters
{ {
public List<Chapter> chapters; public List<Chapter> chapters;
private int totalChapter; private int totalChapter;
[Inject]
public NavigationManager NavigationManager { get; set; }
[CascadingParameter]
public IModalService Modal { get; set; }
[Inject] [Inject]
public IDataService DataService { get; set; } public IDataService DataService { get; set; }
public IWebHostEnvironment WebHostEnvironment { get; set; } public IWebHostEnvironment WebHostEnvironment { get; set; }
@ -25,9 +34,6 @@ public partial class Chapters
[Inject] [Inject]
public ILocalStorageService LocalStorage { get; set; } public ILocalStorageService LocalStorage { get; set; }
[Inject]
public NavigationManager NavigationManager { get; set; }
[Inject] [Inject]
public IJSRuntime IJSRuntime { get; set; } public IJSRuntime IJSRuntime { get; set; }
@ -88,4 +94,26 @@ public partial class Chapters
await IJSRuntime.InvokeVoidAsync("downloadFileFromStream", "data.csv", streamRef); await IJSRuntime.InvokeVoidAsync("downloadFileFromStream", "data.csv", streamRef);
} }
} }
private async void OnDelete(int id)
{
var parameters = new ModalParameters();
parameters.Add(nameof(Chapter.Id), id);
var modal = Modal.Show<DeleteConfirmation>("Delete Confirmation", parameters);
var result = modal.Result;
if (result.IsCanceled)
{
return;
}
await DataService.Delete(id);
// Reload the page
NavigationManager.NavigateTo("chapters", true);
}
} }

@ -0,0 +1,16 @@
<html>
<body>
<link href="_content/Blazored.Modal/blazored-modal.css" rel="stylesheet" />
<script src="_content/Blazored.Modal/blazored.modal.js"></script>
<script src="_framework/blazor.server.js"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css">
<link href="_content/Blazorise/blazorise.css" rel="stylesheet" />
<link href="_content/Blazorise.Bootstrap/blazorise.bootstrap.css" rel="stylesheet" />
</body>
</html>

@ -6,6 +6,7 @@ using Blazorise.Bootstrap;
using Blazorise.Icons.FontAwesome; using Blazorise.Icons.FontAwesome;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.Web;
using Blazored.Modal;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -30,6 +31,9 @@ builder.Services
builder.Services.AddBlazoredLocalStorage(); builder.Services.AddBlazoredLocalStorage();
builder.Services.AddBlazoredModal();
builder.Services.AddScoped<IDataService, DataLocalService>(); builder.Services.AddScoped<IDataService, DataLocalService>();
var app = builder.Build(); var app = builder.Build();

@ -83,6 +83,22 @@ namespace Blazor.Services
await _localStorage.SetItemAsync("data", currentData); await _localStorage.SetItemAsync("data", currentData);
} }
public async Task Delete(int id)
{
// Get the current data
var currentData = await _localStorage.GetItemAsync<List<Chapter>>("data");
// Get the chapter int the list
var chapter = currentData.FirstOrDefault(w => w.Id == id);
// Delete chapter in
currentData.Remove(chapter);
// Save the data
await _localStorage.SetItemAsync("data", currentData);
}
public async Task<int> Count() public async Task<int> Count()
{ {

@ -23,5 +23,7 @@ namespace Blazor.Services
Task<int> CountAdmin(); Task<int> CountAdmin();
Task<List<Administrator>> ListAdmin(int currentPage, int pageSize); Task<List<Administrator>> ListAdmin(int currentPage, int pageSize);
Task Delete(int id);
} }
} }

@ -9,3 +9,6 @@
@using Blazor @using Blazor
@using Blazor.Shared @using Blazor.Shared
@using Blazorise.DataGrid @using Blazorise.DataGrid
@using Blazored.Modal
@using Blazored.Modal.Services

Loading…
Cancel
Save