diff --git a/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/CategoriEdit.razor b/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/CategoriEdit.razor
index d126f53..b995ff1 100644
--- a/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/CategoriEdit.razor
+++ b/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/CategoriEdit.razor
@@ -1,5 +1,140 @@
-
CategoriEdit
+@page "/admin/kategorie/edit"
+@page "/admin/kategorie/edit/{Id:int}"
+@rendermode InteractiveServer
+@using System.ComponentModel.DataAnnotations
+@using System.Globalization
+@using System.Text
+@using System.Text.RegularExpressions
+@using Microsoft.EntityFrameworkCore
+@using Web_Jarmark.Data
+@using Web_Jarmark.Data.Models
+@inject ApplicationDbContext Db
+@inject NavigationManager Nav
+
+@(Id is null ? "Nová kategorie" : "Upravit kategorii")
+
+@(Id is null ? "Nová kategorie" : "Upravit kategorii")
+
+@if (notFound)
+{
+ Kategorie nebyla nalezena.
+ Zpět na seznam
+}
+else
+{
+
+
+
+
+ @if (!string.IsNullOrEmpty(error))
+ {
+ @error
+ }
+
+
+
+
+
+
+
+
+
+
Když necháš prázdné, vytvoří se automaticky z názvu.
+
+
+
+
+
+
+
+
+ Zrušit
+
+}
@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().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()
+ {
+ 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().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().Add(new Category { Name = name, Slug = slug, IsActive = form.IsActive });
+ }
+ else
+ {
+ var cat = await Db.Set().FindAsync(Id);
+ if (cat is null)
+ {
+ notFound = true;
+ return;
+ }
+ cat.Name = name;
+ cat.Slug = slug;
+ cat.IsActive = form.IsActive;
+ }
+
+ await Db.SaveChangesAsync();
+ Nav.NavigateTo("/admin/kategorie");
+ }
+
+ private static string Slugify(string text)
+ {
+ 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);
+ }
+ var noDiacritics = sb.ToString().Normalize(NormalizationForm.FormC);
+ return Regex.Replace(noDiacritics, "[^a-z0-9]+", "-").Trim('-');
+ }
+
+ private class CategoryForm
+ {
+ [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;
+ }
+}
\ No newline at end of file
diff --git a/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/CategoriList.razor b/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/CategoriList.razor
index df91277..023e11e 100644
--- a/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/CategoriList.razor
+++ b/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/CategoriList.razor
@@ -1,5 +1,112 @@
-CategoriList
+@page "/admin/kategorie"
+@rendermode InteractiveServer
+@using Microsoft.EntityFrameworkCore
+@using Web_Jarmark.Data
+@using Web_Jarmark.Data.Models
+@inject ApplicationDbContext Db
+@inject NavigationManager Nav
+
+Kategorie
+
+
+
Kategorie
+
+ Nová kategorie
+
+
+@if (!string.IsNullOrEmpty(error))
+{
+ @error
+}
+
+@if (categories is null)
+{
+ Načítám…
+}
+else if (categories.Count == 0)
+{
+ Zatím tu nejsou žádné kategorie.
+}
+else
+{
+
+}
@code {
+ private List? categories;
+ private string? error;
-}
+ protected override async Task OnInitializedAsync() => await Load();
+
+ private async Task Load()
+ {
+ categories = await Db.Set()
+ .AsNoTracking()
+ .OrderBy(c => c.Name)
+ .Select(c => new CategoryRow(c.Id, c.Name, c.Slug, c.IsActive, c.Products.Count))
+ .ToListAsync();
+ }
+
+ private async Task ToggleActive(int id)
+ {
+ var cat = await Db.Set().FindAsync(id);
+ if (cat is null) return;
+ cat.IsActive = !cat.IsActive;
+ await Db.SaveChangesAsync();
+ await Load();
+ }
+
+ private async Task Delete(int id)
+ {
+ error = null;
+ var cat = await Db.Set()
+ .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().Remove(cat);
+ await Db.SaveChangesAsync();
+ await Load();
+ }
+
+ private record CategoryRow(int Id, string Name, string Slug, bool IsActive, int ProductCount);
+}
\ No newline at end of file
diff --git a/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/ProductEdit.razor b/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/ProductEdit.razor
index af33527..78be197 100644
--- a/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/ProductEdit.razor
+++ b/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/ProductEdit.razor
@@ -1,5 +1,186 @@
-ProductEdit
+@page "/admin/zbozi/edit"
+@page "/admin/zbozi/edit/{Id:int}"
+@rendermode InteractiveServer
+@using System.ComponentModel.DataAnnotations
+@using Microsoft.EntityFrameworkCore
+@using Web_Jarmark.Data
+@using Web_Jarmark.Data.Models
+@inject ApplicationDbContext Db
+@inject NavigationManager Nav
+
+@(Id is null ? "Nové zboží" : "Upravit zboží")
+
+@(Id is null ? "Nové zboží" : "Upravit zboží")
+
+@if (notFound)
+{
+ Zboží nebylo nalezeno.
+ Zpět na seznam
+}
+else if (categories is null)
+{
+ Načítám…
+}
+else if (categories.Count == 0)
+{
+
+}
+else
+{
+
+
+
+
+ @if (!string.IsNullOrEmpty(error))
+ {
+ @error
+ }
+
+
+
+
+
+
+
+
+
+
+ @foreach (var c in categories)
+ {
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Např. /images/cukrovi.jpg (soubor v wwwroot) nebo celá adresa.
+
+
+
+
+
+
+
+
+ Zrušit
+
+}
@code {
+ [Parameter] public int? Id { get; set; }
-}
+ private ProductForm form = new();
+ private List? categories;
+ private string? error;
+ private bool notFound;
+
+ protected override async Task OnParametersSetAsync()
+ {
+ categories = await Db.Set().AsNoTracking().OrderBy(c => c.Name).ToListAsync();
+
+ if (Id is null) return;
+
+ var p = await Db.Set().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().Add(p);
+ }
+ else
+ {
+ var p = await Db.Set().FindAsync(Id);
+ if (p is null)
+ {
+ notFound = true;
+ return;
+ }
+ Apply(p);
+ }
+
+ await Db.SaveChangesAsync();
+ Nav.NavigateTo("/admin/zbozi");
+ }
+
+ private void Apply(Product p)
+ {
+ 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;
+ }
+
+ private class ProductForm
+ {
+ [Required(ErrorMessage = "Zadej název zboží.")]
+ [StringLength(100, ErrorMessage = "Název může mít nejvýše 100 znaků.")]
+ public string Name { get; set; } = "";
+
+ public int CategoryId { get; set; }
+
+ public string? Description { get; set; }
+
+ [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;
+ }
+}
\ No newline at end of file
diff --git a/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/ProductList.razor b/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/ProductList.razor
index da784f0..3c0ad75 100644
--- a/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/ProductList.razor
+++ b/Web-Jarmark/Web-Jarmark/Components/Pages/Admin/ProductList.razor
@@ -1,5 +1,109 @@
-ProductList
+@page "/admin/zbozi"
+@rendermode InteractiveServer
+@using Microsoft.EntityFrameworkCore
+@using Web_Jarmark.Data
+@using Web_Jarmark.Data.Models
+@inject ApplicationDbContext Db
+
+Zboží
+
+
+
+@if (!string.IsNullOrEmpty(error))
+{
+ @error
+}
+
+@if (products is null)
+{
+ Načítám…
+}
+else if (products.Count == 0)
+{
+ Zatím tu není žádné zboží.
+}
+else
+{
+
+}
@code {
+ private List? products;
+ private string? error;
-}
+ protected override async Task OnInitializedAsync() => await Load();
+
+ private async Task Load()
+ {
+ products = await Db.Set()
+ .AsNoTracking()
+ .OrderBy(p => p.Name)
+ .Select(p => new ProductRow(p.Id, p.Name, p.Category.Name, p.Price, p.StockQuantity, p.IsVisible))
+ .ToListAsync();
+ }
+
+ private async Task ToggleVisible(int id)
+ {
+ var p = await Db.Set().FindAsync(id);
+ if (p is null) return;
+ p.IsVisible = !p.IsVisible;
+ p.UpdatedAt = DateTime.Now;
+ await Db.SaveChangesAsync();
+ await Load();
+ }
+
+ private async Task Delete(int id)
+ {
+ error = null;
+ var p = await Db.Set()
+ .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().Remove(p);
+ await Db.SaveChangesAsync();
+ await Load();
+ }
+
+ private record ProductRow(int Id, string Name, string CategoryName, decimal Price, int StockQuantity, bool IsVisible);
+}
\ No newline at end of file
diff --git a/Web-Jarmark/Web-Jarmark/jarmark.db-shm b/Web-Jarmark/Web-Jarmark/jarmark.db-shm
new file mode 100644
index 0000000..6ef8a1d
Binary files /dev/null and b/Web-Jarmark/Web-Jarmark/jarmark.db-shm differ
diff --git a/Web-Jarmark/Web-Jarmark/jarmark.db-wal b/Web-Jarmark/Web-Jarmark/jarmark.db-wal
new file mode 100644
index 0000000..828a071
Binary files /dev/null and b/Web-Jarmark/Web-Jarmark/jarmark.db-wal differ