Modal added

tpBlazor
runtenick 2 years ago
parent 076c444c70
commit 2049302c56

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

@ -13,6 +13,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Blazored.LocalStorage" Version="4.2.0" /> <PackageReference Include="Blazored.LocalStorage" Version="4.2.0" />
<PackageReference Include="Blazored.Modal" Version="7.1.0" />
<PackageReference Include="Blazorise.Bootstrap" Version="1.1.2" /> <PackageReference Include="Blazorise.Bootstrap" Version="1.1.2" />
<PackageReference Include="Blazorise.DataGrid" Version="1.1.2" /> <PackageReference Include="Blazorise.DataGrid" Version="1.1.2" />
<PackageReference Include="Blazorise.Icons.FontAwesome" Version="1.1.2" /> <PackageReference Include="Blazorise.Icons.FontAwesome" Version="1.1.2" />

@ -46,6 +46,7 @@
<DataGridColumn TItem="Item" Field="@nameof(Item.Id)" Caption="Action"> <DataGridColumn TItem="Item" Field="@nameof(Item.Id)" Caption="Action">
<DisplayTemplate> <DisplayTemplate>
<a href="Edit/@(context.Id)" class="btn btn-primary"><i class="fa fa-edit"></i> Editer</a> <a href="Edit/@(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>

@ -30,5 +30,9 @@ namespace BlazorTp1.Pages
totalItem = await DataService.Count(); totalItem = await DataService.Count();
} }
} }
private void OnDelete(int id)
{
}
} }
} }

@ -34,5 +34,8 @@
<link href="_content/Blazorise/blazorise.css" rel="stylesheet" /> <link href="_content/Blazorise/blazorise.css" rel="stylesheet" />
<link href="_content/Blazorise.Bootstrap/blazorise.bootstrap.css" rel="stylesheet" /> <link href="_content/Blazorise.Bootstrap/blazorise.bootstrap.css" rel="stylesheet" />
<link href="_content/Blazored.Modal/blazored-modal.css" rel="stylesheet" />
<script src="_content/Blazored.Modal/blazored.modal.js"></script>
</body> </body>
</html> </html>

@ -3,6 +3,7 @@ using Blazorise;
using Blazorise.Bootstrap; using Blazorise.Bootstrap;
using Blazorise.Icons.FontAwesome; using Blazorise.Icons.FontAwesome;
using BlazorTp1.Data; using BlazorTp1.Data;
using Blazored.Modal;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.Web;
@ -24,6 +25,8 @@ builder.Services.AddBlazoredLocalStorage();
builder.Services.AddScoped<IDataService, DataLocalService>(); builder.Services.AddScoped<IDataService, DataLocalService>();
builder.Services.AddBlazoredModal();
var app = builder.Build(); var app = builder.Build();
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.

@ -138,4 +138,28 @@ public class DataLocalService : IDataService
// Save the data // Save the data
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<Item>>("data");
// Get the item int the list
var item = currentData.FirstOrDefault(w => w.Id == id);
// Delete item in
currentData.Remove(item);
// Delete the image
var imagePathInfo = new DirectoryInfo($"{_webHostEnvironment.WebRootPath}/images");
var fileName = new FileInfo($"{imagePathInfo}/{item.Name}.png");
if (fileName.Exists)
{
File.Delete(fileName.FullName);
}
// Save the data
await _localStorage.SetItemAsync("data", currentData);
}
} }

@ -12,4 +12,6 @@ public interface IDataService
Task<Item> GetById(int id); Task<Item> GetById(int id);
Task Update(int id, ItemModel item); Task Update(int id, ItemModel item);
Task Delete(int id);
} }

@ -9,3 +9,5 @@
@using BlazorTp1 @using BlazorTp1
@using BlazorTp1.Shared @using BlazorTp1.Shared
@using Blazorise.DataGrid @using Blazorise.DataGrid
@using Blazored.Modal
@using Blazored.Modal.Services
Loading…
Cancel
Save