littleshop/LittleShop/Data/LittleShopContext.cs
sysadmin a281bb2896 Implement complete e-commerce functionality with shipping and order management
Features Added:
- Standard e-commerce properties (Price, Weight, shipping fields)
- Order management with Create/Edit views and shipping information
- ShippingRates system for weight-based shipping calculations
- Comprehensive test coverage with JWT authentication tests
- Sample data seeder with 5 orders demonstrating full workflow
- Photo upload functionality for products
- Multi-cryptocurrency payment support (BTC, XMR, USDT, etc.)

Database Changes:
- Added ShippingRates table
- Added shipping fields to Orders (Name, Address, City, PostCode, Country)
- Renamed properties to standard names (BasePrice to Price, ProductWeight to Weight)
- Added UpdatedAt timestamps to models

UI Improvements:
- Added Create/Edit views for Orders
- Added ShippingRates management UI
- Updated navigation menu with Shipping option
- Enhanced Order Details view with shipping information

Sample Data:
- 3 Categories (Electronics, Clothing, Books)
- 5 Products with various prices
- 5 Shipping rates (Royal Mail options)
- 5 Orders in different statuses (Pending to Delivered)
- 3 Crypto payments demonstrating payment flow

Security:
- All API endpoints secured with JWT authentication
- No public endpoints - client apps must authenticate
- Privacy-focused design with minimal data collection

Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-20 17:37:24 +01:00

83 lines
2.5 KiB
C#

using Microsoft.EntityFrameworkCore;
using LittleShop.Models;
namespace LittleShop.Data;
public class LittleShopContext : DbContext
{
public LittleShopContext(DbContextOptions<LittleShopContext> options) : base(options)
{
}
public DbSet<User> Users { get; set; }
public DbSet<Category> Categories { get; set; }
public DbSet<Product> Products { get; set; }
public DbSet<ProductPhoto> ProductPhotos { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<OrderItem> OrderItems { get; set; }
public DbSet<CryptoPayment> CryptoPayments { get; set; }
public DbSet<ShippingRate> ShippingRates { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// User entity
modelBuilder.Entity<User>(entity =>
{
entity.HasIndex(e => e.Username).IsUnique();
});
// Category entity
modelBuilder.Entity<Category>(entity =>
{
entity.HasMany(c => c.Products)
.WithOne(p => p.Category)
.HasForeignKey(p => p.CategoryId)
.OnDelete(DeleteBehavior.Restrict);
});
// Product entity
modelBuilder.Entity<Product>(entity =>
{
entity.HasMany(p => p.Photos)
.WithOne(pp => pp.Product)
.HasForeignKey(pp => pp.ProductId)
.OnDelete(DeleteBehavior.Cascade);
entity.HasMany(p => p.OrderItems)
.WithOne(oi => oi.Product)
.HasForeignKey(oi => oi.ProductId)
.OnDelete(DeleteBehavior.Restrict);
});
// Order entity
modelBuilder.Entity<Order>(entity =>
{
entity.HasMany(o => o.Items)
.WithOne(oi => oi.Order)
.HasForeignKey(oi => oi.OrderId)
.OnDelete(DeleteBehavior.Cascade);
entity.HasMany(o => o.Payments)
.WithOne(cp => cp.Order)
.HasForeignKey(cp => cp.OrderId)
.OnDelete(DeleteBehavior.Cascade);
entity.HasIndex(e => e.IdentityReference);
});
// OrderItem entity
modelBuilder.Entity<OrderItem>(entity =>
{
entity.HasKey(oi => oi.Id);
});
// CryptoPayment entity
modelBuilder.Entity<CryptoPayment>(entity =>
{
entity.HasIndex(e => e.BTCPayInvoiceId);
entity.HasIndex(e => e.WalletAddress);
});
}
}