Compare commits
2 Commits
d9b571fb36
...
c1d0f1b90a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c1d0f1b90a | ||
|
|
47d4662087 |
@@ -1,25 +1,22 @@
|
||||
@page "/"
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@using Web_Jarmark.Data
|
||||
@using Web_Jarmark.Components.Pages.Shared
|
||||
|
||||
@using Web_Jarmark.Data.Models
|
||||
@inject ApplicationDbContext DbContext
|
||||
|
||||
<h3>Katalog Produktů</h3>
|
||||
<div class="row">
|
||||
<div class="market-grid">
|
||||
@foreach (var product in products)
|
||||
{
|
||||
<div class="col-md-4 mb-4">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<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>
|
||||
<ProductCard
|
||||
Product="product"
|
||||
OnAddToCart="HandleAddToCart" />
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private List<Product> products;
|
||||
@@ -30,4 +27,8 @@
|
||||
.Include(p => p.Category)
|
||||
.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>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -334,3 +334,27 @@ h1:focus {
|
||||
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