Compare commits

...

59 Commits

Author SHA1 Message Date
maja
e476e36855 zmena pro lidi 2026-11-25 17:36:29 +01:00
Ondur
69a8138226 objednavky 2026-11-18 18:14:43 +01:00
Ondur
b6f81a12ea ZMENY 2026-11-18 17:47:44 +01:00
Ondur
28316b58ab program 2026-11-18 17:33:30 +01:00
maja
2c593a53a1 data 2026-11-18 17:28:09 +01:00
maja
fe1487a1f5 datasbaze 2026-11-18 17:27:18 +01:00
Ondur
26c82eca08 oprava tokenu 2026-11-18 17:26:16 +01:00
Ondur
217adaba63 Merge branch 'main' of https://git.vedetvic.cz/Ondur/Web-Jarmark 2026-11-11 18:34:53 +01:00
Ondur
083da573e0 hodne admin 2026-11-11 18:34:51 +01:00
maja
e212712cac ... 2026-11-11 18:31:33 +01:00
maja
e5bc6cfbc0 ... 2026-11-11 18:29:11 +01:00
Ondur
dc74a416d0 macinka 2026-11-11 18:04:02 +01:00
Ondur
bfd3b54154 moc moc mocinky zmen jako macinka 2026-11-11 18:03:36 +01:00
maja
31de50c40a upraveni uziv. rozhrani 2026-11-11 18:02:50 +01:00
Ondur
acce73329a nevmenu 2026-11-11 17:20:50 +01:00
Ondur
8e6a4db0ad ... 2026-11-11 17:19:33 +01:00
Ondur
1dad6cc160 Merge branch 'main' of https://git.vedetvic.cz/Ondur/Web-Jarmark 2026-11-11 17:16:22 +01:00
Ondur
89fd7a2f46 admin 2026-11-11 17:16:20 +01:00
maja
f583062d54 zemny 2026-11-11 17:00:26 +01:00
Ondur
257fd7481a admin 2026-11-11 16:53:32 +01:00
Marek Jarolimek
1506bfcf09 hezci disgn katalogu a uvodi stranky 2026-11-07 09:48:25 +01:00
Marek Jarolimek
b3a5f42980 Po kliknuti na celou kartu se otevre detail produtu 2026-11-06 20:51:23 +01:00
Marek Jarolimek
66489a918f uprvaveni onfa kosik i v deteil vyrovku 2026-11-06 20:45:16 +01:00
Marek Jarolimek
4dcec14dac pridani onfo o kosiku 2026-11-06 20:26:09 +01:00
Marek Jarolimek
7e77301838 Pridani info o tom ze jsi neco pridal do kosiku 2026-11-06 20:23:46 +01:00
Marek Jarolimek
2ad874af33 odstraneni FF z bocniho menu 2026-11-06 20:14:36 +01:00
Marek Jarolimek
ec94b0320d objednavky detail pro admin 2026-11-06 19:55:20 +01:00
Marek Jarolimek
2d1ee8338e udelani detail objednavek a pokracovat v objednavce 2026-11-06 19:17:22 +01:00
maja
ce3fa4f689 vytovreni stranky nobaobjed 2026-11-04 18:43:20 +01:00
maja
2a2baba4a4 vytvoreni stranky nova objednavkja 2026-11-04 18:41:47 +01:00
Ondur
83488e97a9 admin prava 2026-11-04 18:40:50 +01:00
Ondur
fcaf17eacd admin 2026-11-04 18:18:30 +01:00
Ondur
59c47f2b03 admin 2026-11-04 18:18:12 +01:00
maja
1a8a3ee563 zmena barvz do kosiku 2026-11-04 18:17:49 +01:00
Ondur
962aad7c86 admin 2026-11-04 18:07:22 +01:00
Ondur
1d546191c1 vylepsteni admin 2026-11-04 18:05:15 +01:00
Ondur
e4550576df vylepseni admin 2026-11-04 18:04:23 +01:00
maja
8a787d5582 detail vyrobku 2026-11-04 18:02:36 +01:00
maja
3a60f670ba pridani tlacitka zobarazit kosik 2026-11-04 17:15:16 +01:00
maja
7e2d20d889 upraveni kosiku aby to bylo hezci 2026-10-30 17:12:28 +01:00
xpohlk
312192a6d6 Oprava stylu 2026-10-30 17:08:02 +01:00
maja
2c3d52299c Merge branch 'main' of https://git.vedetvic.cz/Ondur/Web-Jarmark 2026-10-30 16:47:55 +01:00
maja
1a66b745da skoro celej kosik finish 2026-10-30 16:47:52 +01:00
Ondur
52d75a0af8 Merge branch 'main' of https://git.vedetvic.cz/Ondur/Web-Jarmark 2026-10-30 16:31:03 +01:00
Ondur
9f9742f03e předělání admin 2026-10-30 16:31:00 +01:00
maja
1a3af9ad7f cookie pro kosik 2026-10-30 16:18:05 +01:00
maja
aedfaa45a6 databaze kosik 2026-10-30 15:25:31 +01:00
Ondur
89ad85f185 databaze 2026-10-30 15:05:40 +01:00
maja
38bb28e417 upraveni bocniho menu 2026-10-30 15:04:21 +01:00
maja
f42aaba9c0 dokonceni zobrazeni produktu 2026-10-30 14:53:42 +01:00
Ondur
e73b373e46 zmeny 2026-10-30 14:46:17 +01:00
maja
5aa554e0a6 upravenu katagu 2026-10-30 14:35:22 +01:00
maja
1af2d7507f Merge branch 'main' of https://git.vedetvic.cz/Ondur/Web-Jarmark 2026-10-30 14:33:14 +01:00
maja
9d74272a62 . 2026-10-30 14:33:11 +01:00
Ondur
46364865cb upraveni administrrace 2026-10-30 14:32:20 +01:00
maja
c1d0f1b90a slouceni 2026-10-30 14:25:37 +01:00
maja
47d4662087 upraveni zobrazeni produktu 2026-10-30 14:23:39 +01:00
Ondur
d9b571fb36 Admin předělání 2026-10-30 14:07:39 +01:00
Ondur
a54f265e29 predělání admin 2026-10-30 13:58:21 +01:00
47 changed files with 17285 additions and 840 deletions

2
.gitignore vendored
View File

@@ -414,3 +414,5 @@ FodyWeavers.xsd
# Built Visual Studio Code Extensions
*.vsix
/Web-Jarmark/Web-Jarmark/jarmark.db-shm
/Web-Jarmark/Web-Jarmark/jarmark.db-wal

View File

