Redo entities and configs, plus dummy aspnet identity config
This commit is contained in:
10
src/Printbase.Domain/Entities/EntityBase.cs
Normal file
10
src/Printbase.Domain/Entities/EntityBase.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Printbase.Domain.Entities;
|
||||
|
||||
public abstract class EntityBase
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public DateTime ModifiedAt { get; set; }
|
||||
public string CreatedBy { get; set; }
|
||||
public string ModifiedBy { get; set; }
|
||||
}
|
||||
17
src/Printbase.Domain/Entities/Orders/Order.cs
Normal file
17
src/Printbase.Domain/Entities/Orders/Order.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace Printbase.Domain.Entities;
|
||||
|
||||
public class Order : EntityBase
|
||||
{
|
||||
public string UserId { get; set; }
|
||||
public DateTime OrderDate { get; set; }
|
||||
public decimal TotalPrice { get; set; }
|
||||
public int OrderStatusId { get; set; }
|
||||
public int ShippingStatusId { get; set; }
|
||||
public string OrderNumber { get; set; }
|
||||
public string Notes { get; set; }
|
||||
|
||||
public virtual OrderStatus OrderStatus { get; set; }
|
||||
public virtual ShippingStatus ShippingStatus { get; set; }
|
||||
public virtual OrderAddress OrderAddress { get; set; }
|
||||
public virtual ICollection<OrderItem> OrderItems { get; set; } = new List<OrderItem>();
|
||||
}
|
||||
13
src/Printbase.Domain/Entities/Orders/OrderAddress.cs
Normal file
13
src/Printbase.Domain/Entities/Orders/OrderAddress.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace Printbase.Domain.Entities;
|
||||
|
||||
public class OrderAddress : EntityBase
|
||||
{
|
||||
public Guid OrderId { get; set; }
|
||||
public string Street { get; set; }
|
||||
public string City { get; set; }
|
||||
public string State { get; set; }
|
||||
public string PostalCode { get; set; }
|
||||
public string Country { get; set; }
|
||||
|
||||
public virtual Order Order { get; set; }
|
||||
}
|
||||
17
src/Printbase.Domain/Entities/Orders/OrderItem.cs
Normal file
17
src/Printbase.Domain/Entities/Orders/OrderItem.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace Printbase.Domain.Entities;
|
||||
|
||||
public class OrderItem : EntityBase
|
||||
{
|
||||
public Guid OrderId { get; set; }
|
||||
public Guid ProductId { get; set; }
|
||||
public Guid? ProductVariantId { get; set; }
|
||||
public int Quantity { get; set; }
|
||||
public decimal UnitPrice { get; set; }
|
||||
public decimal TotalPrice { get; set; }
|
||||
public string CustomizationImageUrl { get; set; }
|
||||
public string CustomizationDescription { get; set; }
|
||||
|
||||
public virtual Order Order { get; set; }
|
||||
public virtual Product Product { get; set; }
|
||||
public virtual ProductVariant ProductVariant { get; set; }
|
||||
}
|
||||
9
src/Printbase.Domain/Entities/Orders/OrderStatus.cs
Normal file
9
src/Printbase.Domain/Entities/Orders/OrderStatus.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Printbase.Domain.Entities;
|
||||
|
||||
public class OrderStatus
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public virtual ICollection<Order> Orders { get; set; } = new List<Order>();
|
||||
}
|
||||
9
src/Printbase.Domain/Entities/Orders/ShippingStatus.cs
Normal file
9
src/Printbase.Domain/Entities/Orders/ShippingStatus.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Printbase.Domain.Entities;
|
||||
|
||||
public class ShippingStatus
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public virtual ICollection<Order> Orders { get; set; } = new List<Order>();
|
||||
}
|
||||
15
src/Printbase.Domain/Entities/Product/Category.cs
Normal file
15
src/Printbase.Domain/Entities/Product/Category.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace Printbase.Domain.Entities;
|
||||
|
||||
public class Category : EntityBase
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string ImageUrl { get; set; }
|
||||
public int SortOrder { get; set; }
|
||||
public bool IsActive { get; set; }
|
||||
public Guid? ParentCategoryId { get; set; }
|
||||
|
||||
public virtual Category ParentCategory { get; set; }
|
||||
public virtual ICollection<Category> SubCategories { get; set; } = new List<Category>();
|
||||
public virtual ICollection<Product> Products { get; set; } = new List<Product>();
|
||||
}
|
||||
16
src/Printbase.Domain/Entities/Product/Product.cs
Normal file
16
src/Printbase.Domain/Entities/Product/Product.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace Printbase.Domain.Entities;
|
||||
|
||||
public class Product : EntityBase
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public decimal BasePrice { get; set; }
|
||||
public bool IsCustomizable { get; set; }
|
||||
public bool IsActive { get; set; }
|
||||
public string ImageUrl { get; set; }
|
||||
public Guid? CategoryId { get; set; }
|
||||
|
||||
public virtual Category Category { get; set; }
|
||||
public virtual ICollection<ProductVariant> ProductVariants { get; set; } = new List<ProductVariant>();
|
||||
public virtual ICollection<OrderItem> OrderItems { get; set; } = new List<OrderItem>();
|
||||
}
|
||||
16
src/Printbase.Domain/Entities/Product/ProductVariant.cs
Normal file
16
src/Printbase.Domain/Entities/Product/ProductVariant.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace Printbase.Domain.Entities;
|
||||
|
||||
public class ProductVariant : EntityBase
|
||||
{
|
||||
public Guid ProductId { get; set; }
|
||||
public string Size { get; set; }
|
||||
public string Color { get; set; }
|
||||
public decimal Price { get; set; }
|
||||
public string ImageUrl { get; set; }
|
||||
public string SKU { get; set; }
|
||||
public int StockQuantity { get; set; }
|
||||
public bool IsActive { get; set; }
|
||||
|
||||
public virtual Product Product { get; set; }
|
||||
public virtual ICollection<OrderItem> OrderItems { get; set; } = new List<OrderItem>();
|
||||
}
|
||||
14
src/Printbase.Domain/Entities/Users/Address.cs
Normal file
14
src/Printbase.Domain/Entities/Users/Address.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace Printbase.Domain.Entities;
|
||||
|
||||
public class Address : EntityBase
|
||||
{
|
||||
public string UserId { get; set; }
|
||||
public string AddressType { get; set; }
|
||||
public string Street { get; set; }
|
||||
public string City { get; set; }
|
||||
public string State { get; set; }
|
||||
public string PostalCode { get; set; }
|
||||
public string Country { get; set; }
|
||||
public bool IsDefault { get; set; }
|
||||
public bool IsActive { get; set; }
|
||||
}
|
||||
16
src/Printbase.Domain/Entities/Users/ApplicationRole.cs
Normal file
16
src/Printbase.Domain/Entities/Users/ApplicationRole.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
public class ApplicationRole : IdentityRole
|
||||
{
|
||||
public string Description { get; set; }
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public bool IsActive { get; set; }
|
||||
|
||||
public ApplicationRole() : base()
|
||||
{
|
||||
}
|
||||
|
||||
public ApplicationRole(string roleName) : base(roleName)
|
||||
{
|
||||
}
|
||||
}
|
||||
17
src/Printbase.Domain/Entities/Users/ApplicationUser.cs
Normal file
17
src/Printbase.Domain/Entities/Users/ApplicationUser.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
namespace Printbase.Domain.Entities.Users;
|
||||
|
||||
public class ApplicationUser : IdentityUser
|
||||
{
|
||||
public string FirstName { get; set; }
|
||||
public string LastName { get; set; }
|
||||
public DateTime? DateOfBirth { get; set; }
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public DateTime LastLoginAt { get; set; }
|
||||
public bool IsActive { get; set; }
|
||||
public string ProfileImageUrl { get; set; }
|
||||
|
||||
public virtual ICollection<Address> Addresses { get; set; } = new List<Address>();
|
||||
public virtual ICollection<Order> Orders { get; set; } = new List<Order>();
|
||||
}
|
||||
@@ -10,4 +10,8 @@
|
||||
<Folder Include="Exceptions\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="9.0.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Printbase.Domain.Entities;
|
||||
using Printbase.Domain.Entities.Users;
|
||||
|
||||
namespace Printbase.Infrastructure.Configuration;
|
||||
|
||||
public class AddressConfiguration : EntityBaseConfiguration<Address>
|
||||
{
|
||||
public override void Configure(EntityTypeBuilder<Address> builder)
|
||||
{
|
||||
base.Configure(builder);
|
||||
|
||||
builder.Property(a => a.UserId)
|
||||
.IsRequired()
|
||||
.HasMaxLength(450);
|
||||
|
||||
builder.Property(a => a.AddressType)
|
||||
.IsRequired()
|
||||
.HasMaxLength(50);
|
||||
|
||||
builder.Property(a => a.Street)
|
||||
.IsRequired()
|
||||
.HasMaxLength(200);
|
||||
|
||||
builder.Property(a => a.City)
|
||||
.IsRequired()
|
||||
.HasMaxLength(100);
|
||||
|
||||
builder.Property(a => a.State)
|
||||
.HasMaxLength(100);
|
||||
|
||||
builder.Property(a => a.PostalCode)
|
||||
.IsRequired()
|
||||
.HasMaxLength(20);
|
||||
|
||||
builder.Property(a => a.Country)
|
||||
.IsRequired()
|
||||
.HasMaxLength(100);
|
||||
|
||||
builder.Property(a => a.IsDefault)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(false);
|
||||
|
||||
builder.Property(a => a.IsActive)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(true);
|
||||
|
||||
builder.HasOne<ApplicationUser>()
|
||||
.WithMany(u => u.Addresses)
|
||||
.HasForeignKey(a => a.UserId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.HasIndex(a => a.UserId)
|
||||
.HasDatabaseName("IX_Address_UserId");
|
||||
|
||||
builder.HasIndex(a => new { a.UserId, a.AddressType })
|
||||
.HasDatabaseName("IX_Address_User_Type");
|
||||
|
||||
builder.HasIndex(a => new { a.UserId, a.IsDefault })
|
||||
.HasDatabaseName("IX_Address_User_Default");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Printbase.Infrastructure.Configuration;
|
||||
|
||||
public class ApplicationRoleConfiguration : IEntityTypeConfiguration<ApplicationRole>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<ApplicationRole> builder)
|
||||
{
|
||||
builder.Property(r => r.Description)
|
||||
.HasMaxLength(500);
|
||||
|
||||
builder.Property(r => r.CreatedAt)
|
||||
.IsRequired()
|
||||
.HasDefaultValueSql("GETUTCDATE()");
|
||||
|
||||
builder.Property(r => r.IsActive)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(true);
|
||||
|
||||
builder.HasIndex(r => r.IsActive)
|
||||
.HasDatabaseName("IX_ApplicationRole_IsActive");
|
||||
|
||||
var seedDate = new DateTime(2025, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
|
||||
builder.HasData(
|
||||
new ApplicationRole
|
||||
{
|
||||
Id = "1",
|
||||
Name = "Administrator",
|
||||
NormalizedName = "ADMINISTRATOR",
|
||||
Description = "Full system access",
|
||||
CreatedAt = seedDate,
|
||||
IsActive = true
|
||||
},
|
||||
new ApplicationRole
|
||||
{
|
||||
Id = "2",
|
||||
Name = "Customer",
|
||||
NormalizedName = "CUSTOMER",
|
||||
Description = "Standard customer access",
|
||||
CreatedAt = seedDate,
|
||||
IsActive = true
|
||||
},
|
||||
new ApplicationRole
|
||||
{
|
||||
Id = "3",
|
||||
Name = "OrderManager",
|
||||
NormalizedName = "ORDERMANAGER",
|
||||
Description = "Manage orders and fulfillment",
|
||||
CreatedAt = seedDate,
|
||||
IsActive = true
|
||||
},
|
||||
new ApplicationRole
|
||||
{
|
||||
Id = "4",
|
||||
Name = "ProductManager",
|
||||
NormalizedName = "PRODUCTMANAGER",
|
||||
Description = "Manage products and inventory",
|
||||
CreatedAt = seedDate,
|
||||
IsActive = true
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Printbase.Domain.Entities.Users;
|
||||
|
||||
namespace Printbase.Infrastructure.Configuration;
|
||||
|
||||
public class ApplicationUserConfiguration : IEntityTypeConfiguration<ApplicationUser>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<ApplicationUser> builder)
|
||||
{
|
||||
builder.Property(u => u.FirstName)
|
||||
.HasMaxLength(100);
|
||||
|
||||
builder.Property(u => u.LastName)
|
||||
.HasMaxLength(100);
|
||||
|
||||
builder.Property(u => u.ProfileImageUrl)
|
||||
.HasMaxLength(500);
|
||||
|
||||
builder.Property(u => u.CreatedAt)
|
||||
.IsRequired()
|
||||
.HasDefaultValueSql("GETUTCDATE()");
|
||||
|
||||
builder.Property(u => u.LastLoginAt)
|
||||
.HasDefaultValueSql("GETUTCDATE()");
|
||||
|
||||
builder.Property(u => u.IsActive)
|
||||
.HasDefaultValue(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
using Printbase.Domain.Entities;
|
||||
|
||||
namespace Printbase.Infrastructure.Configuration;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
public class CategoryConfiguration : EntityBaseConfiguration<Category>
|
||||
{
|
||||
public override void Configure(EntityTypeBuilder<Category> builder)
|
||||
{
|
||||
base.Configure(builder);
|
||||
|
||||
builder.Property(c => c.Name)
|
||||
.IsRequired()
|
||||
.HasMaxLength(200);
|
||||
|
||||
builder.Property(c => c.Description)
|
||||
.HasMaxLength(2000);
|
||||
|
||||
builder.Property(c => c.ImageUrl)
|
||||
.HasMaxLength(500);
|
||||
|
||||
builder.Property(c => c.SortOrder)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(0);
|
||||
|
||||
builder.Property(c => c.IsActive)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(true);
|
||||
|
||||
builder.Property(c => c.ParentCategoryId)
|
||||
.IsRequired(false);
|
||||
|
||||
builder.HasOne(c => c.ParentCategory)
|
||||
.WithMany(c => c.SubCategories)
|
||||
.HasForeignKey(c => c.ParentCategoryId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
builder.HasIndex(c => c.Name)
|
||||
.HasDatabaseName("IX_Category_Name");
|
||||
|
||||
builder.HasIndex(c => c.IsActive)
|
||||
.HasDatabaseName("IX_Category_IsActive");
|
||||
|
||||
builder.HasIndex(c => c.ParentCategoryId)
|
||||
.HasDatabaseName("IX_Category_ParentCategoryId");
|
||||
|
||||
builder.HasIndex(c => new { c.ParentCategoryId, c.SortOrder })
|
||||
.HasDatabaseName("IX_Category_Parent_SortOrder");
|
||||
|
||||
builder.HasIndex(c => new { c.IsActive, c.SortOrder })
|
||||
.HasDatabaseName("IX_Category_Active_SortOrder");
|
||||
|
||||
builder.HasData(
|
||||
new Category
|
||||
{
|
||||
Id = Guid.Parse("11111111-1111-1111-1111-111111111111"),
|
||||
Name = "Textile",
|
||||
Description = "Textile and fabric-based products",
|
||||
IsActive = true,
|
||||
SortOrder = 1,
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
ModifiedAt = DateTime.UtcNow
|
||||
},
|
||||
new Category
|
||||
{
|
||||
Id = Guid.Parse("22222222-2222-2222-2222-222222222222"),
|
||||
Name = "Hard Surfaces",
|
||||
Description = "Products for hard surface printing",
|
||||
IsActive = true,
|
||||
SortOrder = 2,
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
ModifiedAt = DateTime.UtcNow
|
||||
},
|
||||
new Category
|
||||
{
|
||||
Id = Guid.Parse("33333333-3333-3333-3333-333333333333"),
|
||||
Name = "Paper",
|
||||
Description = "Paper-based printing products",
|
||||
IsActive = true,
|
||||
SortOrder = 3,
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
ModifiedAt = DateTime.UtcNow
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Printbase.Domain.Entities;
|
||||
|
||||
namespace Printbase.Infrastructure.Configuration;
|
||||
|
||||
public class EntityBaseConfiguration<T> : IEntityTypeConfiguration<T> where T : EntityBase
|
||||
{
|
||||
public virtual void Configure(EntityTypeBuilder<T> builder)
|
||||
{
|
||||
builder.HasKey(e => e.Id);
|
||||
|
||||
builder.Property(e => e.Id)
|
||||
.HasDefaultValueSql("NEWID()");
|
||||
|
||||
builder.Property(e => e.CreatedAt)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(e => e.ModifiedAt)
|
||||
.IsRequired()
|
||||
.HasDefaultValueSql("GETUTCDATE()");
|
||||
|
||||
builder.Property(e => e.CreatedBy)
|
||||
.IsRequired()
|
||||
.HasMaxLength(450);
|
||||
|
||||
builder.Property(e => e.ModifiedBy)
|
||||
.IsRequired()
|
||||
.HasMaxLength(450);
|
||||
|
||||
builder.HasIndex(e => e.CreatedAt)
|
||||
.HasDatabaseName($"IX_{typeof(T).Name}_CreatedAt");
|
||||
|
||||
builder.HasIndex(e => e.ModifiedAt)
|
||||
.HasDatabaseName($"IX_{typeof(T).Name}_ModifiedAt");
|
||||
|
||||
builder.HasIndex(e => e.CreatedBy)
|
||||
.HasDatabaseName($"IX_{typeof(T).Name}_CreatedBy");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Printbase.Domain.Entities;
|
||||
|
||||
namespace Printbase.Infrastructure.Configuration;
|
||||
|
||||
public class OrderAddressConfiguration : EntityBaseConfiguration<OrderAddress>
|
||||
{
|
||||
public override void Configure(EntityTypeBuilder<OrderAddress> builder)
|
||||
{
|
||||
base.Configure(builder);
|
||||
|
||||
builder.Property(oa => oa.OrderId)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(oa => oa.Street)
|
||||
.IsRequired()
|
||||
.HasMaxLength(200);
|
||||
|
||||
builder.Property(oa => oa.City)
|
||||
.IsRequired()
|
||||
.HasMaxLength(100);
|
||||
|
||||
builder.Property(oa => oa.State)
|
||||
.HasMaxLength(100);
|
||||
|
||||
builder.Property(oa => oa.PostalCode)
|
||||
.IsRequired()
|
||||
.HasMaxLength(20);
|
||||
|
||||
builder.Property(oa => oa.Country)
|
||||
.IsRequired()
|
||||
.HasMaxLength(100);
|
||||
|
||||
builder.HasIndex(oa => oa.OrderId)
|
||||
.IsUnique()
|
||||
.HasDatabaseName("IX_OrderAddress_OrderId");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Printbase.Domain.Entities;
|
||||
using Printbase.Domain.Entities.Users;
|
||||
|
||||
namespace Printbase.Infrastructure.Configuration;
|
||||
|
||||
public class OrderConfiguration : EntityBaseConfiguration<Order>
|
||||
{
|
||||
public override void Configure(EntityTypeBuilder<Order> builder)
|
||||
{
|
||||
base.Configure(builder);
|
||||
|
||||
builder.Property(o => o.UserId)
|
||||
.IsRequired()
|
||||
.HasMaxLength(450);
|
||||
|
||||
builder.Property(o => o.OrderDate)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(o => o.TotalPrice)
|
||||
.IsRequired()
|
||||
.HasColumnType("decimal(18,2)");
|
||||
|
||||
builder.Property(o => o.OrderStatusId)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(o => o.ShippingStatusId)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(o => o.OrderNumber)
|
||||
.IsRequired()
|
||||
.HasMaxLength(50);
|
||||
|
||||
builder.Property(o => o.Notes)
|
||||
.HasMaxLength(1000);
|
||||
|
||||
builder.HasOne<ApplicationUser>()
|
||||
.WithMany(u => u.Orders)
|
||||
.HasForeignKey(o => o.UserId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
builder.HasOne(o => o.OrderStatus)
|
||||
.WithMany(os => os.Orders)
|
||||
.HasForeignKey(o => o.OrderStatusId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
builder.HasOne(o => o.ShippingStatus)
|
||||
.WithMany(ss => ss.Orders)
|
||||
.HasForeignKey(o => o.ShippingStatusId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
builder.HasOne(o => o.OrderAddress)
|
||||
.WithOne(oa => oa.Order)
|
||||
.HasForeignKey<OrderAddress>(oa => oa.OrderId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.HasIndex(o => o.UserId)
|
||||
.HasDatabaseName("IX_Order_UserId");
|
||||
|
||||
builder.HasIndex(o => o.OrderNumber)
|
||||
.IsUnique()
|
||||
.HasDatabaseName("IX_Order_OrderNumber");
|
||||
|
||||
builder.HasIndex(o => o.OrderDate)
|
||||
.HasDatabaseName("IX_Order_OrderDate");
|
||||
|
||||
builder.HasIndex(o => o.OrderStatusId)
|
||||
.HasDatabaseName("IX_Order_OrderStatusId");
|
||||
|
||||
builder.HasIndex(o => o.ShippingStatusId)
|
||||
.HasDatabaseName("IX_Order_ShippingStatusId");
|
||||
|
||||
builder.HasIndex(o => new { o.UserId, o.OrderDate })
|
||||
.HasDatabaseName("IX_Order_User_Date");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Printbase.Domain.Entities;
|
||||
|
||||
namespace Printbase.Infrastructure.Configuration;
|
||||
|
||||
public class OrderItemConfiguration : EntityBaseConfiguration<OrderItem>
|
||||
{
|
||||
public override void Configure(EntityTypeBuilder<OrderItem> builder)
|
||||
{
|
||||
base.Configure(builder);
|
||||
|
||||
builder.Property(oi => oi.OrderId)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(oi => oi.ProductId)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(oi => oi.Quantity)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(1);
|
||||
|
||||
builder.Property(oi => oi.UnitPrice)
|
||||
.IsRequired()
|
||||
.HasColumnType("decimal(18,2)");
|
||||
|
||||
builder.Property(oi => oi.TotalPrice)
|
||||
.IsRequired()
|
||||
.HasColumnType("decimal(18,2)");
|
||||
|
||||
builder.Property(oi => oi.CustomizationImageUrl)
|
||||
.HasMaxLength(500);
|
||||
|
||||
builder.Property(oi => oi.CustomizationDescription)
|
||||
.HasMaxLength(2000);
|
||||
|
||||
builder.HasOne(oi => oi.Order)
|
||||
.WithMany(o => o.OrderItems)
|
||||
.HasForeignKey(oi => oi.OrderId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.HasOne(oi => oi.Product)
|
||||
.WithMany(p => p.OrderItems)
|
||||
.HasForeignKey(oi => oi.ProductId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
builder.HasOne(oi => oi.ProductVariant)
|
||||
.WithMany(pv => pv.OrderItems)
|
||||
.HasForeignKey(oi => oi.ProductVariantId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
builder.HasIndex(oi => oi.OrderId)
|
||||
.HasDatabaseName("IX_OrderItem_OrderId");
|
||||
|
||||
builder.HasIndex(oi => oi.ProductId)
|
||||
.HasDatabaseName("IX_OrderItem_ProductId");
|
||||
|
||||
builder.HasIndex(oi => oi.ProductVariantId)
|
||||
.HasDatabaseName("IX_OrderItem_ProductVariantId");
|
||||
|
||||
builder.HasIndex(oi => new { oi.OrderId, oi.ProductId })
|
||||
.HasDatabaseName("IX_OrderItem_Order_Product");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Printbase.Domain.Entities;
|
||||
|
||||
namespace Printbase.Infrastructure.Configuration;
|
||||
|
||||
public class OrderStatusConfiguration : IEntityTypeConfiguration<OrderStatus>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<OrderStatus> builder)
|
||||
{
|
||||
builder.HasKey(os => os.Id);
|
||||
|
||||
builder.Property(os => os.Id)
|
||||
.ValueGeneratedNever();
|
||||
|
||||
builder.Property(os => os.Name)
|
||||
.IsRequired()
|
||||
.HasMaxLength(50);
|
||||
|
||||
builder.HasIndex(os => os.Name)
|
||||
.IsUnique()
|
||||
.HasDatabaseName("IX_OrderStatus_Name");
|
||||
|
||||
builder.HasData(
|
||||
new OrderStatus { Id = 0, Name = "Pending" },
|
||||
new OrderStatus { Id = 1, Name = "Processing" },
|
||||
new OrderStatus { Id = 2, Name = "Completed" },
|
||||
new OrderStatus { Id = 3, Name = "Cancelled" }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Printbase.Domain.Entities;
|
||||
|
||||
namespace Printbase.Infrastructure.Configuration;
|
||||
|
||||
public class ProductConfiguration : EntityBaseConfiguration<Product>
|
||||
{
|
||||
public override void Configure(EntityTypeBuilder<Product> builder)
|
||||
{
|
||||
base.Configure(builder);
|
||||
|
||||
builder.Property(p => p.Name)
|
||||
.IsRequired()
|
||||
.HasMaxLength(200);
|
||||
|
||||
builder.Property(p => p.Description)
|
||||
.HasMaxLength(2000);
|
||||
|
||||
builder.Property(p => p.BasePrice)
|
||||
.IsRequired()
|
||||
.HasColumnType("decimal(18,2)");
|
||||
|
||||
builder.Property(p => p.IsCustomizable)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(false);
|
||||
|
||||
builder.Property(p => p.IsActive)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(true);
|
||||
|
||||
builder.Property(p => p.ImageUrl)
|
||||
.HasMaxLength(500);
|
||||
|
||||
builder.Property(p => p.CategoryId)
|
||||
.IsRequired(false);
|
||||
|
||||
builder.HasOne(p => p.Category)
|
||||
.WithMany(c => c.Products)
|
||||
.HasForeignKey(p => p.CategoryId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
builder.HasIndex(p => p.Name)
|
||||
.HasDatabaseName("IX_Product_Name");
|
||||
|
||||
builder.HasIndex(p => p.IsActive)
|
||||
.HasDatabaseName("IX_Product_IsActive");
|
||||
|
||||
builder.HasIndex(p => p.IsCustomizable)
|
||||
.HasDatabaseName("IX_Product_IsCustomizable");
|
||||
|
||||
builder.HasIndex(p => p.CategoryId)
|
||||
.HasDatabaseName("IX_Product_CategoryId");
|
||||
|
||||
builder.HasIndex(p => new { p.IsActive, p.IsCustomizable })
|
||||
.HasDatabaseName("IX_Product_Active_Customizable");
|
||||
|
||||
builder.HasIndex(p => new { p.CategoryId, p.IsActive })
|
||||
.HasDatabaseName("IX_Product_Category_Active");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Printbase.Domain.Entities;
|
||||
|
||||
namespace Printbase.Infrastructure.Configuration;
|
||||
|
||||
public class ProductVariantConfiguration : EntityBaseConfiguration<ProductVariant>
|
||||
{
|
||||
public override void Configure(EntityTypeBuilder<ProductVariant> builder)
|
||||
{
|
||||
base.Configure(builder);
|
||||
|
||||
builder.Property(pv => pv.ProductId)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(pv => pv.Size)
|
||||
.HasMaxLength(50);
|
||||
|
||||
builder.Property(pv => pv.Color)
|
||||
.HasMaxLength(50);
|
||||
|
||||
builder.Property(pv => pv.Price)
|
||||
.IsRequired()
|
||||
.HasColumnType("decimal(18,2)");
|
||||
|
||||
builder.Property(pv => pv.ImageUrl)
|
||||
.HasMaxLength(500);
|
||||
|
||||
builder.Property(pv => pv.SKU)
|
||||
.IsRequired()
|
||||
.HasMaxLength(100);
|
||||
|
||||
builder.Property(pv => pv.StockQuantity)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(0);
|
||||
|
||||
builder.Property(pv => pv.IsActive)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(true);
|
||||
|
||||
builder.HasOne(pv => pv.Product)
|
||||
.WithMany(p => p.ProductVariants)
|
||||
.HasForeignKey(pv => pv.ProductId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.HasIndex(pv => pv.ProductId)
|
||||
.HasDatabaseName("IX_ProductVariant_ProductId");
|
||||
|
||||
builder.HasIndex(pv => pv.SKU)
|
||||
.IsUnique()
|
||||
.HasDatabaseName("IX_ProductVariant_SKU");
|
||||
|
||||
builder.HasIndex(pv => pv.IsActive)
|
||||
.HasDatabaseName("IX_ProductVariant_IsActive");
|
||||
|
||||
builder.HasIndex(pv => new { pv.ProductId, pv.Size, pv.Color })
|
||||
.IsUnique()
|
||||
.HasDatabaseName("IX_ProductVariant_Product_Size_Color");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Printbase.Domain.Entities;
|
||||
|
||||
namespace Printbase.Infrastructure.Configuration;
|
||||
|
||||
public class ShippingStatusConfiguration : IEntityTypeConfiguration<ShippingStatus>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<ShippingStatus> builder)
|
||||
{
|
||||
builder.HasKey(ss => ss.Id);
|
||||
|
||||
builder.Property(ss => ss.Id)
|
||||
.ValueGeneratedNever();
|
||||
|
||||
builder.Property(ss => ss.Name)
|
||||
.IsRequired()
|
||||
.HasMaxLength(50);
|
||||
|
||||
builder.HasIndex(ss => ss.Name)
|
||||
.IsUnique()
|
||||
.HasDatabaseName("IX_ShippingStatus_Name");
|
||||
|
||||
builder.HasData(
|
||||
new ShippingStatus { Id = 0, Name = "Prepping" },
|
||||
new ShippingStatus { Id = 1, Name = "Packaging" },
|
||||
new ShippingStatus { Id = 2, Name = "Shipped" },
|
||||
new ShippingStatus { Id = 3, Name = "Delivered" }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,37 @@
|
||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Printbase.Infrastructure.DbEntities.Products;
|
||||
using Printbase.Domain.Entities;
|
||||
using Printbase.Domain.Entities.Users;
|
||||
using Printbase.Infrastructure.Configuration;
|
||||
|
||||
namespace Printbase.Infrastructure.Database;
|
||||
|
||||
public class ApplicationDbContext(DbContextOptions<ApplicationDbContext>? options) : DbContext(options)
|
||||
public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
|
||||
: IdentityDbContext<ApplicationUser, ApplicationRole, string>(options)
|
||||
{
|
||||
public DbSet<Product> Products { get; set; }
|
||||
public DbSet<ProductVariant> ProductVariants { get; set; }
|
||||
public DbSet<Order> Orders { get; set; }
|
||||
public DbSet<OrderItem> OrderItems { get; set; }
|
||||
public DbSet<OrderAddress> OrderAddresses { get; set; }
|
||||
public DbSet<Address> Addresses { get; set; }
|
||||
public DbSet<OrderStatus> OrderStatuses { get; set; }
|
||||
public DbSet<ShippingStatus> ShippingStatuses { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
modelBuilder.ApplyConfiguration(new ApplicationUserConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new ApplicationRoleConfiguration());
|
||||
|
||||
modelBuilder.ApplyConfiguration(new ProductConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new ProductVariantConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new OrderConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new OrderItemConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new OrderAddressConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new AddressConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new OrderStatusConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new ShippingStatusConfiguration());
|
||||
}
|
||||
}
|
||||
1150
src/Printbase.Infrastructure/Migrations/20250526100748_InitialSetup.Designer.cs
generated
Normal file
1150
src/Printbase.Infrastructure/Migrations/20250526100748_InitialSetup.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,777 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
|
||||
|
||||
namespace Printbase.Infrastructure.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialSetup : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AspNetRoles",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
Description = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: false),
|
||||
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETUTCDATE()"),
|
||||
IsActive = table.Column<bool>(type: "bit", nullable: false, defaultValue: true),
|
||||
Name = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
|
||||
NormalizedName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
|
||||
ConcurrencyStamp = table.Column<string>(type: "nvarchar(max)", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AspNetRoles", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AspNetUsers",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
FirstName = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
||||
LastName = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
||||
DateOfBirth = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETUTCDATE()"),
|
||||
LastLoginAt = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETUTCDATE()"),
|
||||
IsActive = table.Column<bool>(type: "bit", nullable: false, defaultValue: true),
|
||||
ProfileImageUrl = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: false),
|
||||
UserName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
|
||||
NormalizedUserName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
|
||||
Email = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
|
||||
NormalizedEmail = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
|
||||
EmailConfirmed = table.Column<bool>(type: "bit", nullable: false),
|
||||
PasswordHash = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
SecurityStamp = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
ConcurrencyStamp = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
PhoneNumber = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
PhoneNumberConfirmed = table.Column<bool>(type: "bit", nullable: false),
|
||||
TwoFactorEnabled = table.Column<bool>(type: "bit", nullable: false),
|
||||
LockoutEnd = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
|
||||
LockoutEnabled = table.Column<bool>(type: "bit", nullable: false),
|
||||
AccessFailedCount = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AspNetUsers", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Category",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Description = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
ImageUrl = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
SortOrder = table.Column<int>(type: "int", nullable: false),
|
||||
IsActive = table.Column<bool>(type: "bit", nullable: false),
|
||||
ParentCategoryId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
|
||||
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
ModifiedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
CreatedBy = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
ModifiedBy = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Category", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Category_Category_ParentCategoryId",
|
||||
column: x => x.ParentCategoryId,
|
||||
principalTable: "Category",
|
||||
principalColumn: "Id");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "OrderStatuses",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false),
|
||||
Name = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_OrderStatuses", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ShippingStatuses",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false),
|
||||
Name = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ShippingStatuses", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AspNetRoleClaims",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
RoleId = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
ClaimType = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
ClaimValue = table.Column<string>(type: "nvarchar(max)", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_AspNetRoleClaims_AspNetRoles_RoleId",
|
||||
column: x => x.RoleId,
|
||||
principalTable: "AspNetRoles",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Addresses",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWID()"),
|
||||
UserId = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: false),
|
||||
AddressType = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
|
||||
Street = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
|
||||
City = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
||||
State = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
||||
PostalCode = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
|
||||
Country = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
||||
IsDefault = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
|
||||
IsActive = table.Column<bool>(type: "bit", nullable: false, defaultValue: true),
|
||||
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
ModifiedAt = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETUTCDATE()"),
|
||||
CreatedBy = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: false),
|
||||
ModifiedBy = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Addresses", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Addresses_AspNetUsers_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "AspNetUsers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AspNetUserClaims",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
UserId = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
ClaimType = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
ClaimValue = table.Column<string>(type: "nvarchar(max)", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AspNetUserClaims", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_AspNetUserClaims_AspNetUsers_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "AspNetUsers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AspNetUserLogins",
|
||||
columns: table => new
|
||||
{
|
||||
LoginProvider = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
ProviderKey = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
ProviderDisplayName = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
UserId = table.Column<string>(type: "nvarchar(450)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey });
|
||||
table.ForeignKey(
|
||||
name: "FK_AspNetUserLogins_AspNetUsers_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "AspNetUsers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AspNetUserRoles",
|
||||
columns: table => new
|
||||
{
|
||||
UserId = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
RoleId = table.Column<string>(type: "nvarchar(450)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId });
|
||||
table.ForeignKey(
|
||||
name: "FK_AspNetUserRoles_AspNetRoles_RoleId",
|
||||
column: x => x.RoleId,
|
||||
principalTable: "AspNetRoles",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_AspNetUserRoles_AspNetUsers_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "AspNetUsers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AspNetUserTokens",
|
||||
columns: table => new
|
||||
{
|
||||
UserId = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
LoginProvider = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
Name = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
Value = table.Column<string>(type: "nvarchar(max)", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name });
|
||||
table.ForeignKey(
|
||||
name: "FK_AspNetUserTokens_AspNetUsers_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "AspNetUsers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Products",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWID()"),
|
||||
Name = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
|
||||
Description = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: false),
|
||||
BasePrice = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
|
||||
IsCustomizable = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
|
||||
IsActive = table.Column<bool>(type: "bit", nullable: false, defaultValue: true),
|
||||
ImageUrl = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: false),
|
||||
CategoryId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
|
||||
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
ModifiedAt = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETUTCDATE()"),
|
||||
CreatedBy = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: false),
|
||||
ModifiedBy = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Products", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Products_Category_CategoryId",
|
||||
column: x => x.CategoryId,
|
||||
principalTable: "Category",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Orders",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWID()"),
|
||||
UserId = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: false),
|
||||
OrderDate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
TotalPrice = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
|
||||
OrderStatusId = table.Column<int>(type: "int", nullable: false),
|
||||
ShippingStatusId = table.Column<int>(type: "int", nullable: false),
|
||||
OrderNumber = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
|
||||
Notes = table.Column<string>(type: "nvarchar(1000)", maxLength: 1000, nullable: false),
|
||||
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
ModifiedAt = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETUTCDATE()"),
|
||||
CreatedBy = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: false),
|
||||
ModifiedBy = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Orders", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Orders_AspNetUsers_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "AspNetUsers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "FK_Orders_OrderStatuses_OrderStatusId",
|
||||
column: x => x.OrderStatusId,
|
||||
principalTable: "OrderStatuses",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "FK_Orders_ShippingStatuses_ShippingStatusId",
|
||||
column: x => x.ShippingStatusId,
|
||||
principalTable: "ShippingStatuses",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ProductVariants",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWID()"),
|
||||
ProductId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||
Size = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
|
||||
Color = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
|
||||
Price = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
|
||||
ImageUrl = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: false),
|
||||
SKU = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
||||
StockQuantity = table.Column<int>(type: "int", nullable: false, defaultValue: 0),
|
||||
IsActive = table.Column<bool>(type: "bit", nullable: false, defaultValue: true),
|
||||
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
ModifiedAt = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETUTCDATE()"),
|
||||
CreatedBy = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: false),
|
||||
ModifiedBy = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ProductVariants", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_ProductVariants_Products_ProductId",
|
||||
column: x => x.ProductId,
|
||||
principalTable: "Products",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "OrderAddresses",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWID()"),
|
||||
OrderId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||
Street = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
|
||||
City = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
||||
State = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
||||
PostalCode = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
|
||||
Country = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
||||
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
ModifiedAt = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETUTCDATE()"),
|
||||
CreatedBy = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: false),
|
||||
ModifiedBy = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_OrderAddresses", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_OrderAddresses_Orders_OrderId",
|
||||
column: x => x.OrderId,
|
||||
principalTable: "Orders",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "OrderItems",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false, defaultValueSql: "NEWID()"),
|
||||
OrderId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||
ProductId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||
ProductVariantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
|
||||
Quantity = table.Column<int>(type: "int", nullable: false, defaultValue: 1),
|
||||
UnitPrice = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
|
||||
TotalPrice = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
|
||||
CustomizationImageUrl = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: false),
|
||||
CustomizationDescription = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: false),
|
||||
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
ModifiedAt = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "GETUTCDATE()"),
|
||||
CreatedBy = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: false),
|
||||
ModifiedBy = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_OrderItems", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_OrderItems_Orders_OrderId",
|
||||
column: x => x.OrderId,
|
||||
principalTable: "Orders",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_OrderItems_ProductVariants_ProductVariantId",
|
||||
column: x => x.ProductVariantId,
|
||||
principalTable: "ProductVariants",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "FK_OrderItems_Products_ProductId",
|
||||
column: x => x.ProductId,
|
||||
principalTable: "Products",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "AspNetRoles",
|
||||
columns: new[] { "Id", "ConcurrencyStamp", "CreatedAt", "Description", "IsActive", "Name", "NormalizedName" },
|
||||
values: new object[,]
|
||||
{
|
||||
{ "1", null, new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), "Full system access", true, "Administrator", "ADMINISTRATOR" },
|
||||
{ "2", null, new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), "Standard customer access", true, "Customer", "CUSTOMER" },
|
||||
{ "3", null, new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), "Manage orders and fulfillment", true, "OrderManager", "ORDERMANAGER" },
|
||||
{ "4", null, new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), "Manage products and inventory", true, "ProductManager", "PRODUCTMANAGER" }
|
||||
});
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "OrderStatuses",
|
||||
columns: new[] { "Id", "Name" },
|
||||
values: new object[,]
|
||||
{
|
||||
{ 0, "Pending" },
|
||||
{ 1, "Processing" },
|
||||
{ 2, "Completed" },
|
||||
{ 3, "Cancelled" }
|
||||
});
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "ShippingStatuses",
|
||||
columns: new[] { "Id", "Name" },
|
||||
values: new object[,]
|
||||
{
|
||||
{ 0, "Prepping" },
|
||||
{ 1, "Packaging" },
|
||||
{ 2, "Shipped" },
|
||||
{ 3, "Delivered" }
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Address_CreatedAt",
|
||||
table: "Addresses",
|
||||
column: "CreatedAt");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Address_CreatedBy",
|
||||
table: "Addresses",
|
||||
column: "CreatedBy");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Address_ModifiedAt",
|
||||
table: "Addresses",
|
||||
column: "ModifiedAt");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Address_User_Default",
|
||||
table: "Addresses",
|
||||
columns: new[] { "UserId", "IsDefault" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Address_User_Type",
|
||||
table: "Addresses",
|
||||
columns: new[] { "UserId", "AddressType" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Address_UserId",
|
||||
table: "Addresses",
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AspNetRoleClaims_RoleId",
|
||||
table: "AspNetRoleClaims",
|
||||
column: "RoleId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ApplicationRole_IsActive",
|
||||
table: "AspNetRoles",
|
||||
column: "IsActive");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "RoleNameIndex",
|
||||
table: "AspNetRoles",
|
||||
column: "NormalizedName",
|
||||
unique: true,
|
||||
filter: "[NormalizedName] IS NOT NULL");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AspNetUserClaims_UserId",
|
||||
table: "AspNetUserClaims",
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AspNetUserLogins_UserId",
|
||||
table: "AspNetUserLogins",
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AspNetUserRoles_RoleId",
|
||||
table: "AspNetUserRoles",
|
||||
column: "RoleId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "EmailIndex",
|
||||
table: "AspNetUsers",
|
||||
column: "NormalizedEmail");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "UserNameIndex",
|
||||
table: "AspNetUsers",
|
||||
column: "NormalizedUserName",
|
||||
unique: true,
|
||||
filter: "[NormalizedUserName] IS NOT NULL");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Category_ParentCategoryId",
|
||||
table: "Category",
|
||||
column: "ParentCategoryId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_OrderAddress_CreatedAt",
|
||||
table: "OrderAddresses",
|
||||
column: "CreatedAt");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_OrderAddress_CreatedBy",
|
||||
table: "OrderAddresses",
|
||||
column: "CreatedBy");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_OrderAddress_ModifiedAt",
|
||||
table: "OrderAddresses",
|
||||
column: "ModifiedAt");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_OrderAddress_OrderId",
|
||||
table: "OrderAddresses",
|
||||
column: "OrderId",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_OrderItem_CreatedAt",
|
||||
table: "OrderItems",
|
||||
column: "CreatedAt");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_OrderItem_CreatedBy",
|
||||
table: "OrderItems",
|
||||
column: "CreatedBy");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_OrderItem_ModifiedAt",
|
||||
table: "OrderItems",
|
||||
column: "ModifiedAt");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_OrderItem_Order_Product",
|
||||
table: "OrderItems",
|
||||
columns: new[] { "OrderId", "ProductId" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_OrderItem_OrderId",
|
||||
table: "OrderItems",
|
||||
column: "OrderId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_OrderItem_ProductId",
|
||||
table: "OrderItems",
|
||||
column: "ProductId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_OrderItem_ProductVariantId",
|
||||
table: "OrderItems",
|
||||
column: "ProductVariantId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Order_CreatedAt",
|
||||
table: "Orders",
|
||||
column: "CreatedAt");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Order_CreatedBy",
|
||||
table: "Orders",
|
||||
column: "CreatedBy");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Order_ModifiedAt",
|
||||
table: "Orders",
|
||||
column: "ModifiedAt");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Order_OrderDate",
|
||||
table: "Orders",
|
||||
column: "OrderDate");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Order_OrderNumber",
|
||||
table: "Orders",
|
||||
column: "OrderNumber",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Order_OrderStatusId",
|
||||
table: "Orders",
|
||||
column: "OrderStatusId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Order_ShippingStatusId",
|
||||
table: "Orders",
|
||||
column: "ShippingStatusId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Order_User_Date",
|
||||
table: "Orders",
|
||||
columns: new[] { "UserId", "OrderDate" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Order_UserId",
|
||||
table: "Orders",
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_OrderStatus_Name",
|
||||
table: "OrderStatuses",
|
||||
column: "Name",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Product_Active_Customizable",
|
||||
table: "Products",
|
||||
columns: new[] { "IsActive", "IsCustomizable" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Product_Category_Active",
|
||||
table: "Products",
|
||||
columns: new[] { "CategoryId", "IsActive" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Product_CategoryId",
|
||||
table: "Products",
|
||||
column: "CategoryId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Product_CreatedAt",
|
||||
table: "Products",
|
||||
column: "CreatedAt");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Product_CreatedBy",
|
||||
table: "Products",
|
||||
column: "CreatedBy");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Product_IsActive",
|
||||
table: "Products",
|
||||
column: "IsActive");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Product_IsCustomizable",
|
||||
table: "Products",
|
||||
column: "IsCustomizable");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Product_ModifiedAt",
|
||||
table: "Products",
|
||||
column: "ModifiedAt");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Product_Name",
|
||||
table: "Products",
|
||||
column: "Name");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ProductVariant_CreatedAt",
|
||||
table: "ProductVariants",
|
||||
column: "CreatedAt");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ProductVariant_CreatedBy",
|
||||
table: "ProductVariants",
|
||||
column: "CreatedBy");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ProductVariant_IsActive",
|
||||
table: "ProductVariants",
|
||||
column: "IsActive");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ProductVariant_ModifiedAt",
|
||||
table: "ProductVariants",
|
||||
column: "ModifiedAt");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ProductVariant_Product_Size_Color",
|
||||
table: "ProductVariants",
|
||||
columns: new[] { "ProductId", "Size", "Color" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ProductVariant_ProductId",
|
||||
table: "ProductVariants",
|
||||
column: "ProductId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ProductVariant_SKU",
|
||||
table: "ProductVariants",
|
||||
column: "SKU",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ShippingStatus_Name",
|
||||
table: "ShippingStatuses",
|
||||
column: "Name",
|
||||
unique: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Addresses");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "AspNetRoleClaims");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "AspNetUserClaims");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "AspNetUserLogins");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "AspNetUserRoles");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "AspNetUserTokens");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "OrderAddresses");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "OrderItems");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "AspNetRoles");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Orders");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ProductVariants");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "AspNetUsers");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "OrderStatuses");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ShippingStatuses");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Products");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Category");
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -8,7 +8,12 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="14.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.4" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="9.0.5" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.5" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.5">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.4" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Printbase.Domain.Entities.Users;
|
||||
using Printbase.Infrastructure.Database;
|
||||
|
||||
namespace Printbase.WebApi;
|
||||
@@ -13,6 +15,52 @@ public static class Startup
|
||||
options.UseSqlServer(
|
||||
builder.Configuration.GetConnectionString("DefaultConnection"),
|
||||
b => b.MigrationsAssembly(typeof(ApplicationDbContext).Assembly.FullName)));
|
||||
|
||||
services.AddIdentity<ApplicationUser, ApplicationRole>(options =>
|
||||
{
|
||||
options.Password.RequireDigit = true;
|
||||
options.Password.RequireLowercase = true;
|
||||
options.Password.RequireUppercase = true;
|
||||
options.Password.RequireNonAlphanumeric = true;
|
||||
options.Password.RequiredLength = 8;
|
||||
options.Password.RequiredUniqueChars = 1;
|
||||
|
||||
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30);
|
||||
options.Lockout.MaxFailedAccessAttempts = 5;
|
||||
options.Lockout.AllowedForNewUsers = true;
|
||||
|
||||
options.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+";
|
||||
options.User.RequireUniqueEmail = true;
|
||||
|
||||
options.SignIn.RequireConfirmedEmail = true;
|
||||
options.SignIn.RequireConfirmedPhoneNumber = false;
|
||||
})
|
||||
.AddEntityFrameworkStores<ApplicationDbContext>()
|
||||
.AddDefaultTokenProviders();
|
||||
|
||||
services.ConfigureApplicationCookie(options =>
|
||||
{
|
||||
options.Cookie.HttpOnly = true;
|
||||
options.ExpireTimeSpan = TimeSpan.FromMinutes(60);
|
||||
options.LoginPath = "/Account/Login";
|
||||
options.AccessDeniedPath = "/Account/AccessDenied";
|
||||
options.SlidingExpiration = true;
|
||||
});
|
||||
|
||||
services.Configure<DataProtectionTokenProviderOptions>(options =>
|
||||
{
|
||||
options.TokenLifespan = TimeSpan.FromHours(24);
|
||||
});
|
||||
|
||||
services.AddAuthorizationBuilder()
|
||||
.AddPolicy("AdminPolicy", policy =>
|
||||
policy.RequireRole("Administrator"))
|
||||
.AddPolicy("OrderManagementPolicy", policy =>
|
||||
policy.RequireRole("Administrator", "OrderManager"))
|
||||
.AddPolicy("ProductManagementPolicy", policy =>
|
||||
policy.RequireRole("Administrator", "ProductManager"))
|
||||
.AddPolicy("CustomerPolicy", policy =>
|
||||
policy.RequireRole("Customer", "Administrator", "OrderManager", "ProductManager"));
|
||||
}
|
||||
|
||||
public static void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
@@ -47,6 +95,9 @@ public static class Startup
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Server=db;Database=PrintbaseDb;User Id=sa;Password=Str0ng!Passw0rd383838@@@$23;TrustServerCertificate=True;"
|
||||
"DefaultConnection": "Server=localhost;Database=Printbase;Encrypt=false;Trusted_Connection=True;TrustServerCertificate=true;MultipleActiveResultSets=true;"
|
||||
},
|
||||
"DatabaseOptions": {
|
||||
"ApplyMigrationsAtStartup": true
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Server=db;Database=PrintbaseDb;User Id=sa;Password=Str0ng!Passw0rd383838@@@$23;TrustServerCertificate=True;"
|
||||
"DefaultConnection": "Server=localhost;Database=Printbase;Encrypt=false;TrustServerCertificate=true;Trusted_Connection=True;MultipleActiveResultSets=true;"
|
||||
},
|
||||
"DatabaseOptions": {
|
||||
"ApplyMigrationsAtStartup": true
|
||||
|
||||
Reference in New Issue
Block a user