upraveni zobrazeni produktu
This commit is contained in:
@@ -1,25 +1,22 @@
|
|||||||
@page "/"
|
@page "/"
|
||||||
@using Microsoft.EntityFrameworkCore
|
@using Microsoft.EntityFrameworkCore
|
||||||
@using Web_Jarmark.Data
|
@using Web_Jarmark.Data
|
||||||
|
@using Web_Jarmark.Components.Pages.Shared
|
||||||
|
|
||||||
@using Web_Jarmark.Data.Models
|
@using Web_Jarmark.Data.Models
|
||||||
@inject ApplicationDbContext DbContext
|
@inject ApplicationDbContext DbContext
|
||||||
|
|
||||||
<h3>Katalog Produktů</h3>
|
<h3>Katalog Produktů</h3>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
<div class="market-grid">
|
||||||
@foreach (var product in products)
|
@foreach (var product in products)
|
||||||
{
|
{
|
||||||
<div class="col-md-4 mb-4">
|
<ProductCard
|
||||||
<div class="card">
|
Product="product"
|
||||||
<div class="card-body">
|
OnAddToCart="HandleAddToCart" />
|
||||||
<h5 class="card-title">@product.Name</h5>
|
|
||||||
<p class="card-text">Kategorie: @product.Category.Name</p>
|
|
||||||
<p class="card-text">Cena: @product.Price.ToString("C")</p>
|
|
||||||
<p class="card-text">Stock: @product.StockQuantity</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
private List<Product> products;
|
private List<Product> products;
|
||||||
@@ -30,4 +27,8 @@
|
|||||||
.Include(p => p.Category)
|
.Include(p => p.Category)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
|
private void HandleAddToCart(Product product)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Přidán produkt: {product.Name}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
@using Web_Jarmark.Data.Models
|
||||||
|
|
||||||
|
<article class="market-card">
|
||||||
|
|
||||||
|
<div class="market-product-picture">
|
||||||
|
<span class="product-icon">@ProductIcon</span>
|
||||||
|
|
||||||
|
<span class="market-product-tag">
|
||||||
|
@Product.Category.Name
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="market-card-content">
|
||||||
|
|
||||||
|
<h3>@Product.Name</h3>
|
||||||
|
|
||||||
|
<p class="market-description">
|
||||||
|
@Product.Category.Name
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="market-stock">
|
||||||
|
<span class="market-stock-dot"></span>
|
||||||
|
|
||||||
|
@if (Product.StockQuantity > 0)
|
||||||
|
{
|
||||||
|
<span>Skladem: @Product.StockQuantity ks</span>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<span>Není skladem</span>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="market-card-bottom">
|
||||||
|
<strong>@Product.Price.ToString("C")</strong>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button class="product-cart-button"
|
||||||
|
disabled="@(Product.StockQuantity <= 0)"
|
||||||
|
@onclick="AddToCart">
|
||||||
|
🛒 Do košíku
|
||||||
|
</button>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</article>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
[Parameter, EditorRequired]
|
||||||
|
public Product Product { get; set; } = default!;
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public EventCallback<Product> OnAddToCart { get; set; }
|
||||||
|
|
||||||
|
private string ProductIcon =>
|
||||||
|
Product.Category.Name.Contains("med",
|
||||||
|
StringComparison.OrdinalIgnoreCase) ? "🍯" :
|
||||||
|
Product.Category.Name.Contains("cuk",
|
||||||
|
StringComparison.OrdinalIgnoreCase) ? "🍪" :
|
||||||
|
Product.Category.Name.Contains("dřev",
|
||||||
|
StringComparison.OrdinalIgnoreCase) ? "🪵" : "🎁";
|
||||||
|
|
||||||
|
private async Task AddToCart()
|
||||||
|
{
|
||||||
|
await OnAddToCart.InvokeAsync(Product);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -334,3 +334,27 @@ h1:focus {
|
|||||||
font-size: 23px;
|
font-size: 23px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.product-cart-button {
|
||||||
|
width: 100%;
|
||||||
|
margin-top: 15px;
|
||||||
|
padding: 12px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 7px;
|
||||||
|
background: #07833e;
|
||||||
|
color: white;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: bold;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: .2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.product-cart-button:hover:not(:disabled) {
|
||||||
|
background: #056b32;
|
||||||
|
transform: translateY(-2px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.product-cart-button:disabled {
|
||||||
|
background: #aab3bd;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user