@@ -127,7 +127,7 @@
if (result.Succeeded)
{
Logger.LogInformation("User logged in.");
RedirectManager.RedirectTo(ReturnUrl);
RedirectManager.RedirectTo(string.IsNullOrWhiteSpace(ReturnUrl) ? "admin" : ReturnUrl);
}
else if (result.RequiresTwoFactor)
{

View File

@@ -6,37 +6,21 @@
@inject UserManager<ApplicationUser> UserManager
@inject IdentityRedirectManager RedirectManager
<PageTitle>Personal Data</PageTitle>
<PageTitle>Osobní údaje</PageTitle>
<StatusMessage />
<h3>Personal Data</h3>
<h3>Osobní údaje</h3>
<p>
V účtu jsou uložené osobní údaje, které jsi zadal. Tady si je můžeš stáhnout nebo účet smazat.
</p>
<p>
<strong>Smazání údajů trvale odstraní účet a nelze to vrátit zpět.</strong>
</p>
<div class="row">
<div class="col-md-6">
<p>Your account contains personal data that you have given us. This page allows you to download or delete that data.</p>
<p>
<strong>Deleting this data will permanently remove your account, and this cannot be recovered.</strong>
</p>
<form action="Account/Manage/DownloadPersonalData" method="post">
<div class="manage-actions">
<form method="post" action="Account/Manage/DownloadPersonalData">
<AntiforgeryToken />
<button class="btn btn-primary" type="submit">Download</button>
<button type="submit" class="btn btn-primary">Stáhnout data</button>
</form>
<p>
<a href="Account/Manage/DeletePersonalData" class="btn btn-danger">Delete</a>
</p>
</div>
<a class="btn btn-primary" href="Account/Manage/DeletePersonalData">Smazat účet</a>
</div>
@code {
[CascadingParameter]
private HttpContext HttpContext { get; set; } = default!;
protected override async Task OnInitializedAsync()
{
var user = await UserManager.GetUserAsync(HttpContext.User);
if (user is null)
{
RedirectManager.RedirectToInvalidUser(UserManager, HttpContext);
}
}
}

View File

@@ -1,17 +1,23 @@
@inherits LayoutComponentBase
@layout Web_Jarmark.Components.Layout.MainLayout
@layout Web_Jarmark.Components.Layout.Admin.AdminLayout
@using Microsoft.AspNetCore.Authorization
<h1>Manage your account</h1>
@attribute [Authorize(Roles = "Admin")]
<div>
<h2>Change your account settings</h2>
<hr />
<div class="row">
<div class="col-lg-3">
<div class="ap ao manage-shell">
<header class="ao-hero">
<p class="ao-eyebrow">Účet</p>
<h1>Správa účtu</h1>
<p class="ao-sub">Profil, heslo a zabezpečení.</p>
</header>
<div class="manage-grid">
<aside class="manage-nav-card">
<p class="manage-nav-title">Nastavení</p>
<ManageNavMenu />
</div>
<div class="col-lg-9">
</aside>
<section class="manage-content-card">
@Body
</div>
</section>
</div>
</div>

View File

@@ -1,34 +1,23 @@
@using Microsoft.AspNetCore.Identity
@using Web_Jarmark.Data
@inject SignInManager<ApplicationUser> SignInManager
<ul class="nav nav-pills flex-column">
<li class="nav-item">
<NavLink class="nav-link" href="Account/Manage" Match="NavLinkMatch.All">Profile</NavLink>
</li>
<li class="nav-item">
<NavLink class="nav-link" href="Account/Manage/Email">Email</NavLink>
</li>
<li class="nav-item">
<NavLink class="nav-link" href="Account/Manage/ChangePassword">Password</NavLink>
</li>
<nav class="manage-nav">
<NavLink class="manage-nav-link" href="Account/Manage" Match="NavLinkMatch.All">Profil</NavLink>
<NavLink class="manage-nav-link" href="Account/Manage/Email">E-mail</NavLink>
<NavLink class="manage-nav-link" href="Account/Manage/ChangePassword">Heslo</NavLink>
@if (hasExternalLogins)
{
<li class="nav-item">
<NavLink class="nav-link" href="Account/Manage/ExternalLogins">External logins</NavLink>
</li>
<NavLink class="manage-nav-link" href="Account/Manage/ExternalLogins">Externí přihlášení</NavLink>
}
<li class="nav-item">
<NavLink class="nav-link" href="Account/Manage/TwoFactorAuthentication">Two-factor authentication</NavLink>
</li>
<li class="nav-item">
<NavLink class="nav-link" href="Account/Manage/Passkeys">Passkeys</NavLink>
</li>
<li class="nav-item">
<NavLink class="nav-link" href="Account/Manage/PersonalData">Personal data</NavLink>
</li>
</ul>
<NavLink class="manage-nav-link" href="Account/Manage/TwoFactorAuthentication">2FA</NavLink>
<NavLink class="manage-nav-link" href="Account/Manage/Passkeys">Passkeys</NavLink>
<NavLink class="manage-nav-link" href="Account/Manage/PersonalData">Osobní údaje</NavLink>
<a class="manage-nav-link manage-nav-back" href="/admin">← Admin</a>
</nav>
@code {
private bool hasExternalLogins;

View File

@@ -0,0 +1,89 @@
@inherits LayoutComponentBase
@implements IDisposable
@inject NavigationManager Nav
<div class="admin-shell @(collapsed ? "is-collapsed" : null)">
<aside class="admin-sidebar">
<div class="admin-sidebar-head">
<a href="/admin" class="admin-logo">
<span class="admin-logo-mark">W</span>
<span class="admin-logo-text">Web-Jarmark</span>
</a>
<button type="button"
class="admin-toggle"
title="@(collapsed ? "Rozbalit" : "Sbalit")"
@onclick="Toggle">
☰
</button>
</div>
<AdminNavMenu />
<div class="admin-sidebar-foot">
<div class="admin-foot-card">
<span class="admin-logo-mark small">W</span>
<div class="admin-foot-text">
<strong>Web-Jarmark</strong>
<small>Administrace</small>
</div>
</div>
</div>
</aside>
<div class="admin-main">
<header class="admin-topbar">
<div class="admin-topbar-title">@SectionTitle</div>
<div class="admin-topbar-user">
<span class="admin-dot"></span>
<span>Administrátor</span>
</div>
</header>
<main class="admin-content">
@Body
</main>
</div>
</div>
@code {
private bool collapsed;
private string SectionTitle = "Přehled";
private void Toggle() => collapsed = !collapsed;
protected override void OnInitialized()
{
UpdateTitle();
Nav.LocationChanged += OnLocationChanged;
}
private void OnLocationChanged(object? sender, LocationChangedEventArgs e)
{
UpdateTitle();
_ = InvokeAsync(StateHasChanged);
}
private void UpdateTitle()
{
var path = "/" + Nav.ToBaseRelativePath(Nav.Uri).Split('?', '#')[0].Trim('/');
SectionTitle = path switch
{
"/admin" => "Přehled",
var p when p.StartsWith("/admin/kategorie") => "Kategorie",
var p when p.StartsWith("/admin/zbozi") => "Zboží",
var p when p.StartsWith("/admin/objednavky") => "Objednávky",
var p when p.StartsWith("/admin/administratori") => "Administrátoři",
var p when p.StartsWith("/admin/sklad") => "Sklad",
var p when p.StartsWith("/admin/statistiky") => "Statistiky",
var p when p.StartsWith("/admin/nastaveni") => "Nastavení",
_ => "Administrace"
};
}
public void Dispose()
{
Nav.LocationChanged -= OnLocationChanged;
}
}

View File

@@ -0,0 +1,279 @@
/* Apple-like admin – plovoucí, hodně zaoblené */
.admin-shell {
--bg: #f5f5f7;
--ink: #1d1d1f;
--muted: #6e6e73;
--line: rgba(0, 0, 0, 0.06);
--sidebar-w: 280px;
--sidebar-w-collapsed: 92px;
min-height: 100vh;
display: flex;
gap: 14px;
padding: 14px;
box-sizing: border-box;
background: var(--bg);
color: var(--ink);
font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
-webkit-font-smoothing: antialiased;
}
/* ===== SIDEBAR CARD ===== */
.admin-sidebar {
width: var(--sidebar-w);
flex-shrink: 0;
position: sticky;
top: 14px;
height: calc(100vh - 28px);
display: flex;
flex-direction: column;
background: rgba(255, 255, 255, 0.86);
border: 1px solid rgba(0, 0, 0, 0.04);
border-radius: 28px;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.05);
backdrop-filter: blur(18px);
overflow: hidden;
transition: width 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.admin-shell.is-collapsed .admin-sidebar {
width: var(--sidebar-w-collapsed);
}
.admin-sidebar-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
padding: 18px 16px 12px;
}
.admin-logo {
display: flex;
align-items: center;
gap: 12px;
text-decoration: none;
color: var(--ink);
min-width: 0;
}
.admin-logo-mark {
width: 40px;
height: 40px;
border-radius: 14px;
background: #1d1d1f;
color: #fff;
display: grid;
place-items: center;
font-weight: 800;
font-size: 15px;
flex-shrink: 0;
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}
.admin-logo-mark.small {
width: 32px;
height: 32px;
border-radius: 11px;
font-size: 12px;
}
.admin-logo-text {
font-weight: 700;
font-size: 16px;
letter-spacing: -0.03em;
white-space: nowrap;
}
.admin-toggle {
width: 38px;
height: 38px;
border: 0;
border-radius: 13px;
background: #f0f0f2;
color: var(--ink);
cursor: pointer;
flex-shrink: 0;
transition: background 0.2s ease, transform 0.15s ease;
}
.admin-toggle:hover {
background: #e6e6ea;
transform: scale(1.03);
}
/* NAV */
::deep .admin-nav {
display: flex;
flex-direction: column;
gap: 6px;
padding: 8px 12px 12px;
flex: 1;
overflow-y: auto;
}
::deep .admin-nav-link {
display: flex;
align-items: center;
gap: 12px;
padding: 13px 14px;
border-radius: 16px;
text-decoration: none;
color: var(--muted);
font-weight: 600;
font-size: 14px;
letter-spacing: -0.01em;
transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
white-space: nowrap;
}
::deep .admin-nav-link:hover {
background: rgba(0, 0, 0, 0.04);
color: var(--ink);
}
::deep .admin-nav-link.active {
background: #1d1d1f;
color: #fff;
box-shadow: 0 10px 24px rgba(0, 0, 0, 0.14);
}
::deep .admin-nav-ico {
width: 22px;
text-align: center;
flex-shrink: 0;
font-size: 15px;
}
::deep .admin-nav-label {
overflow: hidden;
}
/* FOOT */
.admin-sidebar-foot {
padding: 10px 12px 14px;
}
.admin-foot-card {
display: flex;
align-items: center;
gap: 10px;
padding: 12px;
border-radius: 18px;
background: #f5f5f7;
}
.admin-foot-text {
min-width: 0;
overflow: hidden;
}
.admin-foot-text strong {
display: block;
font-size: 13px;
font-weight: 700;
letter-spacing: -0.02em;
}
.admin-foot-text small {
display: block;
font-size: 11px;
color: var(--muted);
}
/* ===== MAIN CARD ===== */
.admin-main {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
background: rgba(255, 255, 255, 0.72);
border: 1px solid rgba(0, 0, 0, 0.04);
border-radius: 28px;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.04);
backdrop-filter: blur(18px);
overflow: hidden;
}
.admin-topbar {
height: 68px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
padding: 0 28px;
border-bottom: 1px solid rgba(0, 0, 0, 0.05);
background: rgba(255, 255, 255, 0.55);
}
.admin-topbar-title {
font-size: 20px;
font-weight: 700;
letter-spacing: -0.03em;
}
.admin-topbar-user {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 12px;
border-radius: 999px;
background: #f5f5f7;
font-size: 13px;
font-weight: 600;
color: var(--muted);
}
.admin-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #1d1d1f;
}
.admin-content {
padding: 22px 28px 36px;
flex: 1;
overflow: auto;
}
/* Collapsed */
.admin-shell.is-collapsed .admin-logo-text,
.admin-shell.is-collapsed ::deep .admin-nav-label,
.admin-shell.is-collapsed .admin-foot-text {
display: none;
}
.admin-shell.is-collapsed ::deep .admin-nav-link {
justify-content: center;
padding-left: 0;
padding-right: 0;
}
.admin-shell.is-collapsed .admin-sidebar-head {
justify-content: center;
flex-direction: column;
}
.admin-shell.is-collapsed .admin-foot-card {
justify-content: center;
}
.admin-shell.is-collapsed .admin-logo {
justify-content: center;
}
/* SVG ikony v menu */
::deep .admin-nav-ico {
width: 22px;
height: 22px;
display: inline-flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
::deep .admin-nav-ico svg {
width: 20px;
height: 20px;
display: block;
}

View File

@@ -0,0 +1,127 @@
@implements IDisposable
@inject NavigationManager Nav
<nav class="admin-nav">
<a href="/" class="admin-nav-link">
<span class="admin-nav-ico" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<path d="M15 18 9 12l6-6" />
</svg>
</span>
<span class="admin-nav-label">E-shop</span>
</a>
<a href="/admin" class="admin-nav-link @(IsCurrent("/admin", true) ? "active" : null)">
<span class="admin-nav-ico" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<path d="M4 10.5 12 4l8 6.5V20a1 1 0 0 1-1 1h-5v-6H10v6H5a1 1 0 0 1-1-1v-9.5Z" />
</svg>
</span>
<span class="admin-nav-label">Přehled</span>
</a>
<a href="/admin/kategorie" class="admin-nav-link @(IsCurrent("/admin/kategorie") ? "active" : null)">
<span class="admin-nav-ico" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<rect x="4" y="4" width="7" height="7" rx="1.5" />
<rect x="13" y="4" width="7" height="7" rx="1.5" />
<rect x="4" y="13" width="7" height="7" rx="1.5" />
<rect x="13" y="13" width="7" height="7" rx="1.5" />
</svg>
</span>
<span class="admin-nav-label">Kategorie</span>
</a>
<a href="/admin/zbozi" class="admin-nav-link @(IsCurrent("/admin/zbozi") ? "active" : null)">
<span class="admin-nav-ico" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<path d="M7 7h10l1.2 12.2a1.5 1.5 0 0 1-1.5 1.6H7.3a1.5 1.5 0 0 1-1.5-1.6L7 7Z" />
<path d="M9 7a3 3 0 0 1 6 0" />
</svg>
</span>
<span class="admin-nav-label">Zboží</span>
</a>
<a href="/admin/objednavky" class="admin-nav-link @(IsCurrent("/admin/objednavky") ? "active" : null)">
<span class="admin-nav-ico" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<path d="M7 4h10a2 2 0 0 1 2 2v14l-3-2-3 2-3-2-3 2V6a2 2 0 0 1 2-2Z" />
<path d="M9 9h6M9 13h6" />
</svg>
</span>
<span class="admin-nav-label">Objednávky</span>
</a>
<a href="/admin/administratori" class="admin-nav-link @(IsCurrent("/admin/administratori") ? "active" : null)">
<span class="admin-nav-ico" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="8" r="3.5" />
<path d="M5.5 19a6.5 6.5 0 0 1 13 0" />
</svg>
</span>
<span class="admin-nav-label">Administrátoři</span>
</a>
<a href="/admin/sklad" class="admin-nav-link @(IsCurrent("/admin/sklad") ? "active" : null)">
<span class="admin-nav-ico" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<path d="M4 8.5 12 4l8 4.5V19a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V8.5Z" />
<path d="M12 12v8M8 10.5 12 12l4-1.5" />
</svg>
</span>
<span class="admin-nav-label">Sklad</span>
</a>
<a href="/admin/statistiky" class="admin-nav-link @(IsCurrent("/admin/statistiky") ? "active" : null)">
<span class="admin-nav-ico" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<path d="M5 19V11M12 19V5M19 19v-7" />
</svg>
</span>
<span class="admin-nav-label">Statistiky</span>
</a>
<a href="/admin/nastaveni" class="admin-nav-link @(IsCurrent("/admin/nastaveni") ? "active" : null)">
<span class="admin-nav-ico" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="3" />
<path d="M12 3.5v2.2M12 18.3v2.2M4.9 6.4l1.6 1.6M17.5 16l1.6 1.6M3.5 12h2.2M18.3 12h2.2M4.9 17.6l1.6-1.6M17.5 8l1.6-1.6" />
</svg>
</span>
<span class="admin-nav-label">Nastavení</span>
</a>
</nav>
@code {
private string CurrentPath => "/" +
Nav.ToBaseRelativePath(Nav.Uri)
.Split('?')[0]
.Split('#')[0]
.Trim('/');
private bool IsCurrent(string path, bool exact = false)
{
var current = CurrentPath;
if (exact)
return current.Equals(path, StringComparison.OrdinalIgnoreCase);
return current.Equals(path, StringComparison.OrdinalIgnoreCase)
|| current.StartsWith(path + "/", StringComparison.OrdinalIgnoreCase);
}
protected override void OnInitialized()
{
Nav.LocationChanged += HandleLocationChanged;
}
private void HandleLocationChanged(object? sender, LocationChangedEventArgs e)
{
_ = InvokeAsync(StateHasChanged);
}
public void Dispose()
{
Nav.LocationChanged -= HandleLocationChanged;
}
}

View File

@@ -1,23 +1,41 @@
@inherits LayoutComponentBase
<div class="page">
<div class="sidebar">
<div class="page public-layout">
<a href="#public-main-content"
class="public-skip-link visually-hidden-focusable">
Přeskočit na hlavní obsah
</a>
<header class="sidebar public-header">
<NavMenu />
</div>
</header>
<main>
<div class="top-row px-4">
<a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a>
</div>
<main id="public-main-content"
class="main-content public-main"
tabindex="-1">
<article class="content px-4">
<article class="content public-container">
@Body
</article>
</main>
</div>
<div id="blazor-error-ui" data-nosnippet>
An unhandled error has occurred.
<a href="." class="reload">Reload</a>
<span class="dismiss">🗙</span>
<span role="alert">
Nastala neočekávaná chyba.
</span>
<a href="." class="reload">
Obnovit stránku
</a>
<button type="button"
class="dismiss"
aria-label="Zavřít chybové hlášení"
style="background: none; border: none; color: inherit;">
&#215;
</button>
</div>

View File

@@ -1,98 +1,406 @@
.page {
/* ========================================
SKOLNI JARMARK - PUBLIC LAYOUT
======================================== */
.page.public-layout {
--public-primary: #244b36;
--public-primary-hover: #193b29;
--public-secondary: #e6eddf;
--public-background: #f7f7f2;
--public-surface: #ffffff;
--public-text: #26372b;
--public-muted: #59665b;
--public-border: #dce3d9;
--public-radius-sm: 4px;
--public-radius-md: 8px;
--public-radius-lg: 12px;
--public-space-1: 4px;
--public-space-2: 8px;
--public-space-3: 12px;
--public-space-4: 16px;
--public-space-5: 20px;
--public-space-6: 24px;
--public-space-8: 32px;
--public-space-12: 48px;
--public-space-16: 64px;
position: relative;
display: flex;
flex-direction: column;
align-items: stretch;
width: 100%;
min-width: 0;
min-height: 100vh;
min-height: 100dvh;
margin: 0;
padding: 0;
background: var(--public-background);
color: var(--public-text);
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
font-size: 16px;
line-height: 1.6;
box-sizing: border-box;
}
main {
flex: 1;
/* ========================================
BOX SIZING
======================================== */
.public-layout,
.public-layout ::deep *,
.public-layout ::deep *::before,
.public-layout ::deep *::after {
box-sizing: border-box;
}
.sidebar {
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
}
.top-row {
background-color: #f7f7f7;
border-bottom: 1px solid #d6d5d5;
justify-content: flex-end;
height: 3.5rem;
display: flex;
align-items: center;
}
/* ========================================
PUBLIC HEADER - OVERLAP FIX
======================================== */
.top-row ::deep a, .top-row ::deep .btn-link {
white-space: nowrap;
margin-left: 1.5rem;
text-decoration: none;
.public-layout > .sidebar.public-header {
position: relative !important;
top: auto !important;
right: auto !important;
bottom: auto !important;
left: auto !important;
display: block;
flex: 0 0 auto;
align-self: stretch;
width: 100% !important;
min-width: 0 !important;
max-width: 100%;
height: auto !important;
min-height: 0 !important;
max-height: none;
margin: 0;
padding: 0;
background: var(--public-surface);
border-right: none !important;
border-bottom: 1px solid var(--public-border);
transform: none;
z-index: 100;
}
.top-row ::deep a:hover, .top-row ::deep .btn-link:hover {
/* ========================================
NAVIGATION CONTAINER
======================================== */
.public-header ::deep .nav-panel {
position: relative;
width: 100%;
min-width: 0;
height: auto;
min-height: 68px;
max-height: none;
margin: 0 auto;
}
.public-header ::deep .nav-scrollable {
position: static;
height: auto;
min-height: 0;
max-height: none;
overflow: visible;
}
/* ========================================
MAIN CONTENT - OVERLAP FIX
======================================== */
.public-layout > .main-content.public-main {
position: relative !important;
top: auto;
left: auto;
right: auto;
bottom: auto;
display: block;
flex: 1 0 auto;
width: 100% !important;
min-width: 0;
max-width: 100%;
height: auto;
min-height: 0;
margin: 0 !important;
padding: 0 !important;
background: var(--public-background);
transform: none;
scroll-margin-top: 16px;
}
/* ========================================
CONTENT CONTAINER
======================================== */
.public-main > .content.public-container {
position: relative;
display: block;
width: 100%;
max-width: 1440px;
min-width: 0;
margin: 0 auto !important;
padding: 32px 32px 64px !important;
box-sizing: border-box;
}
/* ========================================
TYPOGRAPHY
======================================== */
.public-container ::deep h1,
.public-container ::deep h2,
.public-container ::deep h3 {
color: var(--public-text);
font-family: Georgia, "Times New Roman", serif;
font-weight: 700;
line-height: 1.2;
letter-spacing: normal;
}
.public-container ::deep h1 {
font-size: clamp(28px, 4vw, 44px);
}
.public-container ::deep h2 {
font-size: clamp(24px, 3vw, 32px);
}
.public-container ::deep h3 {
font-size: clamp(18px, 2vw, 24px);
}
.public-container ::deep p {
line-height: 1.6;
}
/* ========================================
LINKS
======================================== */
.public-container ::deep a {
text-underline-offset: 3px;
}
/* ========================================
KEYBOARD ACCESSIBILITY
======================================== */
.public-layout ::deep a:focus-visible,
.public-layout ::deep button:focus-visible,
.public-layout ::deep input:focus-visible,
.public-layout ::deep select:focus-visible,
.public-layout ::deep textarea:focus-visible,
.public-layout ::deep [tabindex]:focus-visible {
outline: 3px solid #527b49;
outline-offset: 3px;
}
.public-main:focus-visible {
outline: 3px solid #527b49;
outline-offset: -3px;
}
/* ========================================
SKIP NAVIGATION LINK
======================================== */
.public-skip-link {
position: absolute;
top: 12px;
left: 12px;
z-index: 1100;
width: 1px;
height: 1px;
padding: 0;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
.public-skip-link:focus {
width: auto;
height: auto;
padding: 12px 16px;
overflow: visible;
clip-path: none;
background: var(--public-primary);
color: #ffffff;
border-radius: var(--public-radius-md);
font-size: 14px;
font-weight: 600;
text-decoration: none;
white-space: normal;
}
/* ========================================
BLAZOR ERROR MESSAGE
======================================== */
#blazor-error-ui {
display: none;
position: fixed;
left: 0;
right: 0;
bottom: 0;
z-index: 1000;
width: 100%;
padding: 16px 56px 16px 24px;
background: #fff4d6;
color: #58451b;
border-top: 1px solid #e5d4a1;
box-sizing: border-box;
color-scheme: light;
font-size: 14px;
line-height: 1.5;
}
#blazor-error-ui .reload {
display: inline-block;
margin-left: 8px;
color: #244b36;
font-weight: 700;
text-decoration: underline;
}
.top-row ::deep a:first-child {
overflow: hidden;
text-overflow: ellipsis;
}
@media (max-width: 640.98px) {
.top-row {
justify-content: space-between;
}
.top-row ::deep a, .top-row ::deep .btn-link {
margin-left: 0;
}
}
@media (min-width: 641px) {
.page {
flex-direction: row;
}
.sidebar {
width: 250px;
height: 100vh;
position: sticky;
top: 0;
}
.top-row {
position: sticky;
top: 0;
z-index: 1;
}
.top-row.auth ::deep a:first-child {
flex: 1;
text-align: right;
width: 0;
}
.top-row, article {
padding-left: 2rem !important;
padding-right: 1.5rem !important;
}
}
#blazor-error-ui {
color-scheme: light only;
background: lightyellow;
bottom: 0;
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
box-sizing: border-box;
display: none;
left: 0;
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
position: fixed;
width: 100%;
z-index: 1000;
}
#blazor-error-ui .dismiss {
cursor: pointer;
position: absolute;
right: 0.75rem;
top: 0.5rem;
top: 50%;
right: 8px;
transform: translateY(-50%);
display: flex;
align-items: center;
justify-content: center;
width: 44px;
height: 44px;
padding: 0;
background: transparent;
color: #58451b;
border: none;
border-radius: 4px;
font-size: 24px;
cursor: pointer;
}
#blazor-error-ui .dismiss:focus-visible,
#blazor-error-ui .reload:focus-visible {
outline: 3px solid #527b49;
outline-offset: 2px;
}
/* ========================================
TABLET - MAX 1024 PX
======================================== */
@media (max-width: 1024px) {
.public-main > .content.public-container {
padding: 24px 24px 48px !important;
}
.public-layout > .sidebar.public-header {
position: relative !important;
width: 100% !important;
height: auto !important;
min-height: 0 !important;
}
}
/* ========================================
MOBILE - MAX 640 PX
======================================== */
@media (max-width: 640px) {
.page.public-layout {
flex-direction: column;
width: 100%;
font-size: 15px;
}
.public-layout > .sidebar.public-header {
position: relative !important;
top: auto !important;
width: 100% !important;
min-width: 0 !important;
height: auto !important;
min-height: 0 !important;
}
.public-layout > .main-content.public-main {
width: 100% !important;
min-width: 0;
margin: 0 !important;
padding: 0 !important;
}
.public-main > .content.public-container {
width: 100%;
padding: 16px 16px 32px !important;
}
.public-container ::deep h1 {
font-size: 28px;
}
.public-container ::deep h2 {
font-size: 24px;
}
.public-container ::deep h3 {
font-size: 20px;
}
#blazor-error-ui {
padding: 12px 56px 12px 16px;
}
#blazor-error-ui .reload {
margin-left: 0;
margin-top: 4px;
}
}
/* ========================================
SMALL MOBILE - MAX 360 PX
======================================== */
@media (max-width: 360px) {
.public-main > .content.public-container {
padding: 12px 12px 24px !important;
}
.public-container ::deep h1 {
font-size: 26px;
}
}
/* ========================================
REDUCED MOTION
======================================== */
@media (prefers-reduced-motion: reduce) {
.public-layout,
.public-layout ::deep *,
.public-layout ::deep *::before,
.public-layout ::deep *::after {
scroll-behavior: auto !important;
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}

View File

@@ -1,82 +1,212 @@
@implements IDisposable
@implements IDisposable
@inject NavigationManager NavigationManager
<div class="top-row ps-3 navbar navbar-dark">
<div class="container-fluid">
<a class="navbar-brand" href="">Web-Jarmark</a>
<div class="nav-panel">
<div class="nav-brand-area">
<a class="navbar-brand" href="/">
<svg class="brand-symbol"
width="32"
height="32"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.6"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true">
<path d="M20 4C10 4 5 8 5 15
c0 3 2 5 5 5
C17 20 20 12 20 4Z" />
<path d="M3 22L15 10" />
</svg>
<span class="brand-text">
<strong>Školní jarmark</strong>
</span>
</a>
</div>
</div>
<input type="checkbox" title="Navigation menu" class="navbar-toggler" />
<input type="checkbox"
id="public-menu-toggle"
title="Navigační menu"
aria-label="Rozbalit nebo sbalit navigační menu"
aria-controls="public-navigation"
class="navbar-toggler" />
<div class="nav-scrollable"
id="public-navigation">
<nav class="nav public-nav-links"
aria-label="Hlavní navigace">
<div class="nav-item">
<NavLink class="nav-link"
href=""
Match="NavLinkMatch.All"
onclick="document.getElementById('public-menu-toggle').checked = false">
<span>Katalog</span>
<div class="nav-scrollable" onclick="document.querySelector('.navbar-toggler').click()">
<nav class="nav flex-column">
<div class="nav-item px-3">
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
<span class="bi bi-house-door-fill-nav-menu" aria-hidden="true"></span> Home
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="kosik">
<span class="bi bi-plus-square-fill-nav-menu" aria-hidden="true"></span> Kosik
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="FF">
<span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> FF
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="NovaObjednavka">
<span class="bi bi-lock-nav-menu" aria-hidden="true"></span> Nova objednavka
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="DetailObjednavky">
<span class="bi bi-lock-nav-menu" aria-hidden="true"></span> Detail objednavky
</NavLink>
</div>
<AuthorizeView>
<AuthorizeView Roles="Admin">
<Authorized>
<div class="nav-item px-3">
<NavLink class="nav-link" href="Account/Manage">
<span class="bi bi-person-fill-nav-menu" aria-hidden="true"></span> @context.User.Identity?.Name
<div class="nav-item">
<NavLink class="nav-link"
href="admin"
onclick="document.getElementById('public-menu-toggle').checked = false">
<span>Administrace</span>
</NavLink>
</div>
<div class="nav-item px-3">
<form action="Account/Logout" method="post">
<AntiforgeryToken />
<input type="hidden" name="ReturnUrl" value="@currentUrl" />
<button type="submit" class="nav-link">
<span class="bi bi-arrow-bar-left-nav-menu" aria-hidden="true"></span> Logout
</button>
</form>
</div>
</Authorized>
<NotAuthorized>
<div class="nav-item px-3">
<NavLink class="nav-link" href="Account/Register">
<span class="bi bi-person-nav-menu" aria-hidden="true"></span> Register
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="Account/Login">
<span class="bi bi-person-badge-nav-menu" aria-hidden="true"></span> Login
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="admin">
<span class="bi bi-gear-nav-menu" aria-hidden="true"></span> Admin
</NavLink>
</div>
</NotAuthorized>
</AuthorizeView>
</nav>
<div class="nav-bottom public-account-links">
<AuthorizeView>
<Authorized>
<div class="nav-item account-item">
<NavLink class="nav-link"
href="Account/Manage"
onclick="document.getElementById('public-menu-toggle').checked = false">
<svg class="nav-icon"
width="20"
height="20"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.7"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true">
<circle cx="12"
cy="8"
r="4" />
<path d="M4 21v-2
a8 8 0 0 1 16 0
v2" />
</svg>
<span class="user-name">
@context.User.Identity?.Name
</span>
</NavLink>
</div>
<div class="nav-item">
<form action="Account/Logout"
method="post">
<AntiforgeryToken />
<input type="hidden"
name="ReturnUrl"
value="@currentUrl" />
<button type="submit"
class="nav-link logout-link">
<span>Odhlásit</span>
</button>
</form>
</div>
</Authorized>
<NotAuthorized>
<div class="nav-item">
<NavLink class="nav-link"
href="Account/Login"
onclick="document.getElementById('public-menu-toggle').checked = false">
<span>Přihlášení</span>
</NavLink>
</div>
<div class="nav-item">
<NavLink class="nav-link"
href="Account/Register"
onclick="document.getElementById('public-menu-toggle').checked = false">
<span>Registrace</span>
</NavLink>
</div>
</NotAuthorized>
</AuthorizeView>
<div class="nav-item cart-item">
<NavLink class="nav-link public-cart-link"
href="kosik"
onclick="document.getElementById('public-menu-toggle').checked = false">
<svg class="nav-icon"
width="20"
height="20"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.7"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true">
<path d="M3 3h2l3.5 13h10
l3-10H6" />
<circle cx="10"
cy="20"
r="1" />
<circle cx="18"
cy="20"
r="1" />
</svg>
<span>Košík</span>
</NavLink>
</div>
</div>
</div>
</div>
@code {
@@ -84,14 +214,20 @@
protected override void OnInitialized()
{
currentUrl = NavigationManager.ToBaseRelativePath(NavigationManager.Uri);
currentUrl = NavigationManager.ToBaseRelativePath(
NavigationManager.Uri);
NavigationManager.LocationChanged += OnLocationChanged;
}
private void OnLocationChanged(object? sender, LocationChangedEventArgs e)
private void OnLocationChanged(
object? sender,
LocationChangedEventArgs e)
{
currentUrl = NavigationManager.ToBaseRelativePath(e.Location);
StateHasChanged();
currentUrl = NavigationManager.ToBaseRelativePath(
e.Location);
_ = InvokeAsync(StateHasChanged);
}
public void Dispose()

View File

@@ -1,125 +1,522 @@
.navbar-toggler {
appearance: none;
cursor: pointer;
width: 3.5rem;
height: 2.5rem;
color: white;
position: absolute;
top: 0.5rem;
right: 1rem;
border: 1px solid rgba(255, 255, 255, 0.1);
background: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255, 255, 255, 0.55%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e") no-repeat center/1.75rem rgba(255, 255, 255, 0.1);
/* ========================================
SKOLNI JARMARK - PUBLIC NAVIGATION
======================================== */
.nav-panel {
--nav-primary: #244b36;
--nav-primary-hover: #193b29;
--nav-secondary: #e6eddf;
--nav-text: #26372b;
--nav-muted: #59665b;
--nav-border: #dce3d9;
--nav-surface: #ffffff;
position: relative;
display: flex;
align-items: center;
gap: 32px;
width: 100%;
max-width: 1440px;
min-width: 0;
min-height: 76px;
margin: 0 auto;
padding: 12px 32px;
background: var(--nav-surface);
color: var(--nav-text);
box-sizing: border-box;
}
.navbar-toggler:checked {
background-color: rgba(255, 255, 255, 0.5);
}
.top-row {
min-height: 3.5rem;
background-color: rgba(0,0,0,0.4);
/* ========================================
BRAND
======================================== */
.nav-brand-area {
display: flex;
align-items: center;
flex-shrink: 0;
min-width: 0;
}
.navbar-brand {
font-size: 1.1rem;
display: inline-flex;
align-items: center;
gap: 8px;
min-height: 44px;
margin: 0;
padding: 0;
color: var(--nav-primary);
text-decoration: none;
}
.bi {
display: inline-block;
position: relative;
width: 1.25rem;
height: 1.25rem;
margin-right: 0.75rem;
top: -1px;
background-size: cover;
.navbar-brand:hover {
color: var(--nav-primary-hover);
}
.brand-symbol {
display: block;
width: 32px;
height: 32px;
flex-shrink: 0;
color: var(--nav-primary);
}
.bi-house-door-fill-nav-menu {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-house-door-fill' viewBox='0 0 16 16'%3E%3Cpath d='M6.5 14.5v-3.505c0-.245.25-.495.5-.495h2c.25 0 .5.25.5.5v3.5a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5v-7a.5.5 0 0 0-.146-.354L13 5.793V2.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1.293L8.354 1.146a.5.5 0 0 0-.708 0l-6 6A.5.5 0 0 0 1.5 7.5v7a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5Z'/%3E%3C/svg%3E");
.brand-text {
display: block;
}
.bi-plus-square-fill-nav-menu {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-plus-square-fill' viewBox='0 0 16 16'%3E%3Cpath d='M2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2H2zm6.5 4.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3a.5.5 0 0 1 1 0z'/%3E%3C/svg%3E");
.brand-text strong {
font-family: Georgia, "Times New Roman", serif;
font-size: 23px;
font-weight: 700;
line-height: 1.2;
letter-spacing: normal;
white-space: nowrap;
}
/* ========================================
NAVIGATION STRUCTURE
======================================== */
.nav-scrollable {
display: flex;
align-items: center;
justify-content: space-between;
flex: 1;
gap: 16px;
min-width: 0;
}
.bi-list-nested-nav-menu {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-list-nested' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M4.5 11.5A.5.5 0 0 1 5 11h10a.5.5 0 0 1 0 1H5a.5.5 0 0 1-.5-.5zm-2-4A.5.5 0 0 1 3 7h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm-2-4A.5.5 0 0 1 1 3h10a.5.5 0 0 1 0 1H1a.5.5 0 0 1-.5-.5z'/%3E%3C/svg%3E");
.public-nav-links {
display: flex;
flex-direction: row;
align-items: center;
flex-wrap: wrap;
gap: 4px;
margin: 0;
padding: 0;
}
.bi-lock-nav-menu {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-list-nested' viewBox='0 0 16 16'%3E%3Cpath d='M8 1a2 2 0 0 1 2 2v4H6V3a2 2 0 0 1 2-2zm3 6V3a3 3 0 0 0-6 0v4a2 2 0 0 0-2 2v5a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2zM5 8h6a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1z'/%3E%3C/svg%3E");
}
.bi-person-nav-menu {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-person' viewBox='0 0 16 16'%3E%3Cpath d='M8 8a3 3 0 1 0 0-6 3 3 0 0 0 0 6Zm2-3a2 2 0 1 1-4 0 2 2 0 0 1 4 0Zm4 8c0 1-1 1-1 1H3s-1 0-1-1 1-4 6-4 6 3 6 4Zm-1-.004c-.001-.246-.154-.986-.832-1.664C11.516 10.68 10.289 10 8 10c-2.29 0-3.516.68-4.168 1.332-.678.678-.83 1.418-.832 1.664h10Z'/%3E%3C/svg%3E");
}
.bi-person-badge-nav-menu {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-person-badge' viewBox='0 0 16 16'%3E%3Cpath d='M6.5 2a.5.5 0 0 0 0 1h3a.5.5 0 0 0 0-1h-3zM11 8a3 3 0 1 1-6 0 3 3 0 0 1 6 0z'/%3E%3Cpath d='M4.5 0A2.5 2.5 0 0 0 2 2.5V14a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V2.5A2.5 2.5 0 0 0 11.5 0h-7zM3 2.5A1.5 1.5 0 0 1 4.5 1h7A1.5 1.5 0 0 1 13 2.5v10.795a4.2 4.2 0 0 0-.776-.492C11.392 12.387 10.063 12 8 12s-3.392.387-4.224.803a4.2 4.2 0 0 0-.776.492V2.5z'/%3E%3C/svg%3E");
}
.bi-person-fill-nav-menu {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-person-fill' viewBox='0 0 16 16'%3E%3Cpath d='M3 14s-1 0-1-1 1-4 6-4 6 3 6 4-1 1-1 1H3Zm5-6a3 3 0 1 0 0-6 3 3 0 0 0 0 6Z'/%3E%3C/svg%3E");
}
.bi-arrow-bar-left-nav-menu {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-arrow-bar-left' viewBox='0 0 16 16'%3E%3Cpath d='M12.5 15a.5.5 0 0 1-.5-.5v-13a.5.5 0 0 1 1 0v13a.5.5 0 0 1-.5.5ZM10 8a.5.5 0 0 1-.5.5H3.707l2.147 2.146a.5.5 0 0 1-.708.708l-3-3a.5.5 0 0 1 0-.708l3-3a.5.5 0 1 1 .708.708L3.707 7.5H9.5a.5.5 0 0 1 .5.5Z'/%3E%3C/svg%3E");
.public-account-links {
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-end;
flex-wrap: wrap;
gap: 8px;
min-width: 0;
margin: 0 0 0 auto;
padding: 0;
}
.nav-item {
font-size: 0.9rem;
padding-bottom: 0.5rem;
display: block;
min-width: 0;
margin: 0;
padding: 0;
font-size: 14px;
font-weight: 600;
}
.nav-item:first-of-type {
padding-top: 1rem;
/* ========================================
NAVIGATION LINKS
======================================== */
.nav-item ::deep .nav-link {
position: relative;
display: flex;
align-items: center;
justify-content: flex-start;
gap: 8px;
min-height: 44px;
margin: 0;
padding: 8px 12px;
border: 1px solid transparent;
border-radius: 6px;
background: transparent;
color: var(--nav-muted);
font-family: inherit;
font-size: 14px;
font-weight: 600;
line-height: 1.4;
text-align: left;
text-decoration: none;
white-space: nowrap;
transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}
.nav-item:last-of-type {
padding-bottom: 1rem;
.nav-item ::deep .nav-link:hover {
background: #f1f4ef;
color: var(--nav-primary);
text-decoration: none;
}
.nav-item ::deep a.nav-link.active {
background: var(--nav-secondary);
color: var(--nav-primary);
border-color: #dce5d7;
font-weight: 700;
}
/* ========================================
ICONS
======================================== */
.nav-icon {
display: block;
width: 20px;
height: 20px;
flex-shrink: 0;
}
/* ========================================
USER ACCOUNT
======================================== */
.account-item {
min-width: 0;
max-width: 200px;
}
.user-name {
display: block;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.nav-item ::deep form {
margin: 0;
padding: 0;
}
.nav-item ::deep button.nav-link {
width: 100%;
font-family: inherit;
cursor: pointer;
}
.nav-item ::deep .logout-link {
color: #8b4038;
}
.nav-item ::deep .logout-link:hover {
background: #fbefed;
color: #74342d;
border-color: #efd8d4;
}
/* ========================================
SHOPPING CART - PRIMARY ACTION
======================================== */
.cart-item {
margin-left: 4px;
}
.cart-item ::deep .public-cart-link {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
min-height: 44px;
padding: 10px 20px;
border: 1px solid var(--nav-primary);
border-radius: 6px;
background: var(--nav-primary);
color: #ffffff;
font-weight: 700;
}
.cart-item ::deep .public-cart-link:hover {
background: var(--nav-primary-hover);
border-color: var(--nav-primary-hover);
color: #ffffff;
}
.cart-item ::deep a.public-cart-link.active {
background: var(--nav-primary-hover);
border-color: var(--nav-primary-hover);
color: #ffffff;
text-decoration: underline;
text-underline-offset: 4px;
}
/* ========================================
KEYBOARD ACCESSIBILITY
======================================== */
.navbar-brand:focus-visible,
.navbar-toggler:focus-visible,
.nav-panel ::deep .nav-link:focus-visible {
outline: 3px solid #527b49;
outline-offset: 3px;
box-shadow: none;
}
/* ========================================
MOBILE MENU TOGGLE
======================================== */
.navbar-toggler {
display: none;
appearance: none;
-webkit-appearance: none;
position: absolute;
top: 12px;
right: 24px;
width: 44px;
height: 44px;
margin: 0;
padding: 0;
border: 1px solid var(--nav-border);
border-radius: 6px;
background: var(--nav-surface);
color: var(--nav-primary);
cursor: pointer;
box-sizing: border-box;
}
.navbar-toggler::before,
.navbar-toggler::after {
content: "";
position: absolute;
left: 11px;
width: 20px;
height: 2px;
background: currentColor;
border-radius: 1px;
}
.navbar-toggler::before {
top: 14px;
box-shadow: 0 6px 0 currentColor;
}
.navbar-toggler::after {
top: 26px;
}
.navbar-toggler:checked {
background: var(--nav-secondary);
}
.navbar-toggler:checked::before {
top: 20px;
transform: rotate(45deg);
box-shadow: none;
}
.navbar-toggler:checked::after {
top: 20px;
transform: rotate(-45deg);
}
.navbar-toggler:hover {
background-color: var(--nav-secondary);
}
/* ========================================
COMPACT DESKTOP
======================================== */
@media (max-width: 1200px) {
.nav-panel {
gap: 16px;
padding: 12px 24px;
}
.brand-text strong {
font-size: 21px;
}
.public-account-links {
gap: 4px;
}
.nav-item ::deep .nav-link {
color: #d7d7d7;
background: none;
border: none;
border-radius: 4px;
height: 3rem;
display: flex;
align-items: center;
line-height: 3rem;
width: 100%;
padding: 8px 12px;
}
.nav-item ::deep a.active {
background-color: rgba(255,255,255,0.37);
color: white;
.cart-item ::deep .public-cart-link {
padding: 10px 16px;
}
.account-item {
max-width: 160px;
}
}
.nav-item ::deep .nav-link:hover {
background-color: rgba(255,255,255,0.1);
color: white;
}
.nav-scrollable {
display: none;
}
/* ========================================
TABLET AND MOBILE
======================================== */
.navbar-toggler:checked ~ .nav-scrollable {
display: block;
}
@media (max-width: 1024px) {
.nav-panel {
display: flex;
flex-direction: column;
align-items: stretch;
gap: 0;
min-height: 68px;
padding: 0;
}
.nav-brand-area {
display: flex;
align-items: center;
min-height: 68px;
padding: 12px 84px 12px 24px;
}
@media (min-width: 641px) {
.navbar-toggler {
display: none;
display: block;
}
.nav-scrollable {
/* Never collapse the sidebar for wide screens */
display: block;
display: none;
flex-direction: column;
align-items: stretch;
gap: 16px;
width: 100%;
padding: 16px 24px 24px;
border-top: 1px solid var(--nav-border);
}
/* Allow sidebar to scroll for tall menus */
height: calc(100vh - 3.5rem);
overflow-y: auto;
.navbar-toggler:checked ~ .nav-scrollable {
display: flex;
}
.public-nav-links {
display: flex;
flex-direction: column;
align-items: stretch;
gap: 4px;
width: 100%;
}
.public-account-links {
display: flex;
flex-direction: column;
align-items: stretch;
gap: 4px;
width: 100%;
margin: 0;
padding-top: 16px;
border-top: 1px solid var(--nav-border);
}
.nav-item {
width: 100%;
}
.nav-item ::deep .nav-link {
width: 100%;
min-height: 48px;
padding: 12px 16px;
font-size: 15px;
}
.account-item {
max-width: none;
}
.cart-item {
margin: 12px 0 0;
}
.cart-item ::deep .public-cart-link {
width: 100%;
min-height: 48px;
justify-content: center;
}
}
/* ========================================
MOBILE - MAX 640 PX
======================================== */
@media (max-width: 640px) {
.nav-brand-area {
padding: 12px 76px 12px 16px;
}
.navbar-toggler {
right: 16px;
}
.brand-symbol {
width: 28px;
height: 28px;
}
.brand-text strong {
font-size: 20px;
}
.nav-scrollable {
padding: 12px 16px 20px;
}
}
/* ========================================
SMALL MOBILE
======================================== */
@media (max-width: 360px) {
.brand-text strong {
font-size: 18px;
}
.brand-symbol {
width: 24px;
height: 24px;
}
.navbar-brand {
gap: 8px;
}
.nav-brand-area {
padding-left: 12px;
padding-right: 68px;
}
.navbar-toggler {
right: 12px;
}
.nav-scrollable {
padding: 12px 12px 16px;
}
}
/* ========================================
REDUCED MOTION
======================================== */
@media (prefers-reduced-motion: reduce) {
.navbar-brand,
.navbar-toggler,
.nav-panel ::deep .nav-link {
transition: none !important;
animation: none !important;
}
}

View File

@@ -1,4 +1,356 @@
@page "/admin"
@page "/admin"
@layout Web_Jarmark.Components.Layout.Admin.AdminLayout
@rendermode InteractiveServer
@using Microsoft.EntityFrameworkCore
@using Microsoft.AspNetCore.Authorization
@using Web_Jarmark.Data
@using Web_Jarmark.Data.Models
@inject ApplicationDbContext Db
<PageTitle>Admin</PageTitle>
@attribute [Authorize(Roles = "Admin")]
<PageTitle>Přehled administrace</PageTitle>
<div class="dash">
@if (loading)
{
<div class="ao-loading">Načítám přehled…</div>
}
else if (!string.IsNullOrEmpty(error))
{
<div class="ao-alert">@error</div>
}
else
{
<header class="dash-hero">
<div>
<p class="dash-eyebrow">Web-Jarmark</p>
<h1>Přehled</h1>
<p class="dash-sub">Aktuální stav obchodu na jednom místě.</p>
</div>
<div class="dash-hero-actions">
<a class="ap-btn ap-btn-primary" href="/admin/objednavky">Objednávky</a>
<a class="ap-btn" href="/admin/zbozi">Zboží</a>
<a class="ap-btn" href="/admin/sklad">Sklad</a>
</div>
</header>
<section class="dash-kpis">
<article class="dash-kpi" style="--i:0">
<span>Objednávky</span>
<strong class="dash-count">@orderCount</strong>
<small>@pendingCount čeká na platbu</small>
</article>
<article class="dash-kpi" style="--i:1">
<span>Tržby</span>
<strong class="dash-count">@revenue.ToString("N0")</strong>
<small>Kč uhrazené / dokončené</small>
</article>
<article class="dash-kpi" style="--i:2">
<span>Produkty</span>
<strong class="dash-count">@productCount</strong>
<small>@visibleCount viditelných</small>
</article>
<article class="dash-kpi" style="--i:3">
<span>Sklad</span>
<strong class="dash-count">@stockUnits</strong>
<small>@stockValue.ToString("N0") Kč hodnota</small>
</article>
<article class="dash-kpi" style="--i:4">
<span>Nízký sklad</span>
<strong class="dash-count">@lowStockCount</strong>
<small>≤ 5 ks</small>
</article>
<article class="dash-kpi" style="--i:5">
<span>Kategorie</span>
<strong class="dash-count">@categoryCount</strong>
<small>@activeCategoryCount aktivních</small>
</article>
</section>
<section class="dash-row-3">
<article class="dash-card" style="--i:6">
<div class="dash-card-head">
<h2>Viditelnost</h2>
<p>Katalog v e-shopu</p>
</div>
<div class="dash-stack">
<div class="dash-stack-top">
<strong>@productCount</strong>
<span>produktů celkem</span>
</div>
<div class="dash-progress">
<div class="dash-progress-fill is-dark" style="width:@visPercent%"></div>
</div>
<div class="dash-split">
<div class="dash-split-item">
<span class="dash-dot is-on"></span>
<div>
<strong>@visibleCount</strong>
<small>Viditelné</small>
</div>
</div>
<div class="dash-split-item">
<span class="dash-dot is-off"></span>
<div>
<strong>@hiddenCount</strong>
<small>Skryté</small>
</div>
</div>
</div>
</div>
</article>
<article class="dash-card" style="--i:7">
<div class="dash-card-head">
<h2>Stav skladu</h2>
<p>Produkty podle zásob</p>
</div>
<div class="dash-stack">
<div class="dash-stack-top">
<strong>@stockUnits</strong>
<span>ks na skladě · @stockValue.ToString("N0") Kč</span>
</div>
<div class="dash-progress dash-progress-multi">
<div class="dash-progress-fill is-dark" style="width:@okPercent%"></div>
<div class="dash-progress-fill is-mid" style="width:@lowPercent%"></div>
<div class="dash-progress-fill is-light" style="width:@outPercent%"></div>
</div>
<div class="dash-split three">
<div class="dash-split-item">
<span class="dash-dot is-on"></span>
<div>
<strong>@okStockCount</strong>
<small>V pořádku</small>
</div>
</div>
<div class="dash-split-item">
<span class="dash-dot is-mid"></span>
<div>
<strong>@lowStockCount</strong>
<small>Nízký</small>
</div>
</div>
<div class="dash-split-item">
<span class="dash-dot is-off"></span>
<div>
<strong>@outOfStockCount</strong>
<small>Prázdný</small>
</div>
</div>
</div>
</div>
</article>
<article class="dash-card" style="--i:8">
<div class="dash-card-head">
<h2>Objednávky</h2>
<p>Podle stavu</p>
</div>
<div class="dash-bars">
@foreach (var b in orderBars)
{
<div class="dash-bar-row">
<div class="dash-bar-label">
<span>@b.Label</span>
<strong>@b.Count</strong>
</div>
<div class="dash-bar-track">
<div class="dash-bar-fill" style="width:@b.Percent%"></div>
</div>
</div>
}
</div>
</article>
</section>
<section class="dash-row-2">
<article class="dash-card" style="--i:9">
<div class="dash-card-head">
<h2>Rychlé akce</h2>
<p>Nejčastější správa</p>
</div>
<div class="dash-actions">
<a class="dash-action" href="/admin/objednavky"><strong>Objednávky</strong><span>@pendingCount čeká</span></a>
<a class="dash-action" href="/admin/zbozi"><strong>Zboží</strong><span>@productCount produktů</span></a>
<a class="dash-action" href="/admin/sklad"><strong>Sklad</strong><span>@lowStockCount nízký</span></a>
<a class="dash-action" href="/admin/kategorie"><strong>Kategorie</strong><span>@categoryCount položek</span></a>
<a class="dash-action" href="/admin/statistiky"><strong>Statistiky</strong><span>detailní přehled</span></a>
<a class="dash-action" href="/admin/administratori"><strong>Uživatelé</strong><span>správa účtů</span></a>
</div>
</article>
<article class="dash-card" style="--i:10">
<div class="dash-card-head">
<h2>Pozor na sklad</h2>
<p>Nízký stav a vyprodané</p>
</div>
@if (attentionProducts.Count == 0)
{
<div class="dash-empty">Všechny produkty mají dostatek kusů.</div>
}
else
{
<div class="dash-mini-list">
@foreach (var p in attentionProducts)
{
<a class="dash-mini-item" href="@($"/admin/zbozi/edit/{p.Id}")">
<div>
<strong>@p.Name</strong>
<span>@p.CategoryName</span>
</div>
<span class="ao-badge @(p.StockQuantity <= 0 ? "is-cancel" : "is-pending")">
@p.StockQuantity ks
</span>
</a>
}
</div>
}
</article>
</section>
<section class="dash-card" style="--i:11">
<div class="dash-card-head row">
<div>
<h2>Poslední objednávky</h2>
<p>Nejnovějších 8</p>
</div>
<a class="ap-btn ap-btn-ghost" href="/admin/objednavky">Všechny</a>
</div>
@if (recentOrders.Count == 0)
{
<div class="dash-empty">Zatím žádné objednávky.</div>
}
else
{
<div class="dash-orders">
@foreach (var o in recentOrders)
{
<article class="dash-order" style="--i:@o.Index">
<div>
<strong>#@o.Code</strong>
<span>@o.CreatedAt.ToLocalTime().ToString("d. M. yyyy HH:mm")</span>
</div>
<div class="dash-order-mid">
@(string.IsNullOrWhiteSpace(o.CustomerName) ? "—" : o.CustomerName)
</div>
<div class="dash-order-right">
<strong>@o.TotalAmount.ToString("N0") Kč</strong>
<span class="ao-badge @StatusBadge(o.Status)">@StatusText(o.Status)</span>
</div>
</article>
}
</div>
}
</section>
}
</div>
@code {
private bool loading = true;
private string? error;
private int productCount, visibleCount, hiddenCount, categoryCount, activeCategoryCount;
private int stockUnits, lowStockCount, outOfStockCount, okStockCount;
private int orderCount, pendingCount, paidCount, shippedCount, deliveredCount, cancelledCount;
private decimal revenue, stockValue;
private int visPercent, okPercent, lowPercent, outPercent;
private List<BarItem> orderBars = new();
private List<RecentOrder> recentOrders = new();
private List<AttentionProduct> attentionProducts = new();
protected override async Task OnInitializedAsync()
{
try
{
var products = await Db.Products.AsNoTracking().Include(p => p.Category).ToListAsync();
productCount = products.Count;
visibleCount = products.Count(p => p.IsVisible);
hiddenCount = productCount - visibleCount;
stockUnits = products.Sum(p => p.StockQuantity);
stockValue = products.Sum(p => p.Price * p.StockQuantity);
lowStockCount = products.Count(p => p.StockQuantity > 0 && p.StockQuantity <= 5);
outOfStockCount = products.Count(p => p.StockQuantity <= 0);
okStockCount = products.Count(p => p.StockQuantity > 5);
categoryCount = await Db.Categories.CountAsync();
activeCategoryCount = await Db.Categories.CountAsync(c => c.IsActive);
var orders = await Db.Orders.AsNoTracking().ToListAsync();
orderCount = orders.Count;
pendingCount = orders.Count(o => o.Status == OrderStatus.Pending);
paidCount = orders.Count(o => o.Status == OrderStatus.Paid);
shippedCount = orders.Count(o => o.Status == OrderStatus.Shipped);
deliveredCount = orders.Count(o => o.Status == OrderStatus.Delivered);
cancelledCount = orders.Count(o => o.Status == OrderStatus.Cancelled);
revenue = orders
.Where(o => o.Status is OrderStatus.Paid or OrderStatus.Shipped or OrderStatus.Delivered)
.Sum(o => o.TotalAmount);
visPercent = productCount == 0 ? 0 : (int)Math.Round(100.0 * visibleCount / productCount);
okPercent = productCount == 0 ? 0 : (int)Math.Round(100.0 * okStockCount / productCount);
lowPercent = productCount == 0 ? 0 : (int)Math.Round(100.0 * lowStockCount / productCount);
outPercent = productCount == 0 ? 0 : Math.Max(0, 100 - okPercent - lowPercent);
var total = Math.Max(orderCount, 1);
orderBars = new List<BarItem>
{
new("Čeká na zaplacení", pendingCount, pendingCount * 100 / total),
new("Zaplaceno", paidCount, paidCount * 100 / total),
new("Odesláno", shippedCount, shippedCount * 100 / total),
new("Dokončeno", deliveredCount, deliveredCount * 100 / total),
new("Zrušeno", cancelledCount, cancelledCount * 100 / total),
};
recentOrders = orders
.OrderByDescending(o => o.CreatedAt)
.Take(8)
.Select((o, idx) => new RecentOrder(o.Code, o.CustomerName, o.TotalAmount, o.Status, o.CreatedAt, idx))
.ToList();
attentionProducts = products
.Where(p => p.StockQuantity <= 5)
.OrderBy(p => p.StockQuantity)
.ThenBy(p => p.Name)
.Take(8)
.Select(p => new AttentionProduct(p.Id, p.Name, p.Category?.Name ?? "—", p.StockQuantity))
.ToList();
}
catch (Exception ex)
{
error = "Přehled se nepodařilo načíst: " + ex.Message;
}
finally
{
loading = false;
}
}
private static string StatusText(OrderStatus s) => s switch
{
OrderStatus.Pending => "Čeká",
OrderStatus.Paid => "Zaplaceno",
OrderStatus.Shipped => "Odesláno",
OrderStatus.Delivered => "Dokončeno",
OrderStatus.Cancelled => "Zrušeno",
_ => "?"
};
private static string StatusBadge(OrderStatus s) => s switch
{
OrderStatus.Pending => "is-pending",
OrderStatus.Paid => "is-paid",
OrderStatus.Shipped => "is-shipped",
OrderStatus.Delivered => "is-done",
OrderStatus.Cancelled => "is-cancel",
_ => ""
};
private sealed record BarItem(string Label, int Count, int Percent);
private sealed record RecentOrder(string Code, string CustomerName, decimal TotalAmount, OrderStatus Status, DateTime CreatedAt, int Index);
private sealed record AttentionProduct(int Id, string Name, string CategoryName, int StockQuantity);
}

View File

@@ -0,0 +1,498 @@
/* Plná šířka dashboard */
.dash {
width: 100%;
max-width: none;
margin: 0;
color: #1d1d1f;
font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
-webkit-font-smoothing: antialiased;
}
.dash-hero {
display: flex;
justify-content: space-between;
align-items: flex-end;
gap: 16px;
flex-wrap: wrap;
padding: 4px 2px 22px;
animation: dash-in 0.45s ease both;
}
.dash-eyebrow {
margin: 0 0 6px;
font-size: 12px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
color: #6e6e73;
}
.dash-hero h1 {
margin: 0;
font-size: 34px;
font-weight: 750;
letter-spacing: -0.03em;
}
.dash-sub {
margin: 8px 0 0;
color: #6e6e73;
font-size: 15px;
}
.dash-hero-actions {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.dash-kpis {
display: grid;
grid-template-columns: repeat(6, minmax(0, 1fr));
gap: 12px;
margin-bottom: 14px;
}
.dash-kpi {
background: #fff;
border: 1px solid rgba(0, 0, 0, 0.05);
border-radius: 22px;
padding: 16px 14px;
box-shadow: 0 10px 28px rgba(0, 0, 0, 0.04);
animation: dash-rise 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
animation-delay: calc(var(--i, 0) * 0.05s);
transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.dash-kpi:hover {
transform: translateY(-3px);
box-shadow: 0 16px 36px rgba(0, 0, 0, 0.07);
}
.dash-kpi span {
display: block;
font-size: 12px;
font-weight: 650;
color: #6e6e73;
}
.dash-kpi strong.dash-count {
display: block;
margin-top: 8px;
font-size: 26px;
font-weight: 750;
letter-spacing: -0.03em;
line-height: 1;
animation: dash-pop 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
animation-delay: calc(var(--i, 0) * 0.05s + 0.1s);
}
.dash-kpi small {
display: block;
margin-top: 8px;
font-size: 11px;
color: #86868b;
}
.dash-row-3 {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 12px;
margin-bottom: 12px;
}
.dash-row-2 {
display: grid;
grid-template-columns: 1.2fr 0.8fr;
gap: 12px;
margin-bottom: 12px;
}
.dash-card {
background: #fff;
border: 1px solid rgba(0, 0, 0, 0.05);
border-radius: 24px;
padding: 18px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.04);
animation: dash-rise 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
animation-delay: calc(var(--i, 0) * 0.05s);
}
.dash-card-head {
margin-bottom: 14px;
}
.dash-card-head.row {
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 12px;
}
.dash-card-head h2 {
margin: 0;
font-size: 17px;
font-weight: 700;
letter-spacing: -0.02em;
}
.dash-card-head p {
margin: 4px 0 0;
font-size: 13px;
color: #6e6e73;
}
/* Progress verze místo donutů */
.dash-stack {
display: flex;
flex-direction: column;
gap: 16px;
}
.dash-stack-top strong {
display: block;
font-size: 28px;
font-weight: 750;
letter-spacing: -0.03em;
line-height: 1;
}
.dash-stack-top span {
display: block;
margin-top: 6px;
font-size: 13px;
color: #6e6e73;
}
.dash-progress {
height: 12px;
border-radius: 999px;
background: #f0f0f2;
overflow: hidden;
}
.dash-progress-multi {
display: flex;
background: #f0f0f2;
}
.dash-progress-fill {
height: 100%;
border-radius: 999px;
transform-origin: left center;
animation: dash-bar 0.85s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.dash-progress-multi .dash-progress-fill {
border-radius: 0;
}
.dash-progress-multi .dash-progress-fill:first-child {
border-radius: 999px 0 0 999px;
}
.dash-progress-multi .dash-progress-fill:last-child {
border-radius: 0 999px 999px 0;
}
.dash-progress-fill.is-dark {
background: #1d1d1f;
}
.dash-progress-fill.is-mid {
background: #8e8e93;
}
.dash-progress-fill.is-light {
background: #d2d2d7;
}
.dash-split {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.dash-split.three {
grid-template-columns: 1fr 1fr 1fr;
}
.dash-split-item {
display: flex;
align-items: flex-start;
gap: 8px;
padding: 12px;
border-radius: 14px;
background: #f5f5f7;
}
.dash-split-item strong {
display: block;
font-size: 18px;
font-weight: 750;
line-height: 1.1;
}
.dash-split-item small {
display: block;
margin-top: 3px;
font-size: 12px;
color: #6e6e73;
}
.dash-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: #e8e8ed;
flex-shrink: 0;
margin-top: 4px;
}
.dash-dot.is-on {
background: #1d1d1f;
}
.dash-dot.is-mid {
background: #8e8e93;
}
.dash-dot.is-off {
background: #e8e8ed;
border: 1px solid #d2d2d7;
}
.dash-bars {
display: flex;
flex-direction: column;
gap: 12px;
}
.dash-bar-label {
display: flex;
justify-content: space-between;
margin-bottom: 5px;
font-size: 12px;
color: #6e6e73;
}
.dash-bar-label strong {
color: #1d1d1f;
}
.dash-bar-track {
height: 8px;
border-radius: 999px;
background: #f0f0f2;
overflow: hidden;
}
.dash-bar-fill {
height: 100%;
border-radius: 999px;
background: #1d1d1f;
transform-origin: left center;
animation: dash-bar 0.9s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.dash-actions {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 10px;
}
.dash-action {
display: flex;
flex-direction: column;
gap: 4px;
padding: 14px;
border-radius: 16px;
background: #f5f5f7;
text-decoration: none;
color: inherit;
transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}
.dash-action:hover {
background: #fff;
transform: translateY(-2px);
box-shadow: 0 10px 24px rgba(0, 0, 0, 0.06);
color: inherit;
}
.dash-action strong {
font-size: 14px;
font-weight: 700;
}
.dash-action span {
font-size: 12px;
color: #6e6e73;
}
.dash-mini-list {
display: flex;
flex-direction: column;
gap: 8px;
}
.dash-mini-item {
display: flex;
justify-content: space-between;
align-items: center;
gap: 10px;
padding: 12px 14px;
border-radius: 14px;
background: #f5f5f7;
text-decoration: none;
color: inherit;
transition: background 0.2s ease, transform 0.15s ease;
}
.dash-mini-item:hover {
background: #ececee;
transform: translateX(2px);
color: inherit;
}
.dash-mini-item strong {
display: block;
font-size: 13px;
}
.dash-mini-item span {
font-size: 12px;
color: #6e6e73;
}
.dash-empty {
padding: 18px;
text-align: center;
color: #6e6e73;
font-size: 14px;
}
.dash-orders {
display: flex;
flex-direction: column;
gap: 8px;
}
.dash-order {
display: grid;
grid-template-columns: 1.2fr 1fr auto;
gap: 12px;
align-items: center;
padding: 14px 16px;
border-radius: 16px;
background: #f7f7f8;
animation: dash-rise 0.45s ease both;
animation-delay: calc(var(--i, 0) * 0.04s);
transition: background 0.2s ease, transform 0.15s ease;
}
.dash-order:hover {
background: #f0f0f2;
transform: translateX(2px);
}
.dash-order strong {
display: block;
font-size: 14px;
}
.dash-order span {
font-size: 12px;
color: #6e6e73;
}
.dash-order-mid {
font-size: 13px;
color: #6e6e73;
}
.dash-order-right {
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 4px;
}
@keyframes dash-in {
from {
opacity: 0;
transform: translateY(8px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes dash-rise {
from {
opacity: 0;
transform: translateY(16px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes dash-pop {
from {
opacity: 0;
transform: scale(0.92);
}
to {
opacity: 1;
transform: scale(1);
}
}
@keyframes dash-bar {
from {
transform: scaleX(0);
}
to {
transform: scaleX(1);
}
}
@media (max-width: 1200px) {
.dash-kpis {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
.dash-row-3 {
grid-template-columns: 1fr;
}
.dash-row-2 {
grid-template-columns: 1fr;
}
}
@media (max-width: 700px) {
.dash-kpis {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.dash-actions {
grid-template-columns: 1fr 1fr;
}
.dash-order {
grid-template-columns: 1fr;
}
.dash-split.three {
grid-template-columns: 1fr;
}
}

View File

@@ -0,0 +1,321 @@
@page "/admin/administratori"
@layout Web_Jarmark.Components.Layout.Admin.AdminLayout
@rendermode InteractiveServer
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.EntityFrameworkCore
@using Web_Jarmark.Data
@inject UserManager<ApplicationUser> UserManager
@inject RoleManager<IdentityRole> RoleManager
@inject AuthenticationStateProvider AuthenticationStateProvider
@attribute [Authorize(Roles = "Admin")]
<PageTitle>Registrovaní uživatelé</PageTitle>
<div class="ap">
<header class="ap-hero ap-hero-left">
<p class="ap-eyebrow">Administrace</p>
<div class="ap-hero-row">
<div>
<h1>Uživatelé</h1>
<p class="ap-sub">Správa registrovaných účtů a administrátorských oprávnění.</p>
</div>
</div>
</header>
@if (!string.IsNullOrEmpty(message))
{
<div class="ap-alert">@message</div>
}
@if (loading)
{
<div class="ap-loading">Načítám uživatele…</div>
}
else if (users.Count == 0)
{
<section class="ap-panel">
<p class="ap-empty">Zatím žádní registrovaní uživatelé.</p>
</section>
}
else
{
<section class="ap-panel ap-panel-table">
<div class="ap-panel-head">
<h2>Registrované účty</h2>
<span class="ap-muted">@users.Count účtů</span>
</div>
<div class="ap-table-wrap">
<table class="ap-table">
<thead>
<tr>
<th>E-mail</th>
<th>Potvrzený</th>
<th>Admin</th>
<th>Stav</th>
<th>Akce</th>
</tr>
</thead>
<tbody>
@foreach (var u in users)
{
<tr @key="u.Id">
<td class="ap-name">@u.Email</td>
<td>
<span class="ap-status @(u.EmailConfirmed ? "is-on" : "is-off")">
@(u.EmailConfirmed ? "Ano" : "Ne")
</span>
</td>
<td>
<span class="ap-status @(u.IsAdmin ? "is-on" : "is-off")">
@(u.IsAdmin ? "Admin" : "Uživatel")
</span>
</td>
<td>
<span class="ap-status @(u.IsLocked ? "is-off" : "is-on")">
@(u.IsLocked ? "Zamčený" : "Aktivní")
</span>
</td>
<td class="ap-actions-cell">
<button type="button"
class="ap-btn ap-btn-ghost"
disabled="@busy"
@onclick="() => ToggleAdminAsync(u)">
@(u.IsAdmin ? "Odebrat admin" : "Udělat admin")
</button>
<button type="button"
class="ap-btn ap-btn-ghost"
disabled="@busy"
@onclick="() => ToggleLockAsync(u)">
@(u.IsLocked ? "Odemknout" : "Zamknout")
</button>
</td>
</tr>
}
</tbody>
</table>
</div>
</section>
}
</div>
@code {
private List<UserRow> users = new();
private bool loading = true;
private bool busy;
private string? message;
private const string AdminRole = "Admin";
protected override async Task OnInitializedAsync()
{
await EnsureAdminRoleAsync();
await LoadUsersAsync();
loading = false;
}
private async Task EnsureAdminRoleAsync()
{
if (!await RoleManager.RoleExistsAsync(AdminRole))
{
var result = await RoleManager.CreateAsync(
new IdentityRole(AdminRole));
if (!result.Succeeded)
{
message = "Nepodařilo se vytvořit roli Admin: "
+ string.Join(", ", result.Errors.Select(e => e.Description));
}
}
}
private async Task LoadUsersAsync()
{
var list = await UserManager.Users
.AsNoTracking()
.OrderBy(u => u.Email)
.ToListAsync();
users = new List<UserRow>();
foreach (var user in list)
{
var roles = await UserManager.GetRolesAsync(user);
var isLocked = user.LockoutEnd.HasValue
&& user.LockoutEnd > DateTimeOffset.UtcNow;
users.Add(new UserRow(
user.Id,
user.Email ?? "(bez e-mailu)",
user.EmailConfirmed,
roles.Contains(AdminRole),
isLocked));
}
}
private async Task ToggleAdminAsync(UserRow row)
{
if (busy)
return;
busy = true;
message = null;
try
{
var user = await UserManager.FindByIdAsync(row.Id);
if (user is null)
{
message = "Uživatel nebyl nalezen.";
return;
}
if (!await RoleManager.RoleExistsAsync(AdminRole))
{
var createRoleResult = await RoleManager.CreateAsync(
new IdentityRole(AdminRole));
if (!createRoleResult.Succeeded)
{
message = "Nepodařilo se vytvořit roli Admin: "
+ string.Join(", ", createRoleResult.Errors.Select(e => e.Description));
return;
}
}
if (row.IsAdmin)
{
var admins = await UserManager.GetUsersInRoleAsync(AdminRole);
if (admins.Count <= 1)
{
message = "Nelze odebrat roli poslednímu administrátorovi.";
return;
}
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
var currentUserId = UserManager.GetUserId(authState.User);
if (currentUserId == user.Id)
{
message = "Nemůžeš odebrat administrátorskou roli sám sobě.";
return;
}
}
IdentityResult result;
if (row.IsAdmin)
{
result = await UserManager.RemoveFromRoleAsync(user, AdminRole);
}
else
{
result = await UserManager.AddToRoleAsync(user, AdminRole);
}
if (!result.Succeeded)
{
message = "Změna role se nepodařila: "
+ string.Join(", ", result.Errors.Select(e => e.Description));
return;
}
message = row.IsAdmin
? $"Administrátorská role byla odebrána: {row.Email}"
: $"Administrátorská role byla přidána: {row.Email}";
await LoadUsersAsync();
}
catch (Exception ex)
{
message = "Chyba při změně role: " + ex.Message;
}
finally
{
busy = false;
}
}
private async Task ToggleLockAsync(UserRow row)
{
if (busy)
return;
busy = true;
message = null;
try
{
var user = await UserManager.FindByIdAsync(row.Id);
if (user is null)
{
message = "Uživatel nebyl nalezen.";
return;
}
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
var currentUserId = UserManager.GetUserId(authState.User);
if (currentUserId == user.Id)
{
message = "Nemůžeš zamknout vlastní účet.";
return;
}
IdentityResult result;
if (row.IsLocked)
{
result = await UserManager.SetLockoutEndDateAsync(user, null);
}
else
{
result = await UserManager.SetLockoutEnabledAsync(user, true);
if (result.Succeeded)
{
result = await UserManager.SetLockoutEndDateAsync(
user, DateTimeOffset.UtcNow.AddYears(100));
}
}
if (!result.Succeeded)
{
message = "Změna stavu účtu se nepodařila: "
+ string.Join(", ", result.Errors.Select(e => e.Description));
return;
}
message = row.IsLocked
? $"Účet byl odemčen: {row.Email}"
: $"Účet byl zamčen: {row.Email}";
await LoadUsersAsync();
}
catch (Exception ex)
{
message = "Chyba: " + ex.Message;
}
finally
{
busy = false;
}
}
private sealed record UserRow(
string Id,
string Email,
bool EmailConfirmed,
bool IsAdmin,
bool IsLocked);
}

View File

@@ -1,143 +1,156 @@
@page "/admin/kategorie/edit"
@page "/admin/kategorie/edit/{Id:int}"
@layout Web_Jarmark.Components.Layout.Admin.AdminLayout
@rendermode InteractiveServer
@using System.ComponentModel.DataAnnotations
@using System.Globalization
@using System.Text
@using System.Text.RegularExpressions
@using Microsoft.EntityFrameworkCore
@using Microsoft.AspNetCore.Authorization
@using Web_Jarmark.Data
@using Web_Jarmark.Data.Models
@inject ApplicationDbContext Db
@inject NavigationManager Nav
@using Microsoft.AspNetCore.Authorization
@attribute [Authorize]
<AuthorizeView Context="authContext">
<PageTitle>@(Id is null ? "Nová kategorie" : "Upravit kategorii")</PageTitle>
@attribute [Authorize(Roles = "Admin")]
<h3>@(Id is null ? "Nová kategorie" : "Upravit kategorii")</h3>
<PageTitle>@(IsNew ? "Nová kategorie" : "Upravit kategorii")</PageTitle>
@if (notFound)
{
<div class="alert alert-warning">Kategorie nebyla nalezena.</div>
<a class="btn btn-secondary" href="/admin/kategorie">Zpět na seznam</a>
}
else
{
<EditForm Model="form" OnValidSubmit="Save" FormName="categoryForm" style="max-width: 500px;">
<DataAnnotationsValidator />
<ValidationSummary class="text-danger" />
<div class="ap ao">
<header class="ao-hero">
<p class="ao-eyebrow">Kategorie</p>
<h1>@(IsNew ? "Nová kategorie" : "Upravit kategorii")</h1>
<p class="ao-sub">Název a stav kategorie.</p>
</header>
@if (!string.IsNullOrEmpty(error))
{
<div class="alert alert-danger">@error</div>
<div class="ao-alert">@error</div>
}
<div class="mb-3">
<label class="form-label" for="name">Název</label>
<InputText id="name" class="form-control" @bind-Value="form.Name" />
@if (notFound)
{
<div class="ao-empty">Kategorie nebyla nalezena.</div>
<div style="text-align:center;margin-top:12px">
<a class="ap-btn" href="/admin/kategorie">Zpět</a>
</div>
<div class="mb-3">
<label class="form-label" for="slug">Slug (adresa)</label>
<InputText id="slug" class="form-control" @bind-Value="form.Slug" />
<div class="form-text">Když necháš prázdné, vytvoří se automaticky z názvu.</div>
</div>
<div class="form-check mb-3">
<InputCheckbox id="active" class="form-check-input" @bind-Value="form.IsActive" />
<label class="form-check-label" for="active">Aktivní</label>
</div>
<button type="submit" class="btn btn-primary">Uložit</button>
<a class="btn btn-secondary" href="/admin/kategorie">Zrušit</a>
</EditForm>
}
</AuthorizeView>
@code {
[Parameter] public int? Id { get; set; }
private CategoryForm form = new();
private string? error;
private bool notFound;
protected override async Task OnParametersSetAsync()
{
if (Id is null) return;
var cat = await Db.Set<Category>().AsNoTracking().FirstOrDefaultAsync(c => c.Id == Id);
if (cat is null)
{
notFound = true;
return;
}
form = new CategoryForm { Name = cat.Name, Slug = cat.Slug, IsActive = cat.IsActive };
}
private async Task Save()
else if (loading)
{
error = null;
var name = form.Name.Trim();
var slug = Slugify(string.IsNullOrWhiteSpace(form.Slug) ? name : form.Slug);
if (string.IsNullOrEmpty(slug))
{
error = "Ze zadaného názvu nelze vytvořit slug.";
return;
}
var slugTaken = await Db.Set<Category>().AnyAsync(c => c.Slug == slug && c.Id != (Id ?? 0));
if (slugTaken)
{
error = $"Slug „{slug}“ už používá jiná kategorie.";
return;
}
if (Id is null)
{
Db.Set<Category>().Add(new Category { Name = name, Slug = slug, IsActive = form.IsActive });
<div class="ao-loading">Načítám…</div>
}
else
{
var cat = await Db.Set<Category>().FindAsync(Id);
if (cat is null)
<section class="ao-panel" style="max-width:560px;margin:0 auto">
<div class="ap-field">
<label>Název</label>
<input class="ao-input" @bind="name" />
</div>
<div class="ap-field">
<label>Slug</label>
<input class="ao-input" @bind="categorySlug" />
<small class="ap-help">Když necháš prázdné, vytvoří se z názvu.</small>
</div>
<label class="ap-switch">
<input type="checkbox" @bind="isActive" />
<span>Aktivní kategorie</span>
</label>
<div class="ap-form-actions">
<button type="button" class="ap-btn ap-btn-primary" disabled="@saving" @onclick="SaveAsync">
@(saving ? "Ukládám…" : "Uložit")
</button>
<a class="ap-btn" href="/admin/kategorie">Zrušit</a>
</div>
</section>
}
</div>
@code {
[Parameter]
public int? Id { get; set; }
private bool IsNew => Id is null;
private string name = "";
private string categorySlug = "";
private bool isActive = true;
private bool loading = true;
private bool saving;
private bool notFound;
private string? error;
protected override async Task OnParametersSetAsync()
{
notFound = true;
loading = true;
notFound = false;
error = null;
if (IsNew)
{
name = "";
categorySlug = "";
isActive = true;
loading = false;
return;
}
cat.Name = name;
cat.Slug = slug;
cat.IsActive = form.IsActive;
var entity = await Db.Categories.AsNoTracking().FirstOrDefaultAsync(c => c.Id == Id!.Value);
if (entity is null)
{
notFound = true;
loading = false;
return;
}
name = entity.Name ?? "";
categorySlug = entity.Slug ?? "";
isActive = entity.IsActive;
loading = false;
}
private async Task SaveAsync()
{
saving = true;
error = null;
try
{
if (string.IsNullOrWhiteSpace(name))
{
error = "Zadejte název kategorie.";
return;
}
var finalSlug = string.IsNullOrWhiteSpace(categorySlug)
? name.Trim().ToLowerInvariant().Replace(' ', '-')
: categorySlug.Trim();
Category entity;
if (IsNew)
{
entity = new Category();
Db.Categories.Add(entity);
}
else
{
entity = await Db.Categories.FirstAsync(c => c.Id == Id!.Value);
}
entity.Name = name.Trim();
entity.Slug = finalSlug;
entity.IsActive = isActive;
await Db.SaveChangesAsync();
Nav.NavigateTo("/admin/kategorie");
}
private static string Slugify(string text)
catch (Exception ex)
{
var normalized = text.Trim().ToLowerInvariant().Normalize(NormalizationForm.FormD);
var sb = new StringBuilder();
foreach (var ch in normalized)
{
if (CharUnicodeInfo.GetUnicodeCategory(ch) != UnicodeCategory.NonSpacingMark)
sb.Append(ch);
error = "Uložení se nezdařilo: " + ex.Message;
}
var noDiacritics = sb.ToString().Normalize(NormalizationForm.FormC);
return Regex.Replace(noDiacritics, "[^a-z0-9]+", "-").Trim('-');
}
private class CategoryForm
finally
{
[Required(ErrorMessage = "Zadej název kategorie.")]
[StringLength(100, ErrorMessage = "Název může mít nejvýše 100 znaků.")]
public string Name { get; set; } = "";
public string? Slug { get; set; }
public bool IsActive { get; set; } = true;
saving = false;
}
}
}

View File

@@ -1,115 +1,107 @@
@page "/admin/kategorie"
@layout Web_Jarmark.Components.Layout.Admin.AdminLayout
@rendermode InteractiveServer
@using Microsoft.EntityFrameworkCore
@using Microsoft.AspNetCore.Authorization
@using Web_Jarmark.Data
@using Web_Jarmark.Data.Models
@inject ApplicationDbContext Db
@inject NavigationManager Nav
@using Microsoft.AspNetCore.Authorization
@attribute [Authorize]
<AuthorizeView>
@attribute [Authorize(Roles = "Admin")]
<PageTitle>Kategorie</PageTitle>
<div class="d-flex justify-content-between align-items-center mb-3">
<h3 class="mb-0">Kategorie</h3>
<a class="btn btn-primary" href="/admin/kategorie/edit">+ Nová kategorie</a>
<div class="ap ao">
<header class="ao-hero">
<p class="ao-eyebrow">Administrace</p>
<h1>Kategorie</h1>
<p class="ao-sub">Správa kategorií sortimentu.</p>
<div style="margin-top:16px">
<a class="ap-btn ap-btn-primary" href="/admin/kategorie/edit">Nová kategorie</a>
</div>
</header>
@if (!string.IsNullOrEmpty(error))
{
<div class="ao-alert">@error</div>
}
@if (items is null)
{
<div class="ao-loading">Načítám kategorie…</div>
}
else if (items.Count == 0)
{
<div class="ao-empty">Zatím žádné kategorie.</div>
}
else
{
<section class="ao-panel">
<div class="ao-panel-head">
<div>
<h2>Seznam kategorií</h2>
<p>@items.Count položek</p>
</div>
</div>
<div class="ao-list">
@foreach (var c in items)
{
<article class="ao-card" @key="c.Id">
<div class="ao-card-main" style="cursor:default">
<div class="ao-card-left">
<span class="ao-code">@c.Name</span>
<span class="ao-date">@c.Slug</span>
</div>
<div class="ao-card-mid">
<span class="ao-pay">@c.ProductCount produktů</span>
</div>
<div class="ao-card-right">
<span class="ao-badge @(c.IsActive ? "is-paid" : "is-cancel")">
@(c.IsActive ? "Aktivní" : "Neaktivní")
</span>
</div>
</div>
<div class="sklad-row">
<a class="ap-btn ap-btn-ghost" href="@($"/admin/kategorie/edit/{c.Id}")">Upravit</a>
</div>
</article>
}
</div>
</section>
}
</div>
@if (!string.IsNullOrEmpty(error))
{
<div class="alert alert-danger">@error</div>
}
@if (categories is null)
{
<p><em>Načítám…</em></p>
}
else if (categories.Count == 0)
{
<p class="text-muted">Zatím tu nejsou žádné kategorie.</p>
}
else
{
<table class="table table-striped align-middle">
<thead>
<tr>
<th>Název</th>
<th>Slug</th>
<th class="text-center">Počet produktů</th>
<th class="text-center">Aktivní</th>
<th class="text-end">Akce</th>
</tr>
</thead>
<tbody>
@foreach (var c in categories)
{
<tr>
<td>@c.Name</td>
<td><code>@c.Slug</code></td>
<td class="text-center">@c.ProductCount</td>
<td class="text-center">
<input type="checkbox" class="form-check-input"
checked="@c.IsActive"
@onchange="() => ToggleActive(c.Id)" />
</td>
<td class="text-end">
<a class="btn btn-sm btn-outline-secondary" href="/admin/kategorie/edit/@c.Id">Upravit</a>
<button class="btn btn-sm btn-outline-danger"
disabled="@(c.ProductCount > 0)"
title="@(c.ProductCount > 0 ? "Kategorie obsahuje produkty" : "Smazat")"
@onclick="() => Delete(c.Id)">
Smazat
</button>
</td>
</tr>
}
</tbody>
</table>
}
</AuthorizeView>
@code {
private List<CategoryRow>? categories;
private List<Row>? items;
private string? error;
protected override async Task OnInitializedAsync() => await Load();
private async Task Load()
protected override async Task OnInitializedAsync()
{
categories = await Db.Set<Category>()
try
{
items = await Db.Categories
.AsNoTracking()
.OrderBy(c => c.Name)
.Select(c => new CategoryRow(c.Id, c.Name, c.Slug, c.IsActive, c.Products.Count))
.Select(c => new Row(
c.Id,
c.Name,
c.Slug,
c.IsActive,
c.Products.Count))
.ToListAsync();
}
private async Task ToggleActive(int id)
catch (Exception ex)
{
var cat = await Db.Set<Category>().FindAsync(id);
if (cat is null) return;
cat.IsActive = !cat.IsActive;
await Db.SaveChangesAsync();
await Load();
error = "Nepodařilo se načíst kategorie: " + ex.Message;
items = new();
}
}
private async Task Delete(int id)
{
error = null;
var cat = await Db.Set<Category>()
.Include(c => c.Products)
.FirstOrDefaultAsync(c => c.Id == id);
if (cat is null) return;
if (cat.Products.Count > 0)
{
error = "Kategorii nelze smazat, obsahuje produkty.";
return;
}
Db.Set<Category>().Remove(cat);
await Db.SaveChangesAsync();
await Load();
}
private record CategoryRow(int Id, string Name, string Slug, bool IsActive, int ProductCount);
private sealed record Row(
int Id,
string Name,
string Slug,
bool IsActive,
int ProductCount);
}

View File

@@ -0,0 +1,130 @@
@page "/admin/nastaveni"
@layout Web_Jarmark.Components.Layout.Admin.AdminLayout
@rendermode InteractiveServer
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Identity
@using Microsoft.EntityFrameworkCore
@using Microsoft.AspNetCore.Components.Authorization
@using Web_Jarmark.Data
@using Web_Jarmark.Data.Models
@inject ApplicationDbContext Db
@inject UserManager<ApplicationUser> UserManager
@inject AuthenticationStateProvider AuthState
@attribute [Authorize(Roles = "Admin")]
<PageTitle>Nastavení</PageTitle>
<div class="ap ao">
<header class="ao-hero">
<p class="ao-eyebrow">Administrace</p>
<h1>Nastavení</h1>
<p class="ao-sub">Účet, e-shop a rychlé odkazy.</p>
</header>
@if (loading)
{
<div class="ao-loading">Načítám…</div>
}
else
{
<section class="ao-stats">
<article class="ao-stat">
<span>Uživatelé</span>
<strong>@userCount</strong>
<small>registrovaných</small>
</article>
<article class="ao-stat">
<span>Administrátoři</span>
<strong>@adminCount</strong>
<small>role Admin</small>
</article>
<article class="ao-stat">
<span>Produkty</span>
<strong>@productCount</strong>
<small>v katalogu</small>
</article>
<article class="ao-stat">
<span>Objednávky</span>
<strong>@orderCount</strong>
<small>celkem</small>
</article>
</section>
<section class="ao-panel">
<div class="ao-panel-head">
<div>
<h2>Tvůj účet</h2>
<p>Přihlášený administrátor</p>
</div>
</div>
<div class="ao-list">
<div class="ao-item">
<div><strong>E-mail</strong><span>přihlášení</span></div>
<strong>@currentEmail</strong>
</div>
<div class="ao-item">
<div><strong>Role</strong><span>oprávnění</span></div>
<strong>@currentRoles</strong>
</div>
</div>
<div class="sklad-row">
<a class="ap-btn ap-btn-ghost" href="/Account/Manage">Správa účtu</a>
<a class="ap-btn ap-btn-ghost" href="/Account/Manage/ChangePassword">Změna hesla</a>
</div>
</section>
<section class="ao-panel" style="margin-top:14px">
<div class="ao-panel-head">
<div>
<h2>Rychlé odkazy</h2>
<p>Administrace e-shopu</p>
</div>
</div>
<div class="sklad-row">
<a class="ap-btn" href="/">E-shop</a>
<a class="ap-btn" href="/admin">Přehled</a>
<a class="ap-btn" href="/admin/administratori">Uživatelé</a>
<a class="ap-btn" href="/admin/sklad">Sklad</a>
<a class="ap-btn" href="/admin/objednavky">Objednávky</a>
<a class="ap-btn" href="/admin/statistiky">Statistiky</a>
</div>
</section>
}
</div>
@code {
private bool loading = true;
private int userCount, adminCount, productCount, orderCount;
private string currentEmail = "—";
private string currentRoles = "—";
protected override async Task OnInitializedAsync()
{
try
{
userCount = await UserManager.Users.CountAsync();
var admins = await UserManager.GetUsersInRoleAsync("Admin");
adminCount = admins.Count;
productCount = await Db.Products.CountAsync();
orderCount = await Db.Orders.CountAsync();
var state = await AuthState.GetAuthenticationStateAsync();
var user = state.User;
if (user.Identity?.IsAuthenticated == true)
{
currentEmail = user.Identity?.Name ?? "—";
var appUser = await UserManager.FindByEmailAsync(currentEmail);
if (appUser is not null)
{
var roles = await UserManager.GetRolesAsync(appUser);
currentRoles = roles.Count == 0 ? "bez role" : string.Join(", ", roles);
}
}
}
finally
{
loading = false;
}
}
}

View File

@@ -0,0 +1,231 @@
@page "/admin/objednavky"
@layout Web_Jarmark.Components.Layout.Admin.AdminLayout
@rendermode InteractiveServer
@using Microsoft.EntityFrameworkCore
@using Microsoft.AspNetCore.Authorization
@using Web_Jarmark.Data
@using Web_Jarmark.Data.Models
@inject ApplicationDbContext Db
@attribute [Authorize(Roles = "Admin")]
<PageTitle>Objednávky</PageTitle>
<div class="ap ao">
<header class="ao-hero">
<p class="ao-eyebrow">Administrace</p>
<h1>Objednávky</h1>
<p class="ao-sub">Přehled všech objednávek a jejich aktuálního stavu.</p>
</header>
@if (isLoading)
{
<div class="ao-loading">Načítám objednávky…</div>
}
else if (!string.IsNullOrEmpty(errorMessage))
{
<div class="ao-alert">@errorMessage</div>
}
else
{
<section class="ao-stats">
<article class="ao-stat" style="--i:0">
<span>Celkem</span>
<strong>@orders.Count</strong>
<small>objednávek</small>
</article>
<article class="ao-stat" style="--i:1">
<span>Čeká na zaplacení</span>
<strong>@orders.Count(o => o.Status == OrderStatus.Pending)</strong>
<small>k vyřízení</small>
</article>
<article class="ao-stat" style="--i:2">
<span>Zaplaceno</span>
<strong>@orders.Count(o => o.Status == OrderStatus.Paid)</strong>
<small>uhrazeno</small>
</article>
<article class="ao-stat" style="--i:3">
<span>Hodnota</span>
<strong>@orders.Sum(o => o.TotalAmount).ToString("N0")</strong>
<small>Kč celkem</small>
</article>
</section>
<section class="ao-panel" style="--i:4">
<div class="ao-panel-head">
<div>
<h2>Seznam objednávek</h2>
<p>@FilteredOrders.Count zobrazených</p>
</div>
</div>
<div class="ao-filters">
<input class="ao-input"
placeholder="Hledat podle kódu…"
@bind="searchText"
@bind:event="oninput" />
<select class="ao-select" @bind="statusFilter">
<option value="Vše">Všechny stavy</option>
<option value="Čeká na zaplacení">Čeká na zaplacení</option>
<option value="Zaplaceno">Zaplaceno</option>
<option value="Odesláno">Odesláno</option>
<option value="Dokončeno">Dokončeno</option>
<option value="Zrušeno">Zrušeno</option>
</select>
</div>
@if (FilteredOrders.Count == 0)
{
<div class="ao-empty">Žádné objednávky k zobrazení.</div>
}
else
{
<div class="ao-list">
@foreach (var order in FilteredOrders)
{
var open = selectedOrderId == order.Id;
<article class="ao-card @(open ? "is-open" : null)" @key="order.Id">
<button type="button" class="ao-card-main" @onclick="() => ToggleDetail(order.Id)">
<div class="ao-card-left">
<span class="ao-code">#@order.Code</span>
<span class="ao-date">@order.CreatedAt.ToLocalTime().ToString("d. M. yyyy HH:mm")</span>
</div>
<div class="ao-card-mid">
<span class="ao-pay">@GetPaymentText(order.PreferredPayment)</span>
<span class="ao-qty">@order.OrderItems.Sum(i => i.Quantity) ks</span>
</div>
<div class="ao-card-right">
<span class="ao-price">@order.TotalAmount.ToString("N0") Kč</span>
<span class="ao-badge @GetBadgeClass(order.Status)">@GetStatusText(order.Status)</span>
</div>
<span class="ao-chevron @(open ? "is-open" : null)">›</span>
</button>
@if (open)
{
<div class="ao-detail">
<div class="ao-detail-grid">
<div>
<span>Zákazník</span>
<strong>@(string.IsNullOrWhiteSpace(order.CustomerName) ? "—" : order.CustomerName)</strong>
</div>
<div>
<span>E-mail</span>
<strong>@(string.IsNullOrWhiteSpace(order.Email) ? "—" : order.Email)</strong>
</div>
<div>
<span>Telefon</span>
<strong>@(string.IsNullOrWhiteSpace(order.Phone) ? "—" : order.Phone)</strong>
</div>
<div>
<span>Stav</span>
<strong>@GetStatusText(order.Status)</strong>
</div>
</div>
@if (!string.IsNullOrWhiteSpace(order.Note))
{
<p class="ao-note">@order.Note</p>
}
<div class="ao-items">
@foreach (var item in order.OrderItems)
{
<div class="ao-item">
<div>
<strong>@item.ProductName</strong>
<span>@item.Quantity ks × @item.UnitPrice.ToString("N0") Kč</span>
</div>
<strong>@((item.Quantity * item.UnitPrice).ToString("N0")) Kč</strong>
</div>
}
</div>
<div class="ao-total">
<span>Celkem</span>
<strong>@order.TotalAmount.ToString("N0") Kč</strong>
</div>
</div>
}
</article>
}
</div>
}
</section>
}
</div>
@code {
private List<Order> orders = new();
private bool isLoading = true;
private string? errorMessage;
private string searchText = "";
private string statusFilter = "Vše";
private int? selectedOrderId;
private List<Order> FilteredOrders =>
orders
.Where(o =>
string.IsNullOrWhiteSpace(searchText) ||
o.Code.Contains(searchText.Trim(), StringComparison.OrdinalIgnoreCase))
.Where(o =>
statusFilter == "Vše" ||
GetStatusText(o.Status) == statusFilter)
.ToList();
protected override async Task OnInitializedAsync()
{
try
{
orders = await Db.Orders
.AsNoTracking()
.Include(o => o.OrderItems)
.OrderByDescending(o => o.CreatedAt)
.ToListAsync();
}
catch
{
errorMessage = "Objednávky se nepodařilo načíst.";
}
finally
{
isLoading = false;
}
}
private void ToggleDetail(int orderId)
{
selectedOrderId = selectedOrderId == orderId ? null : orderId;
}
private static string GetStatusText(OrderStatus status) => status switch
{
OrderStatus.Pending => "Čeká na zaplacení",
OrderStatus.Paid => "Zaplaceno",
OrderStatus.Shipped => "Odesláno",
OrderStatus.Delivered => "Dokončeno",
OrderStatus.Cancelled => "Zrušeno",
_ => "Neznámý stav"
};
private static string GetBadgeClass(OrderStatus status) => status switch
{
OrderStatus.Pending => "is-pending",
OrderStatus.Paid => "is-paid",
OrderStatus.Shipped => "is-shipped",
OrderStatus.Delivered => "is-done",
OrderStatus.Cancelled => "is-cancel",
_ => ""
};
private static string GetPaymentText(PaymentMethod method) => method switch
{
PaymentMethod.BankTransfer => "Bankovní převod",
PaymentMethod.Cash => "Hotově",
PaymentMethod.CreditCard => "Karta",
PaymentMethod.PayPal => "PayPal",
_ => "—"
};
}

View File

@@ -0,0 +1,426 @@
/* Apple-like objednávky */
.ao {
max-width: 980px;
margin: 0 auto;
color: #1d1d1f;
font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
-webkit-font-smoothing: antialiased;
}
.ao-hero {
text-align: center;
padding: 18px 8px 28px;
animation: ao-in 0.45s ease both;
}
.ao-eyebrow {
margin: 0 0 8px;
font-size: 12px;
font-weight: 600;
letter-spacing: 0.08em;
text-transform: uppercase;
color: #6e6e73;
}
.ao-hero h1 {
margin: 0;
font-size: 36px;
font-weight: 700;
letter-spacing: -0.03em;
}
.ao-sub {
margin: 10px auto 0;
max-width: 420px;
color: #6e6e73;
font-size: 16px;
}
.ao-loading,
.ao-empty,
.ao-alert {
padding: 20px;
border-radius: 20px;
background: #fff;
border: 1px solid rgba(0, 0, 0, 0.05);
color: #6e6e73;
text-align: center;
}
.ao-alert {
color: #1d1d1f;
margin-bottom: 14px;
}
/* Stats */
.ao-stats {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 12px;
margin-bottom: 16px;
}
.ao-stat {
background: rgba(255, 255, 255, 0.9);
border: 1px solid rgba(0, 0, 0, 0.04);
border-radius: 22px;
padding: 18px 16px;
box-shadow: 0 10px 28px rgba(0, 0, 0, 0.04);
animation: ao-rise 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
animation-delay: calc(var(--i, 0) * 0.06s);
transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.ao-stat:hover {
transform: translateY(-3px);
box-shadow: 0 14px 34px rgba(0, 0, 0, 0.07);
}
.ao-stat span {
display: block;
font-size: 12px;
font-weight: 600;
color: #6e6e73;
}
.ao-stat strong {
display: block;
margin-top: 8px;
font-size: 28px;
font-weight: 750;
letter-spacing: -0.03em;
line-height: 1;
}
.ao-stat small {
display: block;
margin-top: 8px;
font-size: 12px;
color: #86868b;
}
/* Panel */
.ao-panel {
background: rgba(255, 255, 255, 0.92);
border: 1px solid rgba(0, 0, 0, 0.045);
border-radius: 26px;
padding: 18px 18px 12px;
box-shadow: 0 12px 36px rgba(0, 0, 0, 0.04);
animation: ao-rise 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
animation-delay: calc(var(--i, 0) * 0.06s);
}
.ao-panel-head {
display: flex;
justify-content: space-between;
align-items: flex-start;
padding: 4px 6px 14px;
}
.ao-panel-head h2 {
margin: 0;
font-size: 18px;
font-weight: 700;
letter-spacing: -0.02em;
}
.ao-panel-head p {
margin: 4px 0 0;
color: #6e6e73;
font-size: 13px;
}
.ao-filters {
display: flex;
gap: 10px;
flex-wrap: wrap;
padding: 0 6px 16px;
}
.ao-input,
.ao-select {
border: 1px solid #d2d2d7;
border-radius: 14px;
padding: 12px 14px;
font-size: 14px;
background: #fff;
color: #1d1d1f;
outline: none;
transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.ao-input {
flex: 1;
min-width: 180px;
}
.ao-select {
min-width: 190px;
}
.ao-input:focus,
.ao-select:focus {
border-color: #1d1d1f;
box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.06);
}
/* Cards list */
.ao-list {
display: flex;
flex-direction: column;
gap: 10px;
}
.ao-card {
border: 1px solid rgba(0, 0, 0, 0.05);
border-radius: 20px;
background: #fafafa;
overflow: hidden;
transition: background 0.2s ease, box-shadow 0.25s ease, transform 0.2s ease;
}
.ao-card:hover {
background: #f5f5f7;
}
.ao-card.is-open {
background: #fff;
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.06);
}
.ao-card-main {
width: 100%;
border: 0;
background: transparent;
display: grid;
grid-template-columns: 1.2fr 1fr 1fr auto;
gap: 12px;
align-items: center;
padding: 16px 16px;
text-align: left;
cursor: pointer;
color: inherit;
}
.ao-card-left,
.ao-card-mid,
.ao-card-right {
display: flex;
flex-direction: column;
gap: 4px;
min-width: 0;
}
.ao-card-right {
align-items: flex-end;
}
.ao-code {
font-weight: 750;
font-size: 15px;
letter-spacing: -0.02em;
}
.ao-date,
.ao-pay,
.ao-qty {
font-size: 12px;
color: #6e6e73;
}
.ao-price {
font-weight: 750;
font-size: 15px;
}
.ao-badge {
display: inline-flex;
align-items: center;
padding: 4px 10px;
border-radius: 999px;
font-size: 11px;
font-weight: 700;
background: #f0f0f2;
color: #6e6e73;
}
.ao-badge.is-pending {
background: #f0f0f2;
color: #1d1d1f;
}
.ao-badge.is-paid {
background: #1d1d1f;
color: #fff;
}
.ao-badge.is-shipped {
background: #3a3a3c;
color: #fff;
}
.ao-badge.is-done {
background: #1d1d1f;
color: #fff;
}
.ao-badge.is-cancel {
background: #e8e8ed;
color: #6e6e73;
}
.ao-chevron {
font-size: 22px;
color: #aeaeb2;
transform: rotate(0deg);
transition: transform 0.25s ease;
line-height: 1;
}
.ao-chevron.is-open {
transform: rotate(90deg);
color: #1d1d1f;
}
/* Detail */
.ao-detail {
padding: 0 16px 16px;
animation: ao-detail 0.28s ease both;
}
.ao-detail-grid {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 10px;
margin-bottom: 12px;
}
.ao-detail-grid span {
display: block;
font-size: 11px;
color: #6e6e73;
margin-bottom: 3px;
}
.ao-detail-grid strong {
font-size: 13px;
font-weight: 650;
}
.ao-note {
margin: 0 0 12px;
padding: 12px 14px;
border-radius: 14px;
background: #f5f5f7;
color: #6e6e73;
font-size: 13px;
}
.ao-items {
display: flex;
flex-direction: column;
gap: 8px;
}
.ao-item {
display: flex;
justify-content: space-between;
gap: 12px;
padding: 12px 14px;
border-radius: 14px;
background: #f5f5f7;
}
.ao-item span {
display: block;
margin-top: 2px;
font-size: 12px;
color: #6e6e73;
}
.ao-total {
margin-top: 12px;
display: flex;
justify-content: space-between;
align-items: center;
padding: 4px 4px 0;
font-size: 15px;
}
.ao-total strong {
font-size: 18px;
font-weight: 750;
letter-spacing: -0.02em;
}
@keyframes ao-in {
from {
opacity: 0;
transform: translateY(8px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes ao-rise {
from {
opacity: 0;
transform: translateY(14px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes ao-detail {
from {
opacity: 0;
transform: translateY(-6px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@media (max-width: 900px) {
.ao-stats {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.ao-card-main {
grid-template-columns: 1fr auto;
grid-template-areas:
"left chev"
"mid chev"
"right chev";
}
.ao-card-left {
grid-area: left;
}
.ao-card-mid {
grid-area: mid;
}
.ao-card-right {
grid-area: right;
align-items: flex-start;
}
.ao-chevron {
grid-area: chev;
}
.ao-detail-grid {
grid-template-columns: 1fr 1fr;
}
}

View File

@@ -1,189 +1,317 @@
@page "/admin/zbozi/edit"
```razor
@page "/admin/zbozi/edit"
@page "/admin/zbozi/edit/{Id:int}"
@layout Web_Jarmark.Components.Layout.Admin.AdminLayout
@rendermode InteractiveServer
@using System.ComponentModel.DataAnnotations
@using Microsoft.EntityFrameworkCore
@using Microsoft.AspNetCore.Authorization
@using Web_Jarmark.Data
@using Web_Jarmark.Data.Models
@inject ApplicationDbContext Db
@inject NavigationManager Nav
@using Microsoft.AspNetCore.Authorization
@attribute [Authorize]
<AuthorizeView Context="authContext1">
<PageTitle>@(Id is null ? "Nové zboží" : "Upravit zboží")</PageTitle>
@attribute [Authorize(Roles = "Admin")]
<h3>@(Id is null ? "Nové zboží" : "Upravit zboží")</h3>
<PageTitle>@(IsNew ? "Nové zboží" : "Upravit zboží")</PageTitle>
@if (notFound)
{
<div class="alert alert-warning">Zboží nebylo nalezeno.</div>
<a class="btn btn-secondary" href="/admin/zbozi">Zpět na seznam</a>
}
else if (categories is null)
{
<p><em>Načítám…</em></p>
}
else if (categories.Count == 0)
{
<div class="alert alert-warning">
Nejdřív musíš vytvořit aspoň jednu kategorii.
<a href="/admin/kategorie/edit">Přidat kategorii</a>
</div>
}
else
{
<EditForm Model="form" OnValidSubmit="Save" FormName="productForm" style="max-width: 500px;">
<DataAnnotationsValidator />
<ValidationSummary class="text-danger" />
<div class="ap ao">
<header class="ao-hero">
<p class="ao-eyebrow">Zboží</p>
<h1>@(IsNew ? "Nové zboží" : "Upravit zboží")</h1>
<p class="ao-sub">Údaje produktu v katalogu.</p>
</header>
@if (!string.IsNullOrEmpty(error))
{
<div class="alert alert-danger">@error</div>
<div class="ao-alert">@error</div>
}
<div class="mb-3">
<label class="form-label" for="name">Název</label>
<InputText id="name" class="form-control" @bind-Value="form.Name" />
</div>
<div class="mb-3">
<label class="form-label" for="cat">Kategorie</label>
<InputSelect id="cat" class="form-select" @bind-Value="form.CategoryId">
<option value="0">– vyber kategorii –</option>
@foreach (var c in categories)
@if (notFound)
{
<option value="@c.Id">@c.Name@(c.IsActive ? "" : " (neaktivní)")</option>
<div class="ao-empty">Produkt nebyl nalezen.</div>
<div style="text-align:center;margin-top:12px">
<a class="ap-btn" href="/admin/zbozi">Zpět</a>
</div>
}
</InputSelect>
</div>
<div class="mb-3">
<label class="form-label" for="desc">Popis</label>
<InputTextArea id="desc" class="form-control" rows="3" @bind-Value="form.Description" />
</div>
<div class="row">
<div class="col mb-3">
<label class="form-label" for="price">Cena (Kč)</label>
<InputNumber id="price" class="form-control" @bind-Value="form.Price" />
</div>
<div class="col mb-3">
<label class="form-label" for="stock">Skladem (ks)</label>
<InputNumber id="stock" class="form-control" @bind-Value="form.StockQuantity" />
</div>
</div>
<div class="mb-3">
<label class="form-label" for="img">Adresa obrázku</label>
<InputText id="img" class="form-control" @bind-Value="form.ImageUrl" />
<div class="form-text">Např. /images/cukrovi.jpg (soubor v wwwroot) nebo celá adresa.</div>
</div>
<div class="form-check mb-3">
<InputCheckbox id="visible" class="form-check-input" @bind-Value="form.IsVisible" />
<label class="form-check-label" for="visible">Viditelné v katalogu</label>
</div>
<button type="submit" class="btn btn-primary">Uložit</button>
<a class="btn btn-secondary" href="/admin/zbozi">Zrušit</a>
</EditForm>
}
</AuthorizeView>
@code {
[Parameter] public int? Id { get; set; }
private ProductForm form = new();
private List<Category>? categories;
private string? error;
private bool notFound;
protected override async Task OnParametersSetAsync()
else if (loading)
{
categories = await Db.Set<Category>().AsNoTracking().OrderBy(c => c.Name).ToListAsync();
if (Id is null) return;
var p = await Db.Set<Product>().AsNoTracking().FirstOrDefaultAsync(x => x.Id == Id);
if (p is null)
{
notFound = true;
return;
}
form = new ProductForm
{
Name = p.Name,
CategoryId = p.CategoryId,
Description = p.Description,
Price = p.Price,
StockQuantity = p.StockQuantity,
ImageUrl = p.ImageUrl,
IsVisible = p.IsVisible
};
}
private async Task Save()
{
error = null;
if (form.CategoryId == 0)
{
error = "Vyber kategorii.";
return;
}
if (Id is null)
{
var p = new Product();
Apply(p);
Db.Set<Product>().Add(p);
<div class="ao-loading">Načítám…</div>
}
else
{
var p = await Db.Set<Product>().FindAsync(Id);
if (p is null)
<section class="ao-panel" style="max-width:560px;margin:0 auto">
<div class="ap-field">
<label>Název</label>
<input class="ao-input" maxlength="150" @bind="name" />
</div>
<div class="ap-field">
<label>Kategorie</label>
<select class="ao-select" style="width:100%" @bind="categoryId">
<option value="0">— vyberte —</option>
@foreach (var c in categories)
{
notFound = true;
<option value="@c.Id">@c.Name</option>
}
</select>
</div>
<div class="ap-field">
<label>Popis</label>
<textarea class="ao-input"
maxlength="5000"
style="min-height:110px;resize:vertical"
@bind="description"></textarea>
</div>
<div class="ap-field">
<label>Cena (Kč)</label>
<input type="number"
min="0"
step="0.01"
class="ao-input"
@bind="price" />
</div>
<div class="ap-field">
<label>Sklad (ks)</label>
<input type="number"
min="0"
step="1"
class="ao-input"
@bind="stockQuantity" />
</div>
<div class="ap-field">
<label>URL obrázku</label>
<input class="ao-input"
maxlength="2048"
@bind="imageUrl" />
</div>
<label class="ap-switch">
<input type="checkbox" @bind="isVisible" />
<span>Viditelné v e-shopu</span>
</label>
<div class="ap-form-actions">
<button type="button"
class="ap-btn ap-btn-primary"
disabled="@saving"
@onclick="SaveAsync">
@(saving ? "Ukládám…" : "Uložit")
</button>
<a class="ap-btn" href="/admin/zbozi">Zrušit</a>
</div>
</section>
}
</div>
@code {
[Parameter]
public int? Id { get; set; }
private bool IsNew => Id is null;
private List<CatOption> categories = new();
private string name = "";
private string description = "";
private int categoryId;
private decimal price;
private int stockQuantity;
private string imageUrl = "";
private bool isVisible = true;
private bool loading = true;
private bool saving;
private bool notFound;
private string? error;
protected override async Task OnParametersSetAsync()
{
loading = true;
notFound = false;
error = null;
categories = await Db.Categories
.AsNoTracking()
.OrderBy(c => c.Name)
.Select(c => new CatOption(c.Id, c.Name))
.ToListAsync();
if (IsNew)
{
name = "";
description = "";
categoryId = 0;
price = 0;
stockQuantity = 0;
imageUrl = "";
isVisible = true;
loading = false;
return;
}
Apply(p);
var entity = await Db.Products
.AsNoTracking()
.FirstOrDefaultAsync(p => p.Id == Id!.Value);
if (entity is null)
{
notFound = true;
loading = false;
return;
}
name = entity.Name ?? "";
description = entity.Description ?? "";
categoryId = entity.CategoryId;
price = entity.Price;
stockQuantity = entity.StockQuantity;
imageUrl = entity.ImageUrl ?? "";
isVisible = entity.IsVisible;
loading = false;
}
private async Task SaveAsync()
{
if (saving)
return;
saving = true;
error = null;
try
{
name = name?.Trim() ?? "";
description = description?.Trim() ?? "";
imageUrl = imageUrl?.Trim() ?? "";
if (string.IsNullOrWhiteSpace(name))
{
error = "Zadejte název produktu.";
return;
}
if (name.Length > 150)
{
error = "Název může mít maximálně 150 znaků.";
return;
}
if (description.Length > 5000)
{
error = "Popis může mít maximálně 5000 znaků.";
return;
}
if (price < 0 || price > 100000000)
{
error = "Cena musí být mezi 0 a 100 000 000 Kč.";
return;
}
if (decimal.Round(price, 2) != price)
{
error = "Cena může mít maximálně dvě desetinná místa.";
return;
}
if (stockQuantity < 0)
{
error = "Počet kusů na skladě nemůže být záporný.";
return;
}
if (categoryId <= 0 ||
!await Db.Categories.AnyAsync(c => c.Id == categoryId))
{
error = "Vyberte platnou kategorii.";
return;
}
if (!IsValidImageUrl(imageUrl))
{
error = "Obrázek musí mít platnou HTTPS adresu nebo bezpečnou relativní cestu.";
return;
}
Product entity;
if (IsNew)
{
entity = new Product();
Db.Products.Add(entity);
}
else
{
entity = await Db.Products
.FirstOrDefaultAsync(p => p.Id == Id!.Value);
if (entity is null)
{
notFound = true;
error = "Produkt již neexistuje.";
return;
}
}
entity.Name = name;
entity.Description = description;
entity.CategoryId = categoryId;
entity.Price = price;
entity.StockQuantity = stockQuantity;
entity.ImageUrl = imageUrl;
entity.IsVisible = isVisible;
entity.UpdatedAt = DateTime.UtcNow;
await Db.SaveChangesAsync();
Nav.NavigateTo("/admin/zbozi");
}
private void Apply(Product p)
catch (DbUpdateException)
{
p.Name = form.Name.Trim();
p.CategoryId = form.CategoryId;
p.Description = form.Description?.Trim() ?? "";
p.Price = form.Price;
p.StockQuantity = form.StockQuantity;
p.ImageUrl = form.ImageUrl?.Trim() ?? "";
p.IsVisible = form.IsVisible;
p.UpdatedAt = DateTime.Now;
error = "Produkt se nepodařilo uložit. Zkontrolujte zadané údaje.";
}
catch (Exception)
{
error = "Při ukládání nastala neočekávaná chyba.";
}
finally
{
saving = false;
}
}
private class ProductForm
private static bool IsValidImageUrl(string value)
{
[Required(ErrorMessage = "Zadej název zboží.")]
[StringLength(100, ErrorMessage = "Název může mít nejvýše 100 znaků.")]
public string Name { get; set; } = "";
if (string.IsNullOrWhiteSpace(value))
return true;
public int CategoryId { get; set; }
if (value.Length > 2048)
return false;
public string? Description { get; set; }
if (value.StartsWith("//") ||
value.Contains('\\') ||
value.Any(char.IsControl))
return false;
[Range(0, 100000, ErrorMessage = "Cena musí být 0 až 100 000 Kč.")]
public decimal Price { get; set; }
[Range(0, 100000, ErrorMessage = "Počet kusů musí být 0 nebo víc.")]
public int StockQuantity { get; set; }
public string? ImageUrl { get; set; }
public bool IsVisible { get; set; } = true;
if (Uri.TryCreate(value, UriKind.Absolute, out var uri))
{
return uri.Scheme == Uri.UriSchemeHttps &&
!string.IsNullOrWhiteSpace(uri.Host);
}
return value.StartsWith('/') &&
!value.StartsWith("//") &&
!value.Contains("..");
}
private sealed record CatOption(int Id, string Name);
}
```

View File

@@ -1,112 +1,127 @@
@page "/admin/zbozi"
@layout Web_Jarmark.Components.Layout.Admin.AdminLayout
@rendermode InteractiveServer
@using Microsoft.EntityFrameworkCore
@using Microsoft.AspNetCore.Authorization
@using Web_Jarmark.Data
@using Web_Jarmark.Data.Models
@inject ApplicationDbContext Db
@using Microsoft.AspNetCore.Authorization
@attribute [Authorize]
<AuthorizeView>
@attribute [Authorize(Roles = "Admin")]
<PageTitle>Zboží</PageTitle>
<div class="d-flex justify-content-between align-items-center mb-3">
<h3 class="mb-0">Zboží</h3>
<a class="btn btn-primary" href="/admin/zbozi/edit">+ Nové zboží</a>
<div class="ap ao">
<header class="ao-hero">
<p class="ao-eyebrow">Administrace</p>
<h1>Zboží</h1>
<p class="ao-sub">Přehled a správa produktů.</p>
<div style="margin-top:16px">
<a class="ap-btn ap-btn-primary" href="/admin/zbozi/edit">Nové zboží</a>
</div>
</header>
@if (!string.IsNullOrEmpty(error))
{
<div class="ao-alert">@error</div>
}
<div class="ao-filters">
<input class="ao-input" placeholder="Hledat produkt…" @bind="search" @bind:event="oninput" />
</div>
@if (items is null)
{
<div class="ao-loading">Načítám zboží…</div>
}
else if (Filtered.Count == 0)
{
<div class="ao-empty">Žádné produkty.</div>
}
else
{
<section class="ao-panel">
<div class="ao-panel-head">
<div>
<h2>Katalog</h2>
<p>@Filtered.Count položek</p>
</div>
</div>
<div class="ao-list">
@foreach (var p in Filtered)
{
<article class="ao-card" @key="p.Id">
<div class="ao-card-main" style="cursor:default">
<div class="ao-card-left">
<span class="ao-code">@p.Name</span>
<span class="ao-date">@p.CategoryName</span>
</div>
<div class="ao-card-mid">
<span class="ao-pay">@p.Price.ToString("N0") Kč</span>
<span class="ao-qty">@p.StockQuantity ks</span>
</div>
<div class="ao-card-right">
<span class="ao-badge @(p.IsVisible ? "is-paid" : "is-cancel")">
@(p.IsVisible ? "Viditelné" : "Skryté")
</span>
</div>
</div>
<div class="sklad-row">
<a class="ap-btn ap-btn-ghost" href="@($"/admin/zbozi/edit/{p.Id}")">Upravit</a>
</div>
</article>
}
</div>
</section>
}
</div>
@if (!string.IsNullOrEmpty(error))
{
<div class="alert alert-danger">@error</div>
}
@if (products is null)
{
<p><em>Načítám…</em></p>
}
else if (products.Count == 0)
{
<p class="text-muted">Zatím tu není žádné zboží.</p>
}
else
{
<table class="table table-striped align-middle">
<thead>
<tr>
<th>Název</th>
<th>Kategorie</th>
<th class="text-end">Cena</th>
<th class="text-center">Skladem</th>
<th class="text-center">Viditelné</th>
<th class="text-end">Akce</th>
</tr>
</thead>
<tbody>
@foreach (var p in products)
{
<tr>
<td>@p.Name</td>
<td>@p.CategoryName</td>
<td class="text-end">@p.Price.ToString("N2") Kč</td>
<td class="text-center">@p.StockQuantity</td>
<td class="text-center">
<input type="checkbox" class="form-check-input"
checked="@p.IsVisible"
@onchange="() => ToggleVisible(p.Id)" />
</td>
<td class="text-end">
<a class="btn btn-sm btn-outline-secondary" href="/admin/zbozi/edit/@p.Id">Upravit</a>
<button class="btn btn-sm btn-outline-danger" @onclick="() => Delete(p.Id)">Smazat</button>
</td>
</tr>
}
</tbody>
</table>
}
</AuthorizeView>
@code {
private List<ProductRow>? products;
private List<Row>? items;
private string search = "";
private string? error;
protected override async Task OnInitializedAsync() => await Load();
private async Task Load()
private List<Row> Filtered
{
products = await Db.Set<Product>()
get
{
if (items is null) return new();
if (string.IsNullOrWhiteSpace(search)) return items;
return items.Where(p =>
p.Name.Contains(search, StringComparison.OrdinalIgnoreCase) ||
p.CategoryName.Contains(search, StringComparison.OrdinalIgnoreCase)).ToList();
}
}
protected override async Task OnInitializedAsync()
{
try
{
items = await Db.Products
.AsNoTracking()
.OrderBy(p => p.Name)
.Select(p => new ProductRow(p.Id, p.Name, p.Category.Name, p.Price, p.StockQuantity, p.IsVisible))
.Select(p => new Row(
p.Id,
p.Name,
p.Category.Name,
p.Price,
p.StockQuantity,
p.IsVisible))
.ToListAsync();
}
private async Task ToggleVisible(int id)
catch (Exception ex)
{
var p = await Db.Set<Product>().FindAsync(id);
if (p is null) return;
p.IsVisible = !p.IsVisible;
p.UpdatedAt = DateTime.Now;
await Db.SaveChangesAsync();
await Load();
error = "Nepodařilo se načíst zboží: " + ex.Message;
items = new();
}
}
private async Task Delete(int id)
{
error = null;
var p = await Db.Set<Product>()
.Include(x => x.OrderItems)
.FirstOrDefaultAsync(x => x.Id == id);
if (p is null) return;
if (p.OrderItems.Count > 0)
{
error = $"Zboží „{p.Name}“ už je v objednávkách, nelze ho smazat. Odškrtni raději „Viditelné“.";
return;
}
Db.Set<Product>().Remove(p);
await Db.SaveChangesAsync();
await Load();
}
private record ProductRow(int Id, string Name, string CategoryName, decimal Price, int StockQuantity, bool IsVisible);
private sealed record Row(
int Id,
string Name,
string CategoryName,
decimal Price,
int StockQuantity,
bool IsVisible);
}

View File

@@ -0,0 +1,419 @@
@page "/admin/sklad"
@layout Web_Jarmark.Components.Layout.Admin.AdminLayout
@rendermode InteractiveServer
@using Microsoft.EntityFrameworkCore
@using Microsoft.AspNetCore.Authorization
@using Web_Jarmark.Data
@using Web_Jarmark.Data.Models
@inject ApplicationDbContext Db
@attribute [Authorize(Roles = "Admin")]
<PageTitle>Sklad</PageTitle>
<div class="ap ao">
<header class="ao-hero">
<p class="ao-eyebrow">Administrace</p>
<h1>Sklad</h1>
<p class="ao-sub">Sledování zásob, rychlé úpravy a upozornění na nízký stav.</p>
</header>
@if (!string.IsNullOrEmpty(message))
{
<div class="ao-alert">@message</div>
}
@if (loading)
{
<div class="ao-loading">Načítám sklad…</div>
}
else
{
<section class="ao-stats">
<article class="ao-stat" style="--i:0">
<span>Produktů</span>
<strong>@items.Count</strong>
<small>ve skladu</small>
</article>
<article class="ao-stat" style="--i:1">
<span>Nízký sklad</span>
<strong>@items.Count(i => i.StockQuantity > 0 && i.StockQuantity <= LowThreshold)</strong>
<small>≤ @LowThreshold ks</small>
</article>
<article class="ao-stat" style="--i:2">
<span>Vyprodané</span>
<strong>@items.Count(i => i.StockQuantity <= 0)</strong>
<small>0 ks</small>
</article>
<article class="ao-stat" style="--i:3">
<span>Hodnota skladu</span>
<strong>@items.Sum(i => i.Price * i.StockQuantity).ToString("N0")</strong>
<small>@items.Sum(i => i.StockQuantity) ks celkem</small>
</article>
</section>
<div class="ao-filters">
<input class="ao-input" placeholder="Hledat produkt nebo kategorii…"
@bind="search" @bind:event="oninput" />
<select class="ao-select" @bind="stockFilter">
<option value="all">Stav: vše</option>
<option value="ok">V pořádku (&gt;@LowThreshold)</option>
<option value="low">Nízký (1–@LowThreshold)</option>
<option value="out">Vyprodané (0)</option>
</select>
<select class="ao-select" @bind="categoryFilter">
<option value="all">Kategorie: vše</option>
@foreach (var c in categoryNames)
{
<option value="@c">@c</option>
}
</select>
<select class="ao-select" @bind="sortBy">
<option value="stock_asc">Řadit: nejméně kusů</option>
<option value="stock_desc">Řadit: nejvíce kusů</option>
<option value="name">Řadit: název</option>
<option value="value">Řadit: hodnota</option>
</select>
</div>
<div class="sklad-row" style="padding-left:0;padding-right:0">
<button type="button" class="ap-btn ap-btn-ghost" disabled="@busy" @onclick="ReloadAsync">Obnovit</button>
<button type="button" class="ap-btn ap-btn-ghost" disabled="@busy || !HasPending" @onclick="SaveAllAsync">
Uložit všechny změny @(HasPending ? $"({PendingCount})" : "")
</button>
<button type="button" class="ap-btn ap-btn-ghost" disabled="@busy" @onclick="() => QuickFilterOut()">
Jen vyprodané
</button>
<button type="button" class="ap-btn ap-btn-ghost" disabled="@busy" @onclick="() => QuickFilterLow()">
Jen nízký sklad
</button>
</div>
<section class="ao-panel">
<div class="ao-panel-head">
<div>
<h2>Zásoby</h2>
<p>@Filtered.Count položek</p>
</div>
</div>
@if (Filtered.Count == 0)
{
<div class="ao-empty">Nic nenalezeno.</div>
}
else
{
<div class="ao-list">
@foreach (var p in Filtered)
{
var qty = GetEditQty(p.Id);
var dirty = IsDirty(p.Id, p.StockQuantity);
<article class="ao-card @(dirty ? "is-open" : null)" @key="p.Id">
<div class="ao-card-main" style="cursor:default">
<div class="ao-card-left">
<span class="ao-code">@p.Name</span>
<span class="ao-date">@p.CategoryName</span>
</div>
<div class="ao-card-mid">
<span class="ao-pay">@p.Price.ToString("N0") Kč / ks</span>
<span class="ao-qty">hodnota @((p.Price * qty).ToString("N0")) Kč</span>
</div>
<div class="ao-card-right">
<span class="ao-badge @StockBadge(qty)">
@StockLabel(qty)
</span>
@if (dirty)
{
<span class="ao-date">neuloženo</span>
}
</div>
</div>
<div class="sklad-row">
<button type="button" class="ap-btn ap-btn-ghost" disabled="@busy"
@onclick="() => Adjust(p.Id, -5)">
−5
</button>
<button type="button" class="ap-btn ap-btn-ghost" disabled="@busy"
@onclick="() => Adjust(p.Id, -1)">
−
</button>
<input type="number" min="0" class="ao-input sklad-input"
value="@qty"
@onchange="e => OnStockInput(p.Id, e)" />
<button type="button" class="ap-btn ap-btn-ghost" disabled="@busy"
@onclick="() => Adjust(p.Id, 1)">
+
</button>
<button type="button" class="ap-btn ap-btn-ghost" disabled="@busy"
@onclick="() => Adjust(p.Id, 5)">
+5
</button>
<button type="button" class="ap-btn ap-btn-ghost" disabled="@busy"
@onclick="() => Adjust(p.Id, 10)">
+10
</button>
<button type="button" class="ap-btn ap-btn-primary" disabled="@busy"
@onclick="() => SaveOneAsync(p.Id)">
Uložit
</button>
<button type="button" class="ap-btn ap-btn-ghost" disabled="@busy"
@onclick="() => SetQty(p.Id, 0)">
Na 0
</button>
<button type="button" class="ap-btn ap-btn-ghost" disabled="@busy"
@onclick="() => ToggleVisibleAsync(p)">
@(p.IsVisible ? "Skrýt" : "Zobrazit")
</button>
<a class="ap-btn ap-btn-ghost" href="@($"/admin/zbozi/edit/{p.Id}")">Upravit</a>
</div>
</article>
}
</div>
}
</section>
}
</div>
@code {
private const int LowThreshold = 5;
private List<StockRow> items = new();
private readonly Dictionary<int, int> edits = new();
private List<string> categoryNames = new();
private bool loading = true;
private bool busy;
private string? message;
private string search = "";
private string stockFilter = "all";
private string categoryFilter = "all";
private string sortBy = "stock_asc";
private bool HasPending => items.Any(i => IsDirty(i.Id, i.StockQuantity));
private int PendingCount => items.Count(i => IsDirty(i.Id, i.StockQuantity));
private List<StockRow> Filtered
{
get
{
IEnumerable<StockRow> q = items;
if (!string.IsNullOrWhiteSpace(search))
{
q = q.Where(p =>
p.Name.Contains(search, StringComparison.OrdinalIgnoreCase) ||
p.CategoryName.Contains(search, StringComparison.OrdinalIgnoreCase));
}
if (categoryFilter != "all")
{
q = q.Where(p => p.CategoryName == categoryFilter);
}
q = stockFilter switch
{
"ok" => q.Where(p => GetEditQty(p.Id) > LowThreshold),
"low" => q.Where(p =>
{
var n = GetEditQty(p.Id);
return n > 0 && n <= LowThreshold;
}),
"out" => q.Where(p => GetEditQty(p.Id) <= 0),
_ => q
};
q = sortBy switch
{
"stock_desc" => q.OrderByDescending(p => GetEditQty(p.Id)).ThenBy(p => p.Name),
"name" => q.OrderBy(p => p.Name),
"value" => q.OrderByDescending(p => p.Price * GetEditQty(p.Id)),
_ => q.OrderBy(p => GetEditQty(p.Id)).ThenBy(p => p.Name)
};
return q.ToList();
}
}
protected override async Task OnInitializedAsync()
{
await ReloadAsync();
loading = false;
}
private async Task ReloadAsync()
{
items = await Db.Products
.AsNoTracking()
.OrderBy(p => p.Name)
.Select(p => new StockRow(
p.Id,
p.Name,
p.Category.Name,
p.Price,
p.StockQuantity,
p.IsVisible))
.ToListAsync();
categoryNames = items
.Select(i => i.CategoryName)
.Distinct()
.OrderBy(x => x)
.ToList();
edits.Clear();
foreach (var i in items)
edits[i.Id] = i.StockQuantity;
message = null;
}
private int GetEditQty(int id) =>
edits.TryGetValue(id, out var v) ? v : 0;
private bool IsDirty(int id, int original) =>
edits.TryGetValue(id, out var v) && v != original;
private void OnStockInput(int id, ChangeEventArgs e)
{
if (int.TryParse(e.Value?.ToString(), out var val))
edits[id] = Math.Max(0, val);
}
private void Adjust(int id, int delta)
{
edits[id] = Math.Max(0, GetEditQty(id) + delta);
}
private void SetQty(int id, int qty)
{
edits[id] = Math.Max(0, qty);
}
private void QuickFilterOut()
{
stockFilter = "out";
sortBy = "name";
}
private void QuickFilterLow()
{
stockFilter = "low";
sortBy = "stock_asc";
}
private async Task SaveOneAsync(int id)
{
busy = true;
message = null;
try
{
var entity = await Db.Products.FirstOrDefaultAsync(p => p.Id == id);
if (entity is null)
{
message = "Produkt nebyl nalezen.";
return;
}
var qty = GetEditQty(id);
entity.StockQuantity = qty;
entity.UpdatedAt = DateTime.UtcNow;
await Db.SaveChangesAsync();
message = $"Uloženo: {entity.Name} → {qty} ks";
await ReloadAsync();
}
catch (Exception ex)
{
message = "Chyba: " + ex.Message;
}
finally
{
busy = false;
}
}
private async Task SaveAllAsync()
{
busy = true;
message = null;
try
{
var changed = items.Where(i => IsDirty(i.Id, i.StockQuantity)).ToList();
if (changed.Count == 0)
{
message = "Žádné změny k uložení.";
return;
}
var ids = changed.Select(c => c.Id).ToList();
var entities = await Db.Products.Where(p => ids.Contains(p.Id)).ToListAsync();
foreach (var entity in entities)
{
entity.StockQuantity = GetEditQty(entity.Id);
entity.UpdatedAt = DateTime.UtcNow;
}
await Db.SaveChangesAsync();
message = $"Uloženo změn: {entities.Count}";
await ReloadAsync();
}
catch (Exception ex)
{
message = "Hromadné uložení selhalo: " + ex.Message;
}
finally
{
busy = false;
}
}
private async Task ToggleVisibleAsync(StockRow row)
{
busy = true;
message = null;
try
{
var entity = await Db.Products.FirstAsync(p => p.Id == row.Id);
entity.IsVisible = !entity.IsVisible;
entity.UpdatedAt = DateTime.UtcNow;
await Db.SaveChangesAsync();
message = entity.IsVisible ? $"Zobrazeno: {entity.Name}" : $"Skryto v e-shopu: {entity.Name}";
await ReloadAsync();
}
catch (Exception ex)
{
message = ex.Message;
}
finally
{
busy = false;
}
}
private static string StockLabel(int q) =>
q <= 0 ? "Vyprodané" : q <= LowThreshold ? "Nízký sklad" : "V pořádku";
private static string StockBadge(int q) =>
q <= 0 ? "is-cancel" : q <= LowThreshold ? "is-pending" : "is-paid";
private sealed record StockRow(
int Id,
string Name,
string CategoryName,
decimal Price,
int StockQuantity,
bool IsVisible);
}

View File

@@ -0,0 +1,200 @@
@page "/admin/statistiky"
@layout Web_Jarmark.Components.Layout.Admin.AdminLayout
@rendermode InteractiveServer
@using Microsoft.EntityFrameworkCore
@using Microsoft.AspNetCore.Authorization
@using Web_Jarmark.Data
@using Web_Jarmark.Data.Models
@inject ApplicationDbContext Db
@attribute [Authorize(Roles = "Admin")]
<PageTitle>Statistiky</PageTitle>
<div class="ap ao">
<header class="ao-hero">
<p class="ao-eyebrow">Administrace</p>
<h1>Statistiky</h1>
<p class="ao-sub">Přehled e-shopu ze skutečných dat.</p>
</header>
@if (loading)
{
<div class="ao-loading">Načítám statistiky…</div>
}
else if (!string.IsNullOrEmpty(error))
{
<div class="ao-alert">@error</div>
}
else
{
<section class="ao-stats">
<article class="ao-stat">
<span>Objednávky</span>
<strong>@orderCount</strong>
<small>celkem</small>
</article>
<article class="ao-stat">
<span>Tržby</span>
<strong>@revenue.ToString("N0")</strong>
<small>Kč</small>
</article>
<article class="ao-stat">
<span>Produkty</span>
<strong>@productCount</strong>
<small>@visibleCount viditelných</small>
</article>
<article class="ao-stat">
<span>Sklad</span>
<strong>@stockUnits</strong>
<small>@stockValue.ToString("N0") Kč</small>
</article>
</section>
<section class="ao-stats">
<article class="ao-stat">
<span>Čeká na zaplacení</span>
<strong>@pendingCount</strong>
<small>objednávek</small>
</article>
<article class="ao-stat">
<span>Zaplaceno</span>
<strong>@paidCount</strong>
<small>objednávek</small>
</article>
<article class="ao-stat">
<span>Odesláno / dokončeno</span>
<strong>@(shippedCount + deliveredCount)</strong>
<small>objednávek</small>
</article>
<article class="ao-stat">
<span>Zrušeno</span>
<strong>@cancelledCount</strong>
<small>objednávek</small>
</article>
</section>
<section class="ao-panel">
<div class="ao-panel-head">
<div>
<h2>Katalog a sklad</h2>
<p>Aktuální stav</p>
</div>
</div>
<div class="ao-list">
<div class="ao-item">
<div><strong>Kategorie</strong><span>celkem</span></div>
<strong>@categoryCount</strong>
</div>
<div class="ao-item">
<div><strong>Aktivní kategorie</strong><span>v e-shopu</span></div>
<strong>@activeCategoryCount</strong>
</div>
<div class="ao-item">
<div><strong>Nízký sklad</strong><span>≤ 5 ks</span></div>
<strong>@lowStockCount</strong>
</div>
<div class="ao-item">
<div><strong>Vyprodané</strong><span>0 ks</span></div>
<strong>@outOfStockCount</strong>
</div>
</div>
</section>
<section class="ao-panel" style="margin-top:14px">
<div class="ao-panel-head">
<div>
<h2>Poslední objednávky</h2>
<p>Nejnovějších 8</p>
</div>
<a class="ap-btn ap-btn-ghost" href="/admin/objednavky">Všechny</a>
</div>
@if (recentOrders.Count == 0)
{
<div class="ao-empty">Žádné objednávky.</div>
}
else
{
<div class="ao-list">
@foreach (var o in recentOrders)
{
<article class="ao-card">
<div class="ao-card-main" style="cursor:default">
<div class="ao-card-left">
<span class="ao-code">#@o.Code</span>
<span class="ao-date">@o.CreatedAt.ToLocalTime().ToString("d. M. yyyy HH:mm")</span>
</div>
<div class="ao-card-mid">
<span class="ao-pay">@(string.IsNullOrWhiteSpace(o.CustomerName) ? "—" : o.CustomerName)</span>
</div>
<div class="ao-card-right">
<span class="ao-price">@o.TotalAmount.ToString("N0") Kč</span>
</div>
</div>
</article>
}
</div>
}
</section>
}
</div>
@code {
private bool loading = true;
private string? error;
private int orderCount, pendingCount, paidCount, shippedCount, deliveredCount, cancelledCount;
private int productCount, visibleCount, categoryCount, activeCategoryCount;
private int stockUnits, lowStockCount, outOfStockCount;
private decimal revenue, stockValue;
private List<RecentOrder> recentOrders = new();
protected override async Task OnInitializedAsync()
{
try
{
var orders = await Db.Orders.AsNoTracking().ToListAsync();
orderCount = orders.Count;
pendingCount = orders.Count(o => o.Status == OrderStatus.Pending);
paidCount = orders.Count(o => o.Status == OrderStatus.Paid);
shippedCount = orders.Count(o => o.Status == OrderStatus.Shipped);
deliveredCount = orders.Count(o => o.Status == OrderStatus.Delivered);
cancelledCount = orders.Count(o => o.Status == OrderStatus.Cancelled);
revenue = orders
.Where(o => o.Status == OrderStatus.Paid
|| o.Status == OrderStatus.Shipped
|| o.Status == OrderStatus.Delivered)
.Sum(o => o.TotalAmount);
var products = await Db.Products.AsNoTracking().ToListAsync();
productCount = products.Count;
visibleCount = products.Count(p => p.IsVisible);
stockUnits = products.Sum(p => p.StockQuantity);
stockValue = products.Sum(p => p.Price * p.StockQuantity);
lowStockCount = products.Count(p => p.StockQuantity > 0 && p.StockQuantity <= 5);
outOfStockCount = products.Count(p => p.StockQuantity <= 0);
categoryCount = await Db.Categories.CountAsync();
activeCategoryCount = await Db.Categories.CountAsync(c => c.IsActive);
recentOrders = orders
.OrderByDescending(o => o.CreatedAt)
.Take(8)
.Select(o => new RecentOrder(o.Code, o.CustomerName, o.TotalAmount, o.CreatedAt))
.ToList();
}
catch (Exception ex)
{
error = "Statistiky se nepodařilo načíst: " + ex.Message;
}
finally
{
loading = false;
}
}
private sealed record RecentOrder(string Code, string CustomerName, decimal TotalAmount, DateTime CreatedAt);
}

View File

@@ -1,6 +1,942 @@
@page "/Vyrobek{Id:int}"
<h3>DatailVyrobku</h3>
@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
@implements IDisposable
<PageTitle>Detail produktu | Školní jarmark</PageTitle>
<div class="jarmark-product-detail">
<!-- NOTIFIKACE -->
@if (showNotification)
{
<div class="jarmark-detail-notification"
role="status"
aria-live="polite">
<svg width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.8"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true">
<circle cx="12" cy="12" r="9" />
<path d="m8 12 3 3 5-6" />
</svg>
<span>@notificationMessage</span>
</div>
}
<!-- NÁVRAT DO KATALOGU -->
<a href="/" class="jarmark-detail-back">
<svg width="20"
height="20"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.8"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true">
<path d="M19 12H5M12 19l-7-7 7-7" />
</svg>
<span>Zpět do katalogu</span>
</a>
<!-- NAČÍTÁNÍ -->
@if (loading)
{
<div class="jarmark-detail-empty"
role="status"
aria-live="polite">
<h2>Načítáme výrobek</h2>
<p>Informace o výrobku se právě načítají.</p>
</div>
}
else if (product == null)
{
<div class="jarmark-detail-empty">
<svg width="48"
height="48"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.4"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true">
<circle cx="11" cy="11" r="7" />
<path d="m20 20-4-4" />
</svg>
<h2>Výrobek nebyl nalezen</h2>
<p>
Tento výrobek již nemusí být dostupný.
Další výrobky najdete v katalogu.
</p>
<a href="/"
class="jarmark-detail-button">
Prohlédnout nabídku
</a>
</div>
}
else
{
<article class="jarmark-detail-card">
<!-- FOTOGRAFIE -->
<div class="jarmark-detail-image">
@if (!string.IsNullOrWhiteSpace(product.ImageUrl)
&& !imageFailed)
{
<img src="@product.ImageUrl"
alt="@product.Name"
decoding="async"
@onerror="HandleImageError" />
}
else
{
<div class="jarmark-detail-placeholder">
<svg width="80"
height="80"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true">
<rect x="3"
y="3"
width="18"
height="18"
rx="2" />
<circle cx="8.5"
cy="8.5"
r="1.5" />
<path d="m21 15-5-5L5 21" />
</svg>
<span>Fotografie není dostupná</span>
</div>
}
</div>
<!-- INFORMACE O VÝROBKU -->
<div class="jarmark-detail-info">
@if (product.Category is not null)
{
<span class="jarmark-detail-category">
@product.Category.Name
</span>
}
<h1 class="jarmark-detail-title">
@product.Name
</h1>
@if (!string.IsNullOrWhiteSpace(product.Description))
{
<p class="jarmark-detail-description">
@product.Description
</p>
}
<!-- SKLADOVÁ DOSTUPNOST -->
<div class="jarmark-detail-stock @(product.StockQuantity > 0 ? "is-available" : "is-unavailable")">
<span class="jarmark-detail-stock-dot"
aria-hidden="true">
</span>
@if (product.StockQuantity > 0)
{
<span>
Skladem: @product.StockQuantity ks
</span>
}
else
{
<span>Není skladem</span>
}
</div>
<!-- CENA A NÁKUP -->
<div class="jarmark-detail-purchase">
<div class="jarmark-detail-price-area">
<span class="jarmark-detail-price-label">
Cena produktu
</span>
<strong class="jarmark-detail-price">
@product.Price.ToString("N0") Kč
</strong>
</div>
<button type="button"
class="jarmark-detail-button"
disabled="@(product.StockQuantity <= 0)"
@onclick="() => HandleAddToCart(product)">
@if (product.StockQuantity > 0)
{
<svg width="22"
height="22"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.7"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true">
<path d="M3 3h2l3.5 13h10l3-10H6" />
<circle cx="10"
cy="20"
r="1" />
<circle cx="18"
cy="20"
r="1" />
</svg>
<span>Přidat do košíku</span>
}
else
{
<span>Vyprodáno</span>
}
</button>
</div>
</div>
</article>
}
</div>
<style>
/* ========================================
PUBLIC PRODUCT DETAIL
======================================== */
.jarmark-product-detail {
--detail-primary: #244b36;
--detail-primary-hover: #193b29;
--detail-secondary: #e6eddf;
--detail-surface: #ffffff;
--detail-text: #26372b;
--detail-muted: #59665b;
--detail-border: #dce3d9;
width: 100%;
max-width: 1200px;
min-width: 0;
margin: 0 auto;
color: var(--detail-text);
font-family: inherit;
box-sizing: border-box;
}
/* ========================================
BACK LINK
======================================== */
.jarmark-product-detail .jarmark-detail-back {
display: inline-flex;
align-items: center;
gap: 8px;
min-height: 44px;
margin: 0 0 20px;
padding: 8px 0;
color: var(--detail-primary);
font-size: 14px;
font-weight: 600;
line-height: 1.4;
text-decoration: none;
}
.jarmark-product-detail .jarmark-detail-back svg {
flex-shrink: 0;
}
.jarmark-product-detail .jarmark-detail-back:hover {
color: var(--detail-primary-hover);
text-decoration: underline;
text-underline-offset: 4px;
}
/* ========================================
PRODUCT CARD
======================================== */
.jarmark-product-detail .jarmark-detail-card {
display: grid;
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
align-items: start;
gap: 40px;
width: 100%;
min-width: 0;
padding: 32px;
background: var(--detail-surface);
border: 1px solid var(--detail-border);
border-radius: 12px;
box-sizing: border-box;
}
/* ========================================
PRODUCT IMAGE
======================================== */
.jarmark-product-detail .jarmark-detail-image {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
min-width: 0;
aspect-ratio: 1 / 1;
background: #edf0e9;
border: 1px solid var(--detail-border);
border-radius: 8px;
overflow: hidden;
}
.jarmark-product-detail .jarmark-detail-image img {
display: block;
width: 100%;
height: 100%;
max-width: 100%;
padding: 20px;
object-fit: contain;
object-position: center;
box-sizing: border-box;
}
/* ========================================
IMAGE PLACEHOLDER
======================================== */
.jarmark-product-detail .jarmark-detail-placeholder {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 16px;
width: 100%;
height: 100%;
padding: 24px;
background: var(--detail-secondary);
color: #64815d;
text-align: center;
}
.jarmark-product-detail .jarmark-detail-placeholder span {
color: var(--detail-muted);
font-size: 14px;
font-weight: 500;
}
/* ========================================
PRODUCT INFORMATION
======================================== */
.jarmark-product-detail .jarmark-detail-info {
display: flex;
flex-direction: column;
gap: 16px;
width: 100%;
min-width: 0;
padding: 12px 0;
}
.jarmark-product-detail .jarmark-detail-category {
display: block;
color: var(--detail-muted);
font-size: 14px;
font-weight: 500;
line-height: 1.5;
letter-spacing: normal;
text-transform: none;
overflow-wrap: anywhere;
}
.jarmark-product-detail .jarmark-detail-title {
margin: 0;
color: var(--detail-text);
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 4vw, 44px);
font-weight: 700;
line-height: 1.2;
letter-spacing: normal;
overflow-wrap: anywhere;
}
.jarmark-product-detail .jarmark-detail-description {
margin: 0;
color: var(--detail-muted);
font-size: 16px;
line-height: 1.8;
white-space: pre-line;
overflow-wrap: anywhere;
}
/* ========================================
STOCK AVAILABILITY
======================================== */
.jarmark-product-detail .jarmark-detail-stock {
display: inline-flex;
align-items: center;
gap: 8px;
align-self: flex-start;
margin-top: 8px;
font-size: 14px;
font-weight: 600;
line-height: 1.5;
}
.jarmark-product-detail .jarmark-detail-stock-dot {
display: inline-block;
flex-shrink: 0;
width: 8px;
height: 8px;
background: currentColor;
border-radius: 50%;
}
.jarmark-product-detail .is-available {
color: #34754b;
}
.jarmark-product-detail .is-unavailable {
color: #93483e;
}
/* ========================================
PURCHASE SECTION
======================================== */
.jarmark-product-detail .jarmark-detail-purchase {
display: flex;
flex-direction: column;
gap: 24px;
width: 100%;
margin-top: 12px;
padding-top: 24px;
border-top: 1px solid var(--detail-border);
}
.jarmark-product-detail .jarmark-detail-price-area {
display: flex;
flex-direction: column;
gap: 4px;
}
.jarmark-product-detail .jarmark-detail-price-label {
color: var(--detail-muted);
font-size: 14px;
font-weight: 500;
}
.jarmark-product-detail .jarmark-detail-price {
color: var(--detail-primary);
font-size: clamp(32px, 4vw, 44px);
font-weight: 750;
line-height: 1.2;
font-variant-numeric: tabular-nums;
overflow-wrap: anywhere;
}
/* ========================================
ADD TO CART BUTTON
======================================== */
.jarmark-product-detail .jarmark-detail-button {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 12px;
width: 100%;
min-height: 52px;
margin: 0;
padding: 12px 24px;
background: var(--detail-primary);
color: #ffffff;
border: 1px solid var(--detail-primary);
border-radius: 6px;
font-family: inherit;
font-size: 15px;
font-weight: 650;
line-height: 1.5;
text-align: center;
text-decoration: none;
cursor: pointer;
transition: background-color 150ms ease, border-color 150ms ease;
}
.jarmark-product-detail .jarmark-detail-button svg {
flex-shrink: 0;
}
.jarmark-product-detail .jarmark-detail-button:not(:disabled):hover {
background: var(--detail-primary-hover);
border-color: var(--detail-primary-hover);
color: #ffffff;
text-decoration: none;
}
.jarmark-product-detail .jarmark-detail-button:disabled {
background: #e9ece7;
color: #59665b;
border-color: var(--detail-border);
opacity: 1;
cursor: not-allowed;
}
/* ========================================
EMPTY AND LOADING STATES
======================================== */
.jarmark-product-detail .jarmark-detail-empty {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 16px;
min-height: 220px;
padding: 32px;
background: var(--detail-surface);
border: 1px solid var(--detail-border);
border-radius: 8px;
}
.jarmark-product-detail .jarmark-detail-empty svg {
color: #64815d;
}
.jarmark-product-detail .jarmark-detail-empty h2 {
margin: 0;
color: var(--detail-text);
font-size: 28px;
line-height: 1.3;
}
.jarmark-product-detail .jarmark-detail-empty p {
margin: 0;
color: var(--detail-muted);
font-size: 15px;
line-height: 1.6;
}
.jarmark-product-detail .jarmark-detail-empty .jarmark-detail-button {
width: auto;
margin-top: 8px;
}
/* ========================================
CART NOTIFICATION
======================================== */
.jarmark-product-detail .jarmark-detail-notification {
position: fixed;
top: 96px;
right: 24px;
z-index: 500;
display: flex;
align-items: center;
gap: 12px;
max-width: 420px;
padding: 16px 20px;
background: var(--detail-surface);
color: var(--detail-text);
border: 1px solid #c7d6c2;
border-left: 4px solid var(--detail-primary);
border-radius: 8px;
box-shadow: 0 4px 16px rgba(0, 0, 0, .08);
font-size: 14px;
font-weight: 500;
line-height: 1.5;
overflow-wrap: anywhere;
}
.jarmark-product-detail .jarmark-detail-notification svg {
flex-shrink: 0;
color: var(--detail-primary);
}
/* ========================================
KEYBOARD ACCESSIBILITY
======================================== */
.jarmark-product-detail .jarmark-detail-back:focus-visible,
.jarmark-product-detail .jarmark-detail-button:focus-visible {
outline: 3px solid #527b49;
outline-offset: 4px;
}
/* ========================================
TABLET
======================================== */
@@media (max-width: 1024px) {
.jarmark-product-detail .jarmark-detail-card {
gap: 24px;
padding: 24px;
}
.jarmark-product-detail .jarmark-detail-title {
font-size: 32px;
}
.jarmark-product-detail .jarmark-detail-info {
padding: 4px 0;
}
.jarmark-product-detail .jarmark-detail-description {
font-size: 15px;
}
.jarmark-product-detail .jarmark-detail-image img {
padding: 16px;
}
}
/* ========================================
MOBILE
======================================== */
@@media (max-width: 768px) {
.jarmark-product-detail .jarmark-detail-card {
grid-template-columns: minmax(0, 1fr);
gap: 24px;
padding: 16px;
border-radius: 8px;
}
.jarmark-product-detail .jarmark-detail-back {
margin-bottom: 12px;
}
.jarmark-product-detail .jarmark-detail-image {
aspect-ratio: 4 / 3;
}
.jarmark-product-detail .jarmark-detail-info {
gap: 12px;
padding: 0;
}
.jarmark-product-detail .jarmark-detail-title {
font-size: 30px;
}
.jarmark-product-detail .jarmark-detail-description {
font-size: 15px;
line-height: 1.7;
}
.jarmark-product-detail .jarmark-detail-purchase {
gap: 16px;
margin-top: 8px;
padding-top: 20px;
}
.jarmark-product-detail .jarmark-detail-price {
font-size: 34px;
}
.jarmark-product-detail .jarmark-detail-button {
min-height: 52px;
padding: 12px 16px;
font-size: 15px;
}
.jarmark-product-detail .jarmark-detail-notification {
top: auto;
right: 12px;
bottom: 16px;
left: 12px;
max-width: none;
padding: 16px;
}
}
/* ========================================
SMALL MOBILE
======================================== */
@@media (max-width: 480px) {
.jarmark-product-detail .jarmark-detail-card {
gap: 20px;
padding: 12px;
}
.jarmark-product-detail .jarmark-detail-image {
aspect-ratio: 1 / 1;
}
.jarmark-product-detail .jarmark-detail-image img {
padding: 12px;
}
.jarmark-product-detail .jarmark-detail-title {
font-size: 28px;
}
.jarmark-product-detail .jarmark-detail-category {
font-size: 13px;
}
.jarmark-product-detail .jarmark-detail-empty {
padding: 20px;
}
.jarmark-product-detail .jarmark-detail-empty h2 {
font-size: 24px;
}
.jarmark-product-detail .jarmark-detail-empty .jarmark-detail-button {
width: 100%;
}
}
/* ========================================
REDUCED MOTION
======================================== */
@@media (prefers-reduced-motion: reduce) {
.jarmark-product-detail,
.jarmark-product-detail * {
animation: none !important;
transition: none !important;
scroll-behavior: auto !important;
}
}
</style>
@code {
[Parameter]
public int Id { get; set; }
private Product? product;
private bool loading = true;
private string? cartToken;
private bool showNotification;
private string notificationMessage = "";
private CancellationTokenSource? notificationCts;
private bool imageFailed;
private void HandleImageError()
{
imageFailed = true;
}
protected override async Task OnInitializedAsync()
{
if (!ApplicationState.TryTakeFromJson<string>(
"CartToken", out cartToken)
|| string.IsNullOrWhiteSpace(cartToken))
{
var context = HttpContextAccessor.HttpContext;
cartToken = context?.Items["CartToken"] as string
?? context?.Request.Cookies["CartToken"];
}
}
protected override async Task OnParametersSetAsync()
{
loading = true;
imageFailed = false;
product = await DbContext.Products
.Include(p => p.Category)
.FirstOrDefaultAsync(p => p.Id == Id);
loading = false;
}
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();
await ShowCartNotification(product.Name);
}
private async Task ShowCartNotification(string productName)
{
notificationCts?.Cancel();
var currentCts = new CancellationTokenSource();
notificationCts = currentCts;
notificationMessage = $"{productName} byl přidán do košíku.";
showNotification = true;
await InvokeAsync(StateHasChanged);
try
{
await Task.Delay(3500, currentCts.Token);
if (!currentCts.Token.IsCancellationRequested)
{
showNotification = false;
await InvokeAsync(StateHasChanged);
}
}
catch (OperationCanceledException)
{
// Nové přidání produktu restartovalo čas notifikace.
}
finally
{
if (ReferenceEquals(notificationCts, currentCts))
{
notificationCts = null;
currentCts.Dispose();
}
}
}
public void Dispose()
{
notificationCts?.Cancel();
notificationCts?.Dispose();
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,606 @@
@using Web_Jarmark.Data.Models
@using Microsoft.AspNetCore.Components.Web
@inject NavigationManager NavigationManager
<article class="jarmark-product-card">
<!-- FOTOGRAFIE PRODUKTU -->
<div class="jarmark-card-picture">
@if (!string.IsNullOrWhiteSpace(Product.ImageUrl) && !imageFailed)
{
<img src="@Product.ImageUrl.Trim()"
alt="@Product.Name"
loading="lazy"
decoding="async"
@onerror="HandleImageError" />
}
else
{
<div class="jarmark-card-placeholder"
aria-hidden="true">
<span>@ProductIcon</span>
</div>
}
</div>
<!-- INFORMACE O PRODUKTU -->
<div class="jarmark-card-body">
@if (Product.Category is not null)
{
<div class="jarmark-card-category">
@Product.Category.Name
</div>
}
<h3 class="jarmark-card-title">
<a href="@($"/produkt/{Product.Id}")"
class="jarmark-card-detail">
@Product.Name
</a>
</h3>
@if (!string.IsNullOrWhiteSpace(Product.Description))
{
<p class="jarmark-card-description">
@Product.Description
</p>
}
<!-- DOSTUPNOST -->
<div class="jarmark-card-stock @(Product.StockQuantity <= 0 ? "is-unavailable" : "is-available")">
<span class="jarmark-stock-indicator"
aria-hidden="true">
</span>
@if (Product.StockQuantity > 0)
{
<span>Skladem: @Product.StockQuantity ks</span>
}
else
{
<span>Není skladem</span>
}
</div>
<!-- CENA A AKCE -->
<div class="jarmark-card-actions">
<div class="jarmark-card-price">
<strong>@Product.Price.ToString("N0") Kč</strong>
</div>
@if (OnAddToCart.HasDelegate)
{
<button type="button"
class="jarmark-card-cart"
disabled="@(Product.StockQuantity <= 0)"
aria-label="@($"Přidat do košíku: {Product.Name}")"
@onclick="AddToCart"
@onclick:stopPropagation="true">
@if (Product.StockQuantity > 0)
{
<svg width="20"
height="20"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.7"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true">
<path d="M3 3h2l3.5 13h10l3-10H6" />
<circle cx="10"
cy="20"
r="1" />
<circle cx="18"
cy="20"
r="1" />
</svg>
<span>Do košíku</span>
}
else
{
<span>Vyprodáno</span>
}
</button>
}
</div>
</div>
</article>
<style>
/* ========================================
PUBLIC PRODUCT CARD
======================================== */
.jarmark-product-card {
--card-primary: #244b36;
--card-primary-hover: #193b29;
--card-surface: #ffffff;
--card-text: #26372b;
--card-muted: #59665b;
--card-border: #dce3d9;
position: relative;
isolation: isolate;
display: flex;
flex-direction: column;
width: 100%;
min-width: 0;
height: 100%;
margin: 0;
padding: 0;
background: var(--card-surface);
color: var(--card-text);
border: 1px solid var(--card-border);
border-radius: 8px;
overflow: hidden;
box-sizing: border-box;
font-family: inherit;
transition: border-color 150ms ease;
}
.jarmark-product-card:hover {
border-color: #9aad96;
}
/* ========================================
PRODUCT IMAGE
======================================== */
.jarmark-product-card .jarmark-card-picture {
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
aspect-ratio: 4 / 3;
overflow: hidden;
background: #edf0e9;
border-bottom: 1px solid var(--card-border);
}
.jarmark-product-card .jarmark-card-picture img {
display: block;
width: 100%;
height: 100%;
max-width: 100%;
object-fit: contain;
object-position: center;
margin: 0;
padding: 12px;
box-sizing: border-box;
}
/* ========================================
IMAGE FALLBACK
======================================== */
.jarmark-product-card .jarmark-card-placeholder {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
min-height: 120px;
background: #e6eddf;
color: var(--card-primary);
}
.jarmark-product-card .jarmark-card-placeholder span {
display: block;
font-size: 48px;
line-height: 1;
}
/* ========================================
CARD CONTENT
======================================== */
.jarmark-product-card .jarmark-card-body {
display: flex;
flex: 1;
flex-direction: column;
gap: 12px;
min-width: 0;
padding: 20px;
}
/* ========================================
CATEGORY
======================================== */
.jarmark-product-card .jarmark-card-category {
margin: 0;
color: var(--card-muted);
font-size: 13px;
font-weight: 500;
line-height: 1.4;
letter-spacing: normal;
text-transform: none;
overflow-wrap: anywhere;
}
/* ========================================
PRODUCT NAME AND DETAIL LINK
======================================== */
.jarmark-product-card .jarmark-card-title {
margin: 0;
color: var(--card-text);
font-family: Georgia, "Times New Roman", serif;
font-size: 21px;
font-weight: 700;
line-height: 1.3;
letter-spacing: normal;
overflow-wrap: anywhere;
}
.jarmark-product-card .jarmark-card-detail {
color: inherit;
text-decoration: none;
}
.jarmark-product-card .jarmark-card-detail:hover {
color: var(--card-primary);
text-decoration: underline;
text-underline-offset: 4px;
}
/*
Celá karta zůstává kliknutelná.
Tlačítko košíku má vlastní vrstvu.
*/
.jarmark-product-card .jarmark-card-detail::after {
content: "";
position: absolute;
inset: 0;
z-index: 1;
border-radius: 8px;
}
.jarmark-product-card .jarmark-card-detail:focus-visible::after {
outline: 3px solid #527b49;
outline-offset: -3px;
}
/* ========================================
DESCRIPTION
======================================== */
.jarmark-product-card .jarmark-card-description {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
overflow: hidden;
overflow-wrap: anywhere;
margin: 0;
color: var(--card-muted);
font-size: 14px;
line-height: 1.6;
}
/* ========================================
STOCK AVAILABILITY
======================================== */
.jarmark-product-card .jarmark-card-stock {
display: flex;
align-items: center;
gap: 8px;
margin: 4px 0 0;
font-size: 13px;
font-weight: 600;
line-height: 1.4;
}
.jarmark-product-card .jarmark-stock-indicator {
display: inline-block;
flex-shrink: 0;
width: 8px;
height: 8px;
background: currentColor;
border-radius: 50%;
}
.jarmark-product-card .is-available {
color: #34754b;
}
.jarmark-product-card .is-unavailable {
color: #93483e;
}
/* ========================================
PRICE AND ACTIONS
======================================== */
.jarmark-product-card .jarmark-card-actions {
display: flex;
flex-direction: column;
gap: 12px;
margin-top: auto;
padding-top: 12px;
}
.jarmark-product-card .jarmark-card-price {
display: flex;
align-items: baseline;
margin: 0;
color: var(--card-primary);
font-size: 26px;
line-height: 1.2;
font-variant-numeric: tabular-nums;
}
.jarmark-product-card .jarmark-card-price strong {
font-weight: 750;
}
/* ========================================
ADD TO CART BUTTON
======================================== */
.jarmark-product-card .jarmark-card-cart {
position: relative;
z-index: 2;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
width: 100%;
min-height: 48px;
margin: 0;
padding: 12px 16px;
background: var(--card-primary);
color: #ffffff;
border: 1px solid var(--card-primary);
border-radius: 6px;
font-family: inherit;
font-size: 14px;
font-weight: 650;
line-height: 1.4;
text-align: center;
cursor: pointer;
transition: background-color 150ms ease, border-color 150ms ease;
}
.jarmark-product-card .jarmark-card-cart svg {
flex-shrink: 0;
}
.jarmark-product-card .jarmark-card-cart:not(:disabled):hover {
background: var(--card-primary-hover);
border-color: var(--card-primary-hover);
color: #ffffff;
}
.jarmark-product-card .jarmark-card-cart:disabled {
background: #e9ece7;
color: #59665b;
border-color: #dce3d9;
opacity: 1;
cursor: not-allowed;
}
.jarmark-product-card .jarmark-card-cart:focus-visible {
outline: 3px solid #527b49;
outline-offset: 3px;
}
/* ========================================
TABLET
======================================== */
@@media (max-width: 1024px) {
.jarmark-product-card .jarmark-card-body {
padding: 16px;
}
.jarmark-product-card .jarmark-card-title {
font-size: 20px;
}
.jarmark-product-card .jarmark-card-price {
font-size: 24px;
}
}
/* ========================================
MOBILE
======================================== */
@@media (max-width: 640px) {
.jarmark-product-card .jarmark-card-body {
gap: 8px;
padding: 12px;
}
.jarmark-product-card .jarmark-card-title {
font-size: 18px;
}
.jarmark-product-card .jarmark-card-category {
font-size: 12px;
}
.jarmark-product-card .jarmark-card-description {
font-size: 13px;
-webkit-line-clamp: 2;
}
.jarmark-product-card .jarmark-card-stock {
gap: 4px;
font-size: 12px;
}
.jarmark-product-card .jarmark-card-price {
font-size: 22px;
}
.jarmark-product-card .jarmark-card-cart {
min-height: 48px;
padding: 12px 8px;
font-size: 13px;
}
.jarmark-product-card .jarmark-card-cart svg {
width: 18px;
height: 18px;
}
.jarmark-product-card .jarmark-card-placeholder span {
font-size: 40px;
}
}
/* ========================================
SINGLE COLUMN MOBILE
======================================== */
@@media (max-width: 480px) {
.jarmark-product-card .jarmark-card-body {
gap: 12px;
padding: 16px;
}
.jarmark-product-card .jarmark-card-title {
font-size: 22px;
}
.jarmark-product-card .jarmark-card-description {
font-size: 14px;
-webkit-line-clamp: 3;
}
.jarmark-product-card .jarmark-card-category {
font-size: 13px;
}
.jarmark-product-card .jarmark-card-stock {
gap: 8px;
font-size: 13px;
}
.jarmark-product-card .jarmark-card-price {
font-size: 26px;
}
.jarmark-product-card .jarmark-card-cart {
font-size: 15px;
}
}
/* ========================================
REDUCED MOTION
======================================== */
@@media (prefers-reduced-motion: reduce) {
.jarmark-product-card,
.jarmark-product-card * {
animation: none !important;
transition: none !important;
scroll-behavior: auto !important;
}
}
</style>
@code {
[Parameter, EditorRequired]
public Product Product { get; set; } = default!;
[Parameter]
public EventCallback<Product> OnAddToCart { get; set; }
private bool imageFailed;
protected override void OnParametersSet()
{
imageFailed = false;
}
private void HandleImageError()
{
imageFailed = true;
}
private string ProductIcon =>
Product.Category?.Name.Contains(
"med",
StringComparison.OrdinalIgnoreCase) == true ? "🍯" :
Product.Category?.Name.Contains(
"cuk",
StringComparison.OrdinalIgnoreCase) == true ? "🍪" :
Product.Category?.Name.Contains(
"dřev",
StringComparison.OrdinalIgnoreCase) == true ? "🪵" :
"🎁";
private async Task AddToCart()
{
await OnAddToCart.InvokeAsync(Product);
}
}

View File

@@ -1,25 +1,72 @@
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Web_Jarmark.Data;
using Web_Jarmark.Data.Models;
namespace Web_Jarmark.Data
{
public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : IdentityDbContext<ApplicationUser>(options)
public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: IdentityDbContext<ApplicationUser>(options)
{
public DbSet<Category> Categories { get; set; }
public DbSet<Product> Products { get; set; }
public DbSet<Cart> Carts { get; set; }
public DbSet<CartItem> CartItems { get; set; }
// Objednávky
public DbSet<Order> Orders { get; set; }
public DbSet<OrderItem> OrderItems { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// Nastavení vazby 1:N mezi Category a Product
// Kategorie a produkty
modelBuilder.Entity<Category>()
.HasMany(c => c.Products) // Jedna kategorie obsahuje mnoho produktů
.WithOne(p => p.Category) // Každý produkt patří ke jedné kategorii
.HasForeignKey(p => p.CategoryId); // Cizí klíč v tabulce Product
}
}
.HasMany(c => c.Products)
.WithOne(p => p.Category)
.HasForeignKey(p => p.CategoryId);
// Košík a položky košíku
modelBuilder.Entity<Cart>()
.HasMany(c => c.CartItems)
.WithOne(ci => ci.Cart)
.HasForeignKey(ci => ci.CartId);
// Položka košíku odkazuje na produkt
modelBuilder.Entity<CartItem>()
.HasOne(ci => ci.Product)
.WithMany()
.HasForeignKey(ci => ci.ProductId);
// Produkt může být v košíku pouze jednou
modelBuilder.Entity<CartItem>()
.HasIndex(ci => new { ci.CartId, ci.ProductId })
.IsUnique();
// Token košíku musí být unikátní
modelBuilder.Entity<Cart>()
.HasIndex(c => c.Token)
.IsUnique();
// Zachování původních názvů tabulek objednávek
modelBuilder.Entity<Order>()
.ToTable("Order");
modelBuilder.Entity<OrderItem>()
.ToTable("OrderItem");
// Objednávka a její položky
modelBuilder.Entity<Order>()
.HasMany(o => o.OrderItems)
.WithOne(oi => oi.Order)
.HasForeignKey(oi => oi.OrderId);
// Položka objednávky odkazuje na produkt
modelBuilder.Entity<OrderItem>()
.HasOne(oi => oi.Product)
.WithMany(p => p.OrderItems)
.HasForeignKey(oi => oi.ProductId);
}
}
}

View File

@@ -1,10 +1,17 @@
using Microsoft.AspNetCore.Identity;
namespace Web_Jarmark.Data
{
// Add profile data for application users by adding properties to the ApplicationUser class
public class ApplicationUser : IdentityUser
{
}
// Jméno uživatele
public string? FirstName { get; set; }
// Příjmení uživatele
public string? LastName { get; set; }
// Datum registrace
public DateTime? CreatedAt { get; set; }
}
}

View File

@@ -0,0 +1,18 @@
namespace Web_Jarmark.Data.Models
{
public class Cart
{
public int Id { get; set; }
// Unikátní identifikátor návštěvníka v prohlížeči
public string Token { get; set; } = Guid.NewGuid().ToString();
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
// Navigační vlastnost pro položky košíku
public ICollection<CartItem> CartItems { get; set; } = new List<CartItem>();
}
}

View File

@@ -0,0 +1,19 @@
namespace Web_Jarmark.Data.Models
{
public class CartItem
{
public int Id { get; set; }
public int CartId { get; set; }
public int ProductId { get; set; }
public int Quantity { get; set; } = 1;
// Navigační vlastnosti
public Cart Cart { get; set; } = null!;
public Product Product { get; set; } = null!;
}
}

View File

@@ -1,4 +1,5 @@
namespace Web_Jarmark.Data.Models
namespace Web_Jarmark.Data.Models
{
public enum OrderStatus
{
@@ -8,6 +9,7 @@
Delivered,
Cancelled
}
public enum PaymentMethod
{
CreditCard,
@@ -19,23 +21,36 @@
public class Order
{
public int Id { get; set; }
public string Code { get; set; }
public OrderStatus Status { get; set; }
public string CustomerName { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public string Note { get; set; }
public string Code { get; set; } =
Guid.NewGuid().ToString("N")[..8].ToUpper();
// Bezpečný přístup k detailu objednávky
public string AccessTokenHash { get; set; } = string.Empty;
public OrderStatus Status { get; set; } = OrderStatus.Pending;
// Původní údaje zachované kvůli databázi
public string CustomerName { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string Phone { get; set; } = string.Empty;
public string Note { get; set; } = string.Empty;
public PaymentMethod PreferredPayment { get; set; }
public string PaymentReference { get; set; }
public string PaymentReference { get; set; } = string.Empty;
public decimal TotalAmount { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public DateTime? ExpiresAt { get; set; }
public DateTime? PaidAt { get; set; }
public DateTime? IssuedAt { get; set; }
public string IssuedByUserId { get; set; }
public string IssuedByUserId { get; set; } = string.Empty;
public DateTime? CancelledAt { get; set; }
// Navigační vlastnost pro objednávací položky
public ICollection<OrderItem> OrderItems { get; set; } = new List<OrderItem>();
public ICollection<OrderItem> OrderItems { get; set; }
= new List<OrderItem>();
}
}

View File

@@ -0,0 +1,615 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Web_Jarmark.Data;
#nullable disable
namespace Web_Jarmark.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20261030142312_261030_kosik")]
partial class _261030_kosik
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "10.0.13");
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ClaimType")
.HasColumnType("TEXT");
b.Property<string>("ClaimValue")
.HasColumnType("TEXT");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ClaimType")
.HasColumnType("TEXT");
b.Property<string>("ClaimValue")
.HasColumnType("TEXT");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("ProviderKey")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("ProviderDisplayName")
.HasColumnType("TEXT");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserPasskey<string>", b =>
{
b.Property<byte[]>("CredentialId")
.HasMaxLength(1024)
.HasColumnType("BLOB");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("CredentialId");
b.HasIndex("UserId");
b.ToTable("AspNetUserPasskeys", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("TEXT");
b.Property<string>("RoleId")
.HasColumnType("TEXT");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("TEXT");
b.Property<string>("LoginProvider")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("Value")
.HasColumnType("TEXT");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("Web_Jarmark.Data.ApplicationUser", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<int>("AccessFailedCount")
.HasColumnType("INTEGER");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<bool>("EmailConfirmed")
.HasColumnType("INTEGER");
b.Property<bool>("LockoutEnabled")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("TEXT");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("PasswordHash")
.HasColumnType("TEXT");
b.Property<string>("PhoneNumber")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("INTEGER");
b.Property<string>("SecurityStamp")
.HasColumnType("TEXT");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("INTEGER");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Cart", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("Token")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("Token")
.IsUnique();
b.ToTable("Carts");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.CartItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("CartId")
.HasColumnType("INTEGER");
b.Property<int>("ProductId")
.HasColumnType("INTEGER");
b.Property<int>("Quantity")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("CartId", "ProductId")
.IsUnique();
b.ToTable("CartItems");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Category", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<bool>("IsActive")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Categories");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime?>("CancelledAt")
.HasColumnType("TEXT");
b.Property<string>("Code")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("CustomerName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime?>("ExpiresAt")
.HasColumnType("TEXT");
b.Property<DateTime?>("IssuedAt")
.HasColumnType("TEXT");
b.Property<string>("IssuedByUserId")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Note")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime?>("PaidAt")
.HasColumnType("TEXT");
b.Property<string>("PaymentReference")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Phone")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("PreferredPayment")
.HasColumnType("INTEGER");
b.Property<int>("Status")
.HasColumnType("INTEGER");
b.Property<decimal>("TotalAmount")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Order");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.OrderItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("OrderId")
.HasColumnType("INTEGER");
b.Property<int>("ProductId")
.HasColumnType("INTEGER");
b.Property<string>("ProductName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Quantity")
.HasColumnType("INTEGER");
b.Property<decimal>("UnitPrice")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("OrderId");
b.HasIndex("ProductId");
b.ToTable("OrderItem");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Product", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("CategoryId")
.HasColumnType("INTEGER");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("ImageUrl")
.IsRequired()
.HasColumnType("TEXT");
b.Property<bool>("IsVisible")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<decimal>("Price")
.HasColumnType("TEXT");
b.Property<int>("StockQuantity")
.HasColumnType("INTEGER");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("CategoryId");
b.ToTable("Products");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("Web_Jarmark.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("Web_Jarmark.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserPasskey<string>", b =>
{
b.HasOne("Web_Jarmark.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.OwnsOne("Microsoft.AspNetCore.Identity.IdentityPasskeyData", "Data", b1 =>
{
b1.Property<byte[]>("IdentityUserPasskeyCredentialId");
b1.Property<byte[]>("AttestationObject")
.IsRequired();
b1.Property<byte[]>("ClientDataJson")
.IsRequired();
b1.Property<DateTimeOffset>("CreatedAt");
b1.Property<bool>("IsBackedUp");
b1.Property<bool>("IsBackupEligible");
b1.Property<bool>("IsUserVerified");
b1.Property<string>("Name");
b1.Property<byte[]>("PublicKey")
.IsRequired();
b1.Property<uint>("SignCount");
b1.PrimitiveCollection<string>("Transports");
b1.HasKey("IdentityUserPasskeyCredentialId");
b1.ToTable("AspNetUserPasskeys");
b1
.ToJson("Data")
.HasColumnType("TEXT");
b1.WithOwner()
.HasForeignKey("IdentityUserPasskeyCredentialId");
});
b.Navigation("Data")
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Web_Jarmark.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("Web_Jarmark.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Web_Jarmark.Data.Models.CartItem", b =>
{
b.HasOne("Web_Jarmark.Data.Models.Cart", "Cart")
.WithMany("CartItems")
.HasForeignKey("CartId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Web_Jarmark.Data.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Cart");
b.Navigation("Product");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.OrderItem", b =>
{
b.HasOne("Web_Jarmark.Data.Models.Order", "Order")
.WithMany("OrderItems")
.HasForeignKey("OrderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Web_Jarmark.Data.Models.Product", "Product")
.WithMany("OrderItems")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Order");
b.Navigation("Product");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Product", b =>
{
b.HasOne("Web_Jarmark.Data.Models.Category", "Category")
.WithMany("Products")
.HasForeignKey("CategoryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Category");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Cart", b =>
{
b.Navigation("CartItems");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Category", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Order", b =>
{
b.Navigation("OrderItems");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Product", b =>
{
b.Navigation("OrderItems");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,84 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Web_Jarmark.Migrations
{
/// <inheritdoc />
public partial class _261030_kosik : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Carts",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Token = table.Column<string>(type: "TEXT", nullable: false),
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Carts", x => x.Id);
});
migrationBuilder.CreateTable(
name: "CartItems",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
CartId = table.Column<int>(type: "INTEGER", nullable: false),
ProductId = table.Column<int>(type: "INTEGER", nullable: false),
Quantity = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_CartItems", x => x.Id);
table.ForeignKey(
name: "FK_CartItems_Carts_CartId",
column: x => x.CartId,
principalTable: "Carts",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_CartItems_Products_ProductId",
column: x => x.ProductId,
principalTable: "Products",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_CartItems_CartId_ProductId",
table: "CartItems",
columns: new[] { "CartId", "ProductId" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_CartItems_ProductId",
table: "CartItems",
column: "ProductId");
migrationBuilder.CreateIndex(
name: "IX_Carts_Token",
table: "Carts",
column: "Token",
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "CartItems");
migrationBuilder.DropTable(
name: "Carts");
}
}
}

View File

@@ -0,0 +1,624 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Web_Jarmark.Data;
#nullable disable
namespace Web_Jarmark.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20261104173931_AddCreatedAtToUsers")]
partial class AddCreatedAtToUsers
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "10.0.13");
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ClaimType")
.HasColumnType("TEXT");
b.Property<string>("ClaimValue")
.HasColumnType("TEXT");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ClaimType")
.HasColumnType("TEXT");
b.Property<string>("ClaimValue")
.HasColumnType("TEXT");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("ProviderKey")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("ProviderDisplayName")
.HasColumnType("TEXT");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserPasskey<string>", b =>
{
b.Property<byte[]>("CredentialId")
.HasMaxLength(1024)
.HasColumnType("BLOB");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("CredentialId");
b.HasIndex("UserId");
b.ToTable("AspNetUserPasskeys", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("TEXT");
b.Property<string>("RoleId")
.HasColumnType("TEXT");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("TEXT");
b.Property<string>("LoginProvider")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("Value")
.HasColumnType("TEXT");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("Web_Jarmark.Data.ApplicationUser", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<int>("AccessFailedCount")
.HasColumnType("INTEGER");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<bool>("EmailConfirmed")
.HasColumnType("INTEGER");
b.Property<string>("FirstName")
.HasColumnType("TEXT");
b.Property<string>("LastName")
.HasColumnType("TEXT");
b.Property<bool>("LockoutEnabled")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("TEXT");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("PasswordHash")
.HasColumnType("TEXT");
b.Property<string>("PhoneNumber")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("INTEGER");
b.Property<string>("SecurityStamp")
.HasColumnType("TEXT");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("INTEGER");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Cart", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("Token")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("Token")
.IsUnique();
b.ToTable("Carts");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.CartItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("CartId")
.HasColumnType("INTEGER");
b.Property<int>("ProductId")
.HasColumnType("INTEGER");
b.Property<int>("Quantity")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("CartId", "ProductId")
.IsUnique();
b.ToTable("CartItems");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Category", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<bool>("IsActive")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Categories");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime?>("CancelledAt")
.HasColumnType("TEXT");
b.Property<string>("Code")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("CustomerName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime?>("ExpiresAt")
.HasColumnType("TEXT");
b.Property<DateTime?>("IssuedAt")
.HasColumnType("TEXT");
b.Property<string>("IssuedByUserId")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Note")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime?>("PaidAt")
.HasColumnType("TEXT");
b.Property<string>("PaymentReference")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Phone")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("PreferredPayment")
.HasColumnType("INTEGER");
b.Property<int>("Status")
.HasColumnType("INTEGER");
b.Property<decimal>("TotalAmount")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Order");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.OrderItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("OrderId")
.HasColumnType("INTEGER");
b.Property<int>("ProductId")
.HasColumnType("INTEGER");
b.Property<string>("ProductName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Quantity")
.HasColumnType("INTEGER");
b.Property<decimal>("UnitPrice")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("OrderId");
b.HasIndex("ProductId");
b.ToTable("OrderItem");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Product", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("CategoryId")
.HasColumnType("INTEGER");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("ImageUrl")
.IsRequired()
.HasColumnType("TEXT");
b.Property<bool>("IsVisible")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<decimal>("Price")
.HasColumnType("TEXT");
b.Property<int>("StockQuantity")
.HasColumnType("INTEGER");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("CategoryId");
b.ToTable("Products");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("Web_Jarmark.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("Web_Jarmark.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserPasskey<string>", b =>
{
b.HasOne("Web_Jarmark.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.OwnsOne("Microsoft.AspNetCore.Identity.IdentityPasskeyData", "Data", b1 =>
{
b1.Property<byte[]>("IdentityUserPasskeyCredentialId");
b1.Property<byte[]>("AttestationObject")
.IsRequired();
b1.Property<byte[]>("ClientDataJson")
.IsRequired();
b1.Property<DateTimeOffset>("CreatedAt");
b1.Property<bool>("IsBackedUp");
b1.Property<bool>("IsBackupEligible");
b1.Property<bool>("IsUserVerified");
b1.Property<string>("Name");
b1.Property<byte[]>("PublicKey")
.IsRequired();
b1.Property<uint>("SignCount");
b1.PrimitiveCollection<string>("Transports");
b1.HasKey("IdentityUserPasskeyCredentialId");
b1.ToTable("AspNetUserPasskeys");
b1
.ToJson("Data")
.HasColumnType("TEXT");
b1.WithOwner()
.HasForeignKey("IdentityUserPasskeyCredentialId");
});
b.Navigation("Data")
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Web_Jarmark.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("Web_Jarmark.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Web_Jarmark.Data.Models.CartItem", b =>
{
b.HasOne("Web_Jarmark.Data.Models.Cart", "Cart")
.WithMany("CartItems")
.HasForeignKey("CartId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Web_Jarmark.Data.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Cart");
b.Navigation("Product");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.OrderItem", b =>
{
b.HasOne("Web_Jarmark.Data.Models.Order", "Order")
.WithMany("OrderItems")
.HasForeignKey("OrderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Web_Jarmark.Data.Models.Product", "Product")
.WithMany("OrderItems")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Order");
b.Navigation("Product");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Product", b =>
{
b.HasOne("Web_Jarmark.Data.Models.Category", "Category")
.WithMany("Products")
.HasForeignKey("CategoryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Category");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Cart", b =>
{
b.Navigation("CartItems");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Category", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Order", b =>
{
b.Navigation("OrderItems");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Product", b =>
{
b.Navigation("OrderItems");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,49 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Web_Jarmark.Migrations
{
/// <inheritdoc />
public partial class AddCreatedAtToUsers : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<DateTime>(
name: "CreatedAt",
table: "AspNetUsers",
type: "TEXT",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "FirstName",
table: "AspNetUsers",
type: "TEXT",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "LastName",
table: "AspNetUsers",
type: "TEXT",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "CreatedAt",
table: "AspNetUsers");
migrationBuilder.DropColumn(
name: "FirstName",
table: "AspNetUsers");
migrationBuilder.DropColumn(
name: "LastName",
table: "AspNetUsers");
}
}
}

View File

@@ -0,0 +1,628 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Web_Jarmark.Data;
#nullable disable
namespace Web_Jarmark.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20261106180726_AddOrderAccessTokenHash")]
partial class AddOrderAccessTokenHash
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "10.0.13");
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ClaimType")
.HasColumnType("TEXT");
b.Property<string>("ClaimValue")
.HasColumnType("TEXT");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ClaimType")
.HasColumnType("TEXT");
b.Property<string>("ClaimValue")
.HasColumnType("TEXT");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("ProviderKey")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("ProviderDisplayName")
.HasColumnType("TEXT");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserPasskey<string>", b =>
{
b.Property<byte[]>("CredentialId")
.HasMaxLength(1024)
.HasColumnType("BLOB");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("CredentialId");
b.HasIndex("UserId");
b.ToTable("AspNetUserPasskeys", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("TEXT");
b.Property<string>("RoleId")
.HasColumnType("TEXT");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("TEXT");
b.Property<string>("LoginProvider")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasMaxLength(128)
.HasColumnType("TEXT");
b.Property<string>("Value")
.HasColumnType("TEXT");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("Web_Jarmark.Data.ApplicationUser", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<int>("AccessFailedCount")
.HasColumnType("INTEGER");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<bool>("EmailConfirmed")
.HasColumnType("INTEGER");
b.Property<string>("FirstName")
.HasColumnType("TEXT");
b.Property<string>("LastName")
.HasColumnType("TEXT");
b.Property<bool>("LockoutEnabled")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("TEXT");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("PasswordHash")
.HasColumnType("TEXT");
b.Property<string>("PhoneNumber")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("INTEGER");
b.Property<string>("SecurityStamp")
.HasColumnType("TEXT");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("INTEGER");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Cart", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("Token")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("Token")
.IsUnique();
b.ToTable("Carts");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.CartItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("CartId")
.HasColumnType("INTEGER");
b.Property<int>("ProductId")
.HasColumnType("INTEGER");
b.Property<int>("Quantity")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("CartId", "ProductId")
.IsUnique();
b.ToTable("CartItems");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Category", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<bool>("IsActive")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Slug")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Categories");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("AccessTokenHash")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime?>("CancelledAt")
.HasColumnType("TEXT");
b.Property<string>("Code")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("CustomerName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime?>("ExpiresAt")
.HasColumnType("TEXT");
b.Property<DateTime?>("IssuedAt")
.HasColumnType("TEXT");
b.Property<string>("IssuedByUserId")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Note")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime?>("PaidAt")
.HasColumnType("TEXT");
b.Property<string>("PaymentReference")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Phone")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("PreferredPayment")
.HasColumnType("INTEGER");
b.Property<int>("Status")
.HasColumnType("INTEGER");
b.Property<decimal>("TotalAmount")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Order", (string)null);
});
modelBuilder.Entity("Web_Jarmark.Data.Models.OrderItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("OrderId")
.HasColumnType("INTEGER");
b.Property<int>("ProductId")
.HasColumnType("INTEGER");
b.Property<string>("ProductName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Quantity")
.HasColumnType("INTEGER");
b.Property<decimal>("UnitPrice")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("OrderId");
b.HasIndex("ProductId");
b.ToTable("OrderItem", (string)null);
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Product", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("CategoryId")
.HasColumnType("INTEGER");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("ImageUrl")
.IsRequired()
.HasColumnType("TEXT");
b.Property<bool>("IsVisible")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<decimal>("Price")
.HasColumnType("TEXT");
b.Property<int>("StockQuantity")
.HasColumnType("INTEGER");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("CategoryId");
b.ToTable("Products");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("Web_Jarmark.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("Web_Jarmark.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserPasskey<string>", b =>
{
b.HasOne("Web_Jarmark.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.OwnsOne("Microsoft.AspNetCore.Identity.IdentityPasskeyData", "Data", b1 =>
{
b1.Property<byte[]>("IdentityUserPasskeyCredentialId");
b1.Property<byte[]>("AttestationObject")
.IsRequired();
b1.Property<byte[]>("ClientDataJson")
.IsRequired();
b1.Property<DateTimeOffset>("CreatedAt");
b1.Property<bool>("IsBackedUp");
b1.Property<bool>("IsBackupEligible");
b1.Property<bool>("IsUserVerified");
b1.Property<string>("Name");
b1.Property<byte[]>("PublicKey")
.IsRequired();
b1.Property<uint>("SignCount");
b1.PrimitiveCollection<string>("Transports");
b1.HasKey("IdentityUserPasskeyCredentialId");
b1.ToTable("AspNetUserPasskeys");
b1
.ToJson("Data")
.HasColumnType("TEXT");
b1.WithOwner()
.HasForeignKey("IdentityUserPasskeyCredentialId");
});
b.Navigation("Data")
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Web_Jarmark.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("Web_Jarmark.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Web_Jarmark.Data.Models.CartItem", b =>
{
b.HasOne("Web_Jarmark.Data.Models.Cart", "Cart")
.WithMany("CartItems")
.HasForeignKey("CartId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Web_Jarmark.Data.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Cart");
b.Navigation("Product");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.OrderItem", b =>
{
b.HasOne("Web_Jarmark.Data.Models.Order", "Order")
.WithMany("OrderItems")
.HasForeignKey("OrderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Web_Jarmark.Data.Models.Product", "Product")
.WithMany("OrderItems")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Order");
b.Navigation("Product");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Product", b =>
{
b.HasOne("Web_Jarmark.Data.Models.Category", "Category")
.WithMany("Products")
.HasForeignKey("CategoryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Category");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Cart", b =>
{
b.Navigation("CartItems");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Category", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Order", b =>
{
b.Navigation("OrderItems");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Product", b =>
{
b.Navigation("OrderItems");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Web_Jarmark.Migrations
{
/// <inheritdoc />
public partial class AddOrderAccessTokenHash : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "AccessTokenHash",
table: "Order",
type: "TEXT",
nullable: false,
defaultValue: "");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "AccessTokenHash",
table: "Order");
}
}
}

View File

@@ -178,6 +178,9 @@ namespace Web_Jarmark.Migrations
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("TEXT");
@@ -185,6 +188,12 @@ namespace Web_Jarmark.Migrations
b.Property<bool>("EmailConfirmed")
.HasColumnType("INTEGER");
b.Property<string>("FirstName")
.HasColumnType("TEXT");
b.Property<string>("LastName")
.HasColumnType("TEXT");
b.Property<bool>("LockoutEnabled")
.HasColumnType("INTEGER");
@@ -231,6 +240,55 @@ namespace Web_Jarmark.Migrations
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Cart", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("Token")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("Token")
.IsUnique();
b.ToTable("Carts");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.CartItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("CartId")
.HasColumnType("INTEGER");
b.Property<int>("ProductId")
.HasColumnType("INTEGER");
b.Property<int>("Quantity")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("CartId", "ProductId")
.IsUnique();
b.ToTable("CartItems");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Category", b =>
{
b.Property<int>("Id")
@@ -259,6 +317,10 @@ namespace Web_Jarmark.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("AccessTokenHash")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime?>("CancelledAt")
.HasColumnType("TEXT");
@@ -313,7 +375,7 @@ namespace Web_Jarmark.Migrations
b.HasKey("Id");
b.ToTable("Order");
b.ToTable("Order", (string)null);
});
modelBuilder.Entity("Web_Jarmark.Data.Models.OrderItem", b =>
@@ -344,7 +406,7 @@ namespace Web_Jarmark.Migrations
b.HasIndex("ProductId");
b.ToTable("OrderItem");
b.ToTable("OrderItem", (string)null);
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Product", b =>
@@ -489,6 +551,25 @@ namespace Web_Jarmark.Migrations
.IsRequired();
});
modelBuilder.Entity("Web_Jarmark.Data.Models.CartItem", b =>
{
b.HasOne("Web_Jarmark.Data.Models.Cart", "Cart")
.WithMany("CartItems")
.HasForeignKey("CartId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Web_Jarmark.Data.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Cart");
b.Navigation("Product");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.OrderItem", b =>
{
b.HasOne("Web_Jarmark.Data.Models.Order", "Order")
@@ -519,6 +600,11 @@ namespace Web_Jarmark.Migrations
b.Navigation("Category");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Cart", b =>
{
b.Navigation("CartItems");
});
modelBuilder.Entity("Web_Jarmark.Data.Models.Category", b =>
{
b.Navigation("Products");

View File

@@ -1,3 +1,4 @@
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
@@ -7,40 +8,64 @@ using Web_Jarmark.Data;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
builder.Services.AddAuthorization();
builder.Services.AddCascadingAuthenticationState();
builder.Services.AddScoped<IdentityRedirectManager>();
builder.Services.AddScoped<AuthenticationStateProvider, IdentityRevalidatingAuthenticationStateProvider>();
builder.Services.AddAuthentication(options =>
{
{
options.DefaultScheme = IdentityConstants.ApplicationScheme;
options.DefaultSignInScheme = IdentityConstants.ExternalScheme;
})
.AddIdentityCookies();
})
.AddIdentityCookies();
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection")
?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(connectionString));
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
builder.Services.AddIdentityCore<ApplicationUser>(options =>
{
{
options.SignIn.RequireConfirmedAccount = true;
options.Stores.SchemaVersion = IdentitySchemaVersions.Version3;
})
})
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddSignInManager()
.AddDefaultTokenProviders();
builder.Services.AddSingleton<IEmailSender<ApplicationUser>, IdentityNoOpEmailSender>();
builder.Services.AddHttpContextAccessor();
var app = builder.Build();
// Configure the HTTP request pipeline.
// Vytvoření role Admin, pokud ještě neexistuje
using (var scope = app.Services.CreateScope())
{
var roleManager = scope.ServiceProvider
.GetRequiredService<RoleManager<IdentityRole>>();
if (!await roleManager.RoleExistsAsync("Admin"))
{
var result = await roleManager.CreateAsync(new IdentityRole("Admin"));
if (!result.Succeeded)
{
throw new InvalidOperationException(
"Nepodařilo se vytvořit roli Admin: "
+ string.Join(", ", result.Errors.Select(e => e.Description)));
}
}
}
if (app.Environment.IsDevelopment())
{
app.UseMigrationsEndPoint();
@@ -48,19 +73,46 @@ if (app.Environment.IsDevelopment())
else
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true);
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.Use(async (context, next) =>
{
const string cookieName = "CartToken";
if (!context.Request.Cookies.TryGetValue(cookieName, out var token)
|| !Guid.TryParse(token, out _))
{
token = Guid.NewGuid().ToString();
context.Response.Cookies.Append(cookieName, token, new CookieOptions
{
HttpOnly = true,
Secure = true,
SameSite = SameSiteMode.Lax,
Expires = DateTimeOffset.UtcNow.AddDays(30),
IsEssential = true
});
}
context.Items["CartToken"] = token;
await next();
});
app.UseAntiforgery();
app.MapStaticAssets();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
// Add additional endpoints required by the Identity /Account Razor components.
app.MapAdditionalIdentityEndpoints();
app.Run();

Binary file not shown.

File diff suppressed because it is too large Load Diff