From 8a787d55821e66952bcf909989283381bb3973d4 Mon Sep 17 00:00:00 2001 From: maja Date: Wed, 4 Nov 2026 18:02:36 +0100 Subject: [PATCH] detail vyrobku --- .../Components/Pages/DatailVyrobku.razor | 149 ++++++++++++++++- .../Components/Pages/Shared/ProductCard.razor | 4 +- Web-Jarmark/Web-Jarmark/jarmark.db-shm | Bin 32768 -> 32768 bytes Web-Jarmark/Web-Jarmark/jarmark.db-wal | Bin 799312 -> 972352 bytes Web-Jarmark/Web-Jarmark/wwwroot/app.css | 150 ++++++++++++++++++ 5 files changed, 300 insertions(+), 3 deletions(-) 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 6f904984bcdf2cc98059e2044a28f07b4e5f83f3..3838493309cf63037c1bef510babca87e7de46a2 100644 GIT binary patch delta 257 zcmZo@U}|V!s+V}A%K!pAK+MR%An*oAYXNaV@5UEbeyutF@7}GzrjOGuEns9Wyv?=8 zomBNeqrd=U?tdfz6=q_%vayk$dE$W;nu q!zG3*4A&TLFx+Ce!*Gw`0mCDPCk)RRUNF33cmvYHx_Lu+00#ghYGsuG delta 174 zcmZo@U}|V!s+V}A%K!t63=9H?fE+C#4xYH*a_0FrXa3#071;D~+NHgB;v^33O?4$z zJRGf+7(8fl7=FJu?TOub1u&mhpCbmOxvlEL0)8s9Mdq51<%^S)CH~@`f BK=l9s diff --git a/Web-Jarmark/Web-Jarmark/jarmark.db-wal b/Web-Jarmark/Web-Jarmark/jarmark.db-wal index 080c88a2ac52c06092e2b487c7735f4018f13487..ec367b6b252579d216567c8c1a4a092d00e082f0 100644 GIT binary patch delta 1516 zcmZA1TSyd97zglmSKVDNt)`G&OtGva8)xR6-8pB}b@NiatQkpCNJ7~|;SB;!!!#M9 z#EPg?gffYGNa<#xsYHZnWeZWQ)fO6PW*15q%g9Sjc4TJH!@U0ZfB)}%^K68@-x6Ob zc}ZGHCwWUglCPwf43bgull<=lWbk!1hat$2!i^QU*Xl#sALSW1Qy_#Q&oct%1rC|d zo{HF2XS-)SWB^-C_9f=DEA1Ik0e?(OS&c>$Eq|K1LD#mbiQ4Dmn;vJs_bZuJDS&}y z0U@lVVu37zSd}F>HZw0}bwW5%cv@*on)0sR?>b5p zGZZ0UEOHVcU}d6pICOcjGxac00IlfsZ+zpOH?1BD7BD~pP?Q&;VfLppy){IEwBlHu zyXx(iHH9h#GAxfUk5o!cnXbTH*Y}AiW?E@F?lV|Bb6~xvf&i8qRc(Mq?Mn4Eqrr|h2+XEF&Q%ZU&%EW()QRa+XkJa+fHX+u46Fzvk3mRxPkclJ{b zz=DP2R8xH|o%+z&qn#y=NIRzS=w+KLob&Hjl?Pz~a7dM>Gn7A3RRkTxiKm_IA)}9t z?t6{uJZ8*5003g4($DQ9JGwcCW?|zAv=fnTy?%aXG>mdAoFI>;x`i0+!!+0R+;1dL zBJDKQXFVCKXgEhXh~)$XRQ>c1ybd0m)QiNi(vE%VLvj`qqUxC!S(afrAV5L2_qOu% zGh4gLE)XY)b~>|f1UcN{)k>auM^3}ameNm7Z^`MKam^jXvC+F7M2#)7Pc1l7LFFq7OocVEj$560Ner#JOBUy 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