DB a Backend Vytvoreni entiti a registrace v dbcontextu
This commit is contained in:
@@ -25,8 +25,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="nav-item px-3">
|
<div class="nav-item px-3">
|
||||||
<NavLink class="nav-link" href="DetailVyrobku">
|
<NavLink class="nav-link" href="FF">
|
||||||
<span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> Detail vyrobku
|
<span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> FF
|
||||||
</NavLink>
|
</NavLink>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Web_Jarmark.Data;
|
||||||
|
using Web_Jarmark.Data.Models;
|
||||||
|
|
||||||
namespace Web_Jarmark.Data
|
namespace Web_Jarmark.Data
|
||||||
{
|
{
|
||||||
@@ -7,3 +9,19 @@ namespace Web_Jarmark.Data
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : IdentityDbContext<ApplicationUser>(options)
|
||||||
|
{
|
||||||
|
public DbSet<Category> Categories { get; set; }
|
||||||
|
public DbSet<Product> Products { get; set; }
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
base.OnModelCreating(modelBuilder);
|
||||||
|
|
||||||
|
// Nastavení vazby 1:N mezi Category a Product
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
15
Web-Jarmark/Web-Jarmark/Data/Models/Category.cs
Normal file
15
Web-Jarmark/Web-Jarmark/Data/Models/Category.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
using Microsoft.CodeAnalysis;
|
||||||
|
|
||||||
|
namespace Web_Jarmark.Data.Models
|
||||||
|
{
|
||||||
|
public class Category
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string Slug { get; set; }
|
||||||
|
public bool IsActive { get; set; }
|
||||||
|
|
||||||
|
// Navigační vlastnost pro produkty
|
||||||
|
public ICollection<Product> Products { get; set; } = new List<Product>();
|
||||||
|
}
|
||||||
|
}
|
||||||
41
Web-Jarmark/Web-Jarmark/Data/Models/Order.cs
Normal file
41
Web-Jarmark/Web-Jarmark/Data/Models/Order.cs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
namespace Web_Jarmark.Data.Models
|
||||||
|
{
|
||||||
|
public enum OrderStatus
|
||||||
|
{
|
||||||
|
Pending,
|
||||||
|
Paid,
|
||||||
|
Shipped,
|
||||||
|
Delivered,
|
||||||
|
Cancelled
|
||||||
|
}
|
||||||
|
public enum PaymentMethod
|
||||||
|
{
|
||||||
|
CreditCard,
|
||||||
|
PayPal,
|
||||||
|
BankTransfer,
|
||||||
|
Cash
|
||||||
|
}
|
||||||
|
|
||||||
|
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 PaymentMethod PreferredPayment { get; set; }
|
||||||
|
public string PaymentReference { get; set; }
|
||||||
|
public decimal TotalAmount { get; set; }
|
||||||
|
public DateTime CreatedAt { get; set; }
|
||||||
|
public DateTime? ExpiresAt { get; set; }
|
||||||
|
public DateTime? PaidAt { get; set; }
|
||||||
|
public DateTime? IssuedAt { get; set; }
|
||||||
|
public string IssuedByUserId { get; set; }
|
||||||
|
public DateTime? CancelledAt { get; set; }
|
||||||
|
|
||||||
|
// Navigační vlastnost pro objednávací položky
|
||||||
|
public ICollection<OrderItem> OrderItems { get; set; } = new List<OrderItem>();
|
||||||
|
}
|
||||||
|
}
|
||||||
16
Web-Jarmark/Web-Jarmark/Data/Models/OrderItem.cs
Normal file
16
Web-Jarmark/Web-Jarmark/Data/Models/OrderItem.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
namespace Web_Jarmark.Data.Models
|
||||||
|
{
|
||||||
|
public class OrderItem
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public int OrderId { get; set; }
|
||||||
|
public int ProductId { get; set; }
|
||||||
|
public string ProductName { get; set; }
|
||||||
|
public decimal UnitPrice { get; set; }
|
||||||
|
public int Quantity { get; set; }
|
||||||
|
|
||||||
|
// Navigační vlastnosti pro objednávku a produkt
|
||||||
|
public Order Order { get; set; }
|
||||||
|
public Product Product { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
19
Web-Jarmark/Web-Jarmark/Data/Models/Product.cs
Normal file
19
Web-Jarmark/Web-Jarmark/Data/Models/Product.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
namespace Web_Jarmark.Data.Models
|
||||||
|
{
|
||||||
|
public class Product
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public int CategoryId { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string Description { get; set; }
|
||||||
|
public decimal Price { get; set; }
|
||||||
|
public int StockQuantity { get; set; }
|
||||||
|
public string ImageUrl { get; set; }
|
||||||
|
public bool IsVisible { get; set; }
|
||||||
|
public DateTime UpdatedAt { get; set; }
|
||||||
|
|
||||||
|
// Navigační vlastnosti pro kategorii a objednávky
|
||||||
|
public Category Category { get; set; }
|
||||||
|
public ICollection<OrderItem> OrderItems { get; set; } = new List<OrderItem>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
|||||||
Reference in New Issue
Block a user