* Added maintaining Products

* Extended DataModels
* Extended API
This commit is contained in:
2025-03-29 21:37:36 +01:00
parent 15b0060c50
commit 0eaf941021
13 changed files with 237 additions and 4 deletions

View File

@@ -33,6 +33,7 @@
<SfMenu TValue="MenuItem" HamburgerMode="true" Orientation="Vertical" Title="Menu">
<MenuItems>
<MenuItem Text="Zamówienia DELFOR" Url="/" IconCss="fa-solid fa-landmark"></MenuItem>
<MenuItem Text="Zarządzanie Indeksami" Url="/Products" IconCss="fa-solid fa-basket-shopping"></MenuItem>
@* <MenuItem Text="Zamówienia klienta EDI" Url="/EdiCustomerOrders" IconCss="fa-solid fa-list-check"></MenuItem> *@
@* <MenuItem Text="Zamówienia klienta" Url="/CustomerOrders" IconCss="fa-solid fa-database"></MenuItem> *@
@if (UserName == "pkus")

View File

@@ -0,0 +1,76 @@
@page "/Products"
@using Syncfusion.Blazor.Grids
@using Syncfusion.Blazor.Cards
@using Action = Syncfusion.Blazor.Grids.Action
@inject ProductService ProductService
@inject CustomAuthenticationStateProvider CustomAuthenticationStateProvider
<div class="h-100 d-flex justify-content-center align-items-start">
<SfCard CssClass="shadow" style="width: 100%; max-width: 1200px;">
<CardHeader>
<h3 class="text-primary">Zarządzanie Indeksami</h3>
</CardHeader>
<CardContent>
<SfGrid DataSource="@_products"
AllowPaging="true"
ShowColumnMenu="true"
Toolbar="@(new List<string> { "Update" })">
<GridColumns>
<GridColumn Field="@nameof(ProductDto.ID)" AllowEditing="false" IsPrimaryKey="true" HeaderText="ID" Width="70"></GridColumn>
<GridColumn Field="@nameof(ProductDto.RecipientID)" AllowEditing="false" HeaderText="Odbiorca" Width="100"></GridColumn>
<GridColumn Field="@nameof(ProductDto.RecipientIdx)" AllowEditing="false" HeaderText="Indeks odbiorcy" Width="100"></GridColumn>
<GridColumn Field="@nameof(ProductDto.FaIdx)" HeaderText="Kod FA" Width="100"></GridColumn>
</GridColumns>
<GridEditSettings AllowEditing="true">
</GridEditSettings>
<GridEvents OnActionComplete="UserActionComplete"
TValue="ProductDto">
</GridEvents>
<GridPageSettings PageSize="10"></GridPageSettings>
</SfGrid>
</CardContent>
<CardFooter>
<small class="text-muted">FA Krosno Manager © @(DateTime.Now.Year)</small>
</CardFooter>
</SfCard>
</div>
@code {
private IEnumerable<ProductDto>? _products { get; set; }
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
// ClaimsPrincipal currentUser = CustomAuthenticationStateProvider.GetCurrentUser();
//
// if (currentUser.Identity?.IsAuthenticated == false)
// {
// NavigationManager.NavigateTo("/Unauthorized");
// }
// else
// {
await GetProducts();
// }
}
}
private async Task UserActionComplete(ActionEventArgs<ProductDto> args)
{
switch (args.RequestType)
{
case Action.Save:
await ProductService.UpdateProductAsync(args.Data);
await GetProducts();
break;
}
}
private async Task GetProducts()
{
_products = await ProductService.GetProductsByIndexAsync("Uzupelnij") ?? new List<ProductDto>();
StateHasChanged();
}
}

View File

@@ -13,7 +13,6 @@ var builder = WebApplication.CreateBuilder(args);
string faKrosnoApiUrl = builder.Configuration["FaKrosnoApiUrl"] ?? "http://localhost:5001";
builder.Services.AddSyncfusionBlazor();
builder.Services.AddBlazorBootstrap();
builder.Services.AddBlazoredLocalStorage();
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
@@ -51,6 +50,7 @@ builder.Services.AddScoped<RoleService>();
builder.Services.AddScoped<FunctionService>();
builder.Services.AddScoped<UserService>();
builder.Services.AddScoped<ErrorLogService>();
builder.Services.AddScoped<ProductService>();
var app = builder.Build();

View File

@@ -0,0 +1,25 @@
using FaKrosnoEfDataModel.Dtos;
namespace OrdersManagement.Services;
public class ProductService(IHttpClientFactory httpClientFactory, CustomAuthenticationStateProvider authenticationStateProvider)
: ServiceBase<ProductDto>(httpClientFactory, authenticationStateProvider)
{
public async Task<IEnumerable<ProductDto>?> GetProductsByIndexAsync(string indexName)
{
try
{
return await GetListAsync($"api/Product/by-index?indexName={indexName}");
}
catch (HttpRequestException ex)
{
Console.WriteLine($"Błąd HTTP w GetProductsByIndexAsync: {ex.Message}");
return null;
}
}
public async Task<HttpResponseMessage> UpdateProductAsync(ProductDto product)
{
return await PutAsJsonAsync("api/Product", product);
}
}