master
Lilian BRETON 2 years ago
parent 94d222c754
commit fc4314df8d

File diff suppressed because one or more lines are too long

@ -1,5 +1,6 @@
@page "/inventory"
@using System.Globalization
@using myBlazorApp.Models;
<h3>Inventory</h3>
@ -7,3 +8,38 @@
<p>
<b>CurrentCulture</b>: @CultureInfo.CurrentCulture
</p>
<div id="ItemList">
<div>
<p>
List of items
</p>
@*SearchBar*@
</div>
<DataGrid TItem="Item"
Data="@items"
ReadData="@OnReadData"
TotalItems="@totalItem"
PageSize="10"
ShowPager
Responsive>
<DataGridColumn TItem="Item" Field=""/>
<DataGridColumn TItem="Item" Field="@nameof(Item.DisplayName)" Caption="Display name" />
<DataGridColumn TItem="Item" Field="@nameof(Item.Id)" Caption="Image">
<DisplayTemplate>
@if (File.Exists($"{WebHostEnvironment.WebRootPath}/images/{context.Name}.png"))
{
<img src="images/@(context.Name).png" class="img-thumbnail" title="@context.DisplayName" alt="@context.DisplayName" style="max-width: 150px"/>
}
else
{
<img src="images/default.png" class="img-thumbnail" title="@context.DisplayName" alt="@context.DisplayName" style="max-width: 150px"/>
}
</DisplayTemplate>
</DataGridColumn>
</DataGrid>
</div>

@ -1,6 +1,12 @@
using Blazored.LocalStorage;
using Blazored.Modal;
using Blazored.Modal.Services;
using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components;
using System;
using myBlazorApp.Modals;
using myBlazorApp.Models;
using myBlazorApp.Services;
namespace myBlazorApp.Pages
{
public partial class Inventory
@ -14,6 +20,52 @@ namespace myBlazorApp.Pages
[Inject]
public NavigationManager NavigationManager { get; set; }
[CascadingParameter]
public IModalService Modal { get; set; }
[Inject]
public IDataService DataService { get; set; }
private int totalItem;
private List<Item> items;
private async Task OnReadData(DataGridReadDataEventArgs<Item> e)
{
if (e.CancellationToken.IsCancellationRequested)
{
return;
}
if (!e.CancellationToken.IsCancellationRequested)
{
items = await DataService.List(e.Page, e.PageSize);
totalItem = await DataService.Count();
}
}
private async void OnDelete(int id)
{
var parameters = new ModalParameters();
parameters.Add(nameof(Item.Id), id);
var modal = Modal.Show<DeleteConfirmation>("Delete Confirmation", parameters);
var result = await modal.Result;
if (result.Cancelled)
{
return;
}
await DataService.Delete(id);
// Reload the page
NavigationManager.NavigateTo("list", true);
}
}
}

Loading…
Cancel
Save