diff --git a/Web-Jarmark/Web-Jarmark/Components/Pages/DatailVyrobku.razor b/Web-Jarmark/Web-Jarmark/Components/Pages/DatailVyrobku.razor index 529a6e9..090b84d 100644 --- a/Web-Jarmark/Web-Jarmark/Components/Pages/DatailVyrobku.razor +++ b/Web-Jarmark/Web-Jarmark/Components/Pages/DatailVyrobku.razor @@ -1,6 +1,151 @@ -@page "/Vyrobek{Id:int}" -

DatailVyrobku

+@page "/produkt/{Id:int}" + +@using Microsoft.EntityFrameworkCore +@using Web_Jarmark.Data +@using Web_Jarmark.Data.Models + +@inject ApplicationDbContext DbContext +@inject IHttpContextAccessor HttpContextAccessor +@inject PersistentComponentState ApplicationState + +Detail produktu + +@if (loading) +{ +

Načítám produkt...

+} +else if (product == null) +{ +

Produkt nebyl nalezen.

+} +else +{ + + { +
+ ← Zpět do katalogu + +
+
+ @product.Name +
+ +
+ + @product.Category?.Name + + +

@product.Name

+ +

+ @product.Description +

+ +
+ + Skladem: @product.StockQuantity ks +
+ +
+ +
+
+ Cena produktu +
+ @product.Price.ToString("N0") Kč +
+
+ + + + +
+
+
+
+ } +} @code { + [Parameter] + public int Id { get; set; } + private Product? product; + private bool loading = true; + + protected override async Task OnParametersSetAsync() + { + loading = true; + + product = await DbContext.Products + .Include(p => p.Category) + .FirstOrDefaultAsync(p => p.Id == Id); + + loading = false; + } + private string? cartToken; + +protected override async Task OnInitializedAsync() +{ + if (!ApplicationState.TryTakeFromJson( + "CartToken", out cartToken) + || string.IsNullOrWhiteSpace(cartToken)) + { + var context = HttpContextAccessor.HttpContext; + + cartToken = context?.Items["CartToken"] as string + ?? context?.Request.Cookies["CartToken"]; + } +} + +private async Task HandleAddToCart(Product product) +{ + if (string.IsNullOrWhiteSpace(cartToken)) + return; + + var cart = await DbContext.Carts + .FirstOrDefaultAsync(c => c.Token == cartToken); + + if (cart == null) + { + cart = new Cart + { + Token = cartToken, + CreatedAt = DateTime.UtcNow, + UpdatedAt = DateTime.UtcNow + }; + + DbContext.Carts.Add(cart); + await DbContext.SaveChangesAsync(); + } + + var cartItem = await DbContext.CartItems + .FirstOrDefaultAsync(ci => + ci.CartId == cart.Id && + ci.ProductId == product.Id); + + if (cartItem != null) + { + cartItem.Quantity++; + } + else + { + cartItem = new CartItem + { + CartId = cart.Id, + ProductId = product.Id, + Quantity = 1 + }; + + DbContext.CartItems.Add(cartItem); + } + + cart.UpdatedAt = DateTime.UtcNow; + + await DbContext.SaveChangesAsync(); +} } diff --git a/Web-Jarmark/Web-Jarmark/Components/Pages/Shared/ProductCard.razor b/Web-Jarmark/Web-Jarmark/Components/Pages/Shared/ProductCard.razor index 3d9c630..9da89ea 100644 --- a/Web-Jarmark/Web-Jarmark/Components/Pages/Shared/ProductCard.razor +++ b/Web-Jarmark/Web-Jarmark/Components/Pages/Shared/ProductCard.razor @@ -23,7 +23,9 @@
-

@Product.Name

+ +

@Product.Name

+
@if (!string.IsNullOrWhiteSpace(Product.Description)) { diff --git a/Web-Jarmark/Web-Jarmark/jarmark.db-shm b/Web-Jarmark/Web-Jarmark/jarmark.db-shm index 6f90498..3838493 100644 Binary files a/Web-Jarmark/Web-Jarmark/jarmark.db-shm and b/Web-Jarmark/Web-Jarmark/jarmark.db-shm differ diff --git a/Web-Jarmark/Web-Jarmark/jarmark.db-wal b/Web-Jarmark/Web-Jarmark/jarmark.db-wal index 080c88a..ec367b6 100644 Binary files a/Web-Jarmark/Web-Jarmark/jarmark.db-wal and b/Web-Jarmark/Web-Jarmark/jarmark.db-wal differ diff --git a/Web-Jarmark/Web-Jarmark/wwwroot/app.css b/Web-Jarmark/Web-Jarmark/wwwroot/app.css index 28b71e4..442c80c 100644 --- a/Web-Jarmark/Web-Jarmark/wwwroot/app.css +++ b/Web-Jarmark/Web-Jarmark/wwwroot/app.css @@ -2653,5 +2653,155 @@ textarea.wj-input { font-weight: 700; transition: background 0.2s ease; } +.product-detail-link { + color: inherit; + text-decoration: none; +} + .product-detail-link:hover { + text-decoration: underline; + } +.detail-container { + max-width: 1150px; + margin: 45px auto; + padding: 0 20px; +} + +.back-link { + display: inline-block; + margin-bottom: 22px; + color: #777; + text-decoration: none; + font-weight: 600; +} + + .back-link:hover { + color: #222; + } + +.detail-card { + display: grid; + grid-template-columns: 1fr 1fr; + gap: 45px; + padding: 35px; + background: white; + border-radius: 20px; + box-shadow: 0 8px 35px rgba(0,0,0,0.07); +} + +.detail-image { + display: flex; + align-items: center; + justify-content: center; + min-height: 400px; + background: #f5f5f5; + border-radius: 16px; + overflow: hidden; +} + + .detail-image img { + width: 100%; + height: 400px; + object-fit: contain; + } + +.detail-info { + display: flex; + flex-direction: column; + justify-content: center; +} + +.detail-category { + color: #777; + font-size: 14px; + font-weight: 600; + text-transform: uppercase; +} + +.detail-info h1 { + margin: 12px 0; + font-size: 34px; + color: #222; +} + +.detail-description { + color: #666; + line-height: 1.7; + font-size: 16px; +} + +.detail-stock { + margin-top: 20px; + display: flex; + align-items: center; + gap: 9px; + color: #333; + font-weight: 600; +} + +.stock-dot { + width: 10px; + height: 10px; + border-radius: 50%; + background: #22a06b; +} + +.detail-divider { + height: 1px; + background: #eee; + margin: 25px 0; +} + +.detail-bottom { + display: flex; + align-items: center; + justify-content: space-between; + gap: 15px; +} + +.price-label { + color: #888; + font-size: 13px; +} + +.detail-price { + font-size: 30px; + font-weight: 800; + color: #222; +} + +.detail-cart-button { + padding: 15px 22px; + border: none; + border-radius: 10px; + background: #222; + color: white; + font-size: 15px; + font-weight: 700; + cursor: not-allowed; + opacity: 0.6; +} + +@media (max-width: 750px) { + .detail-card { + grid-template-columns: 1fr; + padding: 18px; + gap: 25px; + } + + .detail-image, + .detail-image img { + min-height: 250px; + height: 250px; + } + + .detail-info h1 { + font-size: 26px; + } + + .detail-bottom { + flex-direction: column; + align-items: stretch; + } +} \ No newline at end of file