Files
CMS/src/CMSMicroservice.Infrastructure/Persistence/Configurations/DiscountShop/DiscountShoppingCartConfiguration.cs
T
masoodafar-web f0f48118e7 Add validators and services for Product Galleries and Product Tags
- Implemented Create, Delete, Get, and Update validators for Product Galleries.
- Added Create, Delete, Get, and Update validators for Product Tags.
- Created service classes for handling Discount Categories, Discount Orders, Discount Products, Discount Shopping Cart, Product Categories, Product Galleries, and Product Tags.
- Each service class integrates with CQRS for command and query handling.
- Established mapping profiles for Product Galleries.
2025-12-04 02:40:49 +03:30

42 lines
1.7 KiB
C#

using CMSMicroservice.Domain.Entities.DiscountShop;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace CMSMicroservice.Infrastructure.Persistence.Configurations.DiscountShop;
/// <summary>
/// تنظیمات EF Core برای سبد خرید فروشگاه تخفیفی
/// </summary>
public class DiscountShoppingCartConfiguration : IEntityTypeConfiguration<DiscountShoppingCart>
{
public void Configure(EntityTypeBuilder<DiscountShoppingCart> builder)
{
builder.HasQueryFilter(p => !p.IsDeleted);
builder.Ignore(entity => entity.DomainEvents);
builder.HasKey(entity => entity.Id);
builder.Property(entity => entity.Id).UseIdentityColumn();
builder.Property(entity => entity.UserId).IsRequired();
builder.Property(entity => entity.ProductId).IsRequired();
builder.Property(entity => entity.Count).IsRequired();
// Relationship: User -> ShoppingCarts
builder
.HasOne(entity => entity.User)
.WithMany(entity => entity.DiscountShoppingCarts)
.HasForeignKey(entity => entity.UserId)
.OnDelete(DeleteBehavior.Cascade);
// Relationship: Product -> ShoppingCarts
builder
.HasOne(entity => entity.Product)
.WithMany(entity => entity.ShoppingCarts)
.HasForeignKey(entity => entity.ProductId)
.OnDelete(DeleteBehavior.Cascade);
// Unique constraint: کاربر فقط یک ردیف برای هر محصول در سبد دارد
builder.HasIndex(e => new { e.UserId, e.ProductId }).IsUnique();
}
}