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.
This commit is contained in:
masoodafar-web
2025-12-04 02:40:49 +03:30
parent 40d54d08fc
commit f0f48118e7
436 changed files with 33159 additions and 2005 deletions
@@ -17,7 +17,7 @@ public class CategoryConfiguration : IEntityTypeConfiguration<Category>
builder.Property(entity => entity.ImagePath).IsRequired(false);
builder
.HasOne(entity => entity.Parent)
.WithMany(entity => entity.Categorys)
.WithMany(entity => entity.Categories)
.HasForeignKey(entity => entity.ParentId)
.IsRequired(false);
builder.Property(entity => entity.IsActive).IsRequired(true);
@@ -20,6 +20,7 @@ public class ClubMembershipConfiguration : IEntityTypeConfiguration<ClubMembersh
builder.Property(entity => entity.IsActive).IsRequired();
builder.Property(entity => entity.ActivatedAt).IsRequired(false);
builder.Property(entity => entity.InitialContribution).IsRequired();
builder.Property(entity => entity.GiftValue).IsRequired();
builder.Property(entity => entity.TotalEarned).IsRequired();
// رابطه یک‌به‌یک با User
@@ -0,0 +1,45 @@
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 DiscountCategoryConfiguration : IEntityTypeConfiguration<DiscountCategory>
{
public void Configure(EntityTypeBuilder<DiscountCategory> 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.Name)
.IsRequired()
.HasMaxLength(100);
builder.Property(entity => entity.Title)
.IsRequired()
.HasMaxLength(200);
builder.Property(entity => entity.Description)
.HasMaxLength(1000);
builder.Property(entity => entity.ImagePath)
.HasMaxLength(500);
builder.Property(entity => entity.IsActive)
.IsRequired()
.HasDefaultValue(true);
// Self-referencing relationship for parent/child categories
builder
.HasOne(entity => entity.ParentCategory)
.WithMany(entity => entity.ChildCategories)
.HasForeignKey(entity => entity.ParentCategoryId)
.OnDelete(DeleteBehavior.Restrict);
}
}
@@ -0,0 +1,56 @@
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 DiscountOrderConfiguration : IEntityTypeConfiguration<DiscountOrder>
{
public void Configure(EntityTypeBuilder<DiscountOrder> 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.TotalAmount).IsRequired();
builder.Property(entity => entity.DiscountBalanceUsed).IsRequired();
builder.Property(entity => entity.GatewayAmountPaid).IsRequired();
builder.Property(entity => entity.VatAmount).IsRequired();
builder.Property(entity => entity.PaymentStatus).IsRequired();
builder.Property(entity => entity.UserAddressId).IsRequired();
builder.Property(entity => entity.DeliveryStatus).IsRequired();
builder.Property(entity => entity.TrackingCode)
.HasMaxLength(100);
builder.Property(entity => entity.DeliveryDescription)
.HasMaxLength(500);
// Relationship: User -> Orders
builder
.HasOne(entity => entity.User)
.WithMany(entity => entity.DiscountOrders)
.HasForeignKey(entity => entity.UserId)
.OnDelete(DeleteBehavior.Restrict);
// Relationship: Transaction (nullable)
builder
.HasOne(entity => entity.Transaction)
.WithMany()
.HasForeignKey(entity => entity.TransactionId)
.OnDelete(DeleteBehavior.Restrict);
// Relationship: UserAddress
builder
.HasOne(entity => entity.UserAddress)
.WithMany()
.HasForeignKey(entity => entity.UserAddressId)
.OnDelete(DeleteBehavior.Restrict);
}
}
@@ -0,0 +1,42 @@
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 DiscountOrderDetailConfiguration : IEntityTypeConfiguration<DiscountOrderDetail>
{
public void Configure(EntityTypeBuilder<DiscountOrderDetail> 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.DiscountOrderId).IsRequired();
builder.Property(entity => entity.ProductId).IsRequired();
builder.Property(entity => entity.Count).IsRequired();
builder.Property(entity => entity.UnitPrice).IsRequired();
builder.Property(entity => entity.DiscountPercentUsed).IsRequired();
builder.Property(entity => entity.DiscountAmount).IsRequired();
builder.Property(entity => entity.FinalPrice).IsRequired();
// Relationship: Order -> OrderDetails
builder
.HasOne(entity => entity.DiscountOrder)
.WithMany(entity => entity.OrderDetails)
.HasForeignKey(entity => entity.DiscountOrderId)
.OnDelete(DeleteBehavior.Cascade);
// Relationship: Product
builder
.HasOne(entity => entity.Product)
.WithMany(entity => entity.OrderDetails)
.HasForeignKey(entity => entity.ProductId)
.OnDelete(DeleteBehavior.Restrict);
}
}
@@ -0,0 +1,39 @@
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 DiscountProductCategoryConfiguration : IEntityTypeConfiguration<DiscountProductCategory>
{
public void Configure(EntityTypeBuilder<DiscountProductCategory> 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.ProductId).IsRequired();
builder.Property(entity => entity.CategoryId).IsRequired();
// Many-to-Many relationship: Product <-> Category
builder
.HasOne(entity => entity.Product)
.WithMany(entity => entity.ProductCategories)
.HasForeignKey(entity => entity.ProductId)
.OnDelete(DeleteBehavior.Cascade);
builder
.HasOne(entity => entity.Category)
.WithMany(entity => entity.ProductCategories)
.HasForeignKey(entity => entity.CategoryId)
.OnDelete(DeleteBehavior.Cascade);
// Unique constraint: یک محصول فقط یکبار در یک دسته
builder.HasIndex(e => new { e.ProductId, e.CategoryId }).IsUnique();
}
}
@@ -0,0 +1,50 @@
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 DiscountProductConfiguration : IEntityTypeConfiguration<DiscountProduct>
{
public void Configure(EntityTypeBuilder<DiscountProduct> 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.Title)
.IsRequired()
.HasMaxLength(200);
builder.Property(entity => entity.ShortInfomation)
.IsRequired()
.HasMaxLength(500);
builder.Property(entity => entity.FullInformation)
.IsRequired()
.HasMaxLength(2000);
builder.Property(entity => entity.Price)
.IsRequired();
builder.Property(entity => entity.MaxDiscountPercent)
.IsRequired();
builder.Property(entity => entity.ImagePath)
.IsRequired()
.HasMaxLength(500);
builder.Property(entity => entity.ThumbnailPath)
.IsRequired()
.HasMaxLength(500);
builder.Property(entity => entity.IsActive)
.IsRequired()
.HasDefaultValue(true);
}
}
@@ -0,0 +1,41 @@
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();
}
}
@@ -13,7 +13,7 @@ public class FactorDetailsConfiguration : IEntityTypeConfiguration<FactorDetails
builder.Property(entity => entity.Id).UseIdentityColumn();
builder
.HasOne(entity => entity.Product)
.WithMany(entity => entity.FactorDetailss)
.WithMany(entity => entity.FactorDetails)
.HasForeignKey(entity => entity.ProductId)
.IsRequired(true);
builder.Property(entity => entity.Count).IsRequired(true);
@@ -21,7 +21,7 @@ public class FactorDetailsConfiguration : IEntityTypeConfiguration<FactorDetails
builder.Property(entity => entity.UnitDiscount).IsRequired(true);
builder
.HasOne(entity => entity.Order)
.WithMany(entity => entity.FactorDetailss)
.WithMany(entity => entity.FactorDetails)
.HasForeignKey(entity => entity.OrderId)
.IsRequired(true);
builder.Property(entity => entity.UnitDiscountPrice).IsRequired(true);
@@ -0,0 +1,65 @@
using CMSMicroservice.Domain.Entities.Payment;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace CMSMicroservice.Infrastructure.Persistence.Configurations;
public class ManualPaymentConfiguration : IEntityTypeConfiguration<ManualPayment>
{
public void Configure(EntityTypeBuilder<ManualPayment> builder)
{
builder.ToTable("ManualPayments");
builder.HasKey(x => x.Id);
builder.Property(x => x.UserId)
.IsRequired();
builder.Property(x => x.Amount)
.IsRequired();
builder.Property(x => x.Type)
.IsRequired();
builder.Property(x => x.Description)
.IsRequired()
.HasMaxLength(1000);
builder.Property(x => x.ReferenceNumber)
.HasMaxLength(100);
builder.Property(x => x.Status)
.IsRequired();
builder.Property(x => x.RequestedBy)
.IsRequired();
builder.Property(x => x.ApprovedBy);
builder.Property(x => x.ApprovedAt);
builder.Property(x => x.RejectionReason)
.HasMaxLength(500);
builder.Property(x => x.TransactionId);
// Relations
builder.HasOne(x => x.User)
.WithMany()
.HasForeignKey(x => x.UserId)
.OnDelete(DeleteBehavior.Restrict);
builder.HasOne(x => x.Transaction)
.WithMany()
.HasForeignKey(x => x.TransactionId)
.OnDelete(DeleteBehavior.Restrict);
// Indexes
builder.HasIndex(x => x.UserId);
builder.HasIndex(x => x.Status);
builder.HasIndex(x => x.RequestedBy);
builder.HasIndex(x => x.ApprovedBy);
builder.HasIndex(x => x.Created);
builder.HasIndex(x => new { x.UserId, x.Status });
}
}
@@ -0,0 +1,55 @@
using CMSMicroservice.Domain.Entities.Order;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace CMSMicroservice.Infrastructure.Persistence.Configurations;
public class OrderVATConfiguration : IEntityTypeConfiguration<OrderVAT>
{
public void Configure(EntityTypeBuilder<OrderVAT> builder)
{
builder.ToTable("OrderVATs");
builder.HasKey(x => x.Id);
builder.Property(x => x.OrderId)
.IsRequired();
builder.Property(x => x.VATRate)
.IsRequired()
.HasColumnType("decimal(5,4)"); // 0.0900 (9%)
builder.Property(x => x.BaseAmount)
.IsRequired();
builder.Property(x => x.VATAmount)
.IsRequired();
builder.Property(x => x.TotalAmount)
.IsRequired();
builder.Property(x => x.IsPaid)
.IsRequired()
.HasDefaultValue(false);
builder.Property(x => x.Note)
.HasMaxLength(500);
// Foreign Key
builder.HasOne(x => x.Order)
.WithOne()
.HasForeignKey<OrderVAT>(x => x.OrderId)
.OnDelete(DeleteBehavior.Restrict);
// Indexes
builder.HasIndex(x => x.OrderId)
.IsUnique()
.HasDatabaseName("IX_OrderVATs_OrderId");
builder.HasIndex(x => x.IsPaid)
.HasDatabaseName("IX_OrderVATs_IsPaid");
builder.HasIndex(x => x.Created)
.HasDatabaseName("IX_OrderVATs_Created");
}
}
@@ -0,0 +1,21 @@
using CMSMicroservice.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace CMSMicroservice.Infrastructure.Persistence.Configurations;
public class ProductCategoryConfiguration : IEntityTypeConfiguration<ProductCategory>
{
public void Configure(EntityTypeBuilder<ProductCategory> builder)
{
builder.ToTable("ProductCategories", "CMS");
builder.HasKey(e => e.Id);
builder.HasOne(d => d.Product)
.WithMany(p => p.ProductCategories)
.HasForeignKey(d => d.ProductId);
builder.HasOne(d => d.Category)
.WithMany(p => p.ProductCategories)
.HasForeignKey(d => d.CategoryId);
}
}
@@ -2,10 +2,10 @@ using CMSMicroservice.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace CMSMicroservice.Infrastructure.Persistence.Configurations;
//توکن Otp
public class ProductsConfiguration : IEntityTypeConfiguration<Products>
//محصول
public class ProductConfiguration : IEntityTypeConfiguration<Product>
{
public void Configure(EntityTypeBuilder<Products> builder)
public void Configure(EntityTypeBuilder<Product> builder)
{
builder.HasQueryFilter(p => !p.IsDeleted);
builder.Ignore(entity => entity.DomainEvents);
@@ -2,24 +2,24 @@ using CMSMicroservice.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace CMSMicroservice.Infrastructure.Persistence.Configurations;
//برچسب محصول
public class PruductTagConfiguration : IEntityTypeConfiguration<PruductTag>
//تنظیمات گالری تصاویر محصول
public class ProductGalleriesConfiguration : IEntityTypeConfiguration<ProductGallery>
{
public void Configure(EntityTypeBuilder<PruductTag> builder)
public void Configure(EntityTypeBuilder<ProductGallery> builder)
{
builder.HasQueryFilter(p => !p.IsDeleted);
builder.Ignore(entity => entity.DomainEvents);
builder.HasKey(entity => entity.Id);
builder.Property(entity => entity.Id).UseIdentityColumn();
builder
.HasOne(entity => entity.Product)
.WithMany(entity => entity.PruductTags)
.HasForeignKey(entity => entity.ProductId)
.HasOne(entity => entity.ProductImage)
.WithMany(entity => entity.ProductGalleries)
.HasForeignKey(entity => entity.ProductImageId)
.IsRequired(true);
builder
.HasOne(entity => entity.Tag)
.WithMany(entity => entity.PruductTags)
.HasForeignKey(entity => entity.TagId)
.HasOne(entity => entity.Product)
.WithMany(entity => entity.ProductGalleries)
.HasForeignKey(entity => entity.ProductId)
.IsRequired(true);
}
@@ -2,24 +2,24 @@ using CMSMicroservice.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace CMSMicroservice.Infrastructure.Persistence.Configurations;
//دسته بندی
public class PruductCategoryConfiguration : IEntityTypeConfiguration<PruductCategory>
//تنظیمات گالری تصاویر محصول
public class ProductGalleryConfiguration : IEntityTypeConfiguration<ProductGallery>
{
public void Configure(EntityTypeBuilder<PruductCategory> builder)
public void Configure(EntityTypeBuilder<ProductGallery> builder)
{
builder.HasQueryFilter(p => !p.IsDeleted);
builder.Ignore(entity => entity.DomainEvents);
builder.HasKey(entity => entity.Id);
builder.Property(entity => entity.Id).UseIdentityColumn();
builder
.HasOne(entity => entity.Product)
.WithMany(entity => entity.PruductCategorys)
.HasForeignKey(entity => entity.ProductId)
.HasOne(entity => entity.ProductImage)
.WithMany(entity => entity.ProductGalleries)
.HasForeignKey(entity => entity.ProductImageId)
.IsRequired(true);
builder
.HasOne(entity => entity.Category)
.WithMany(entity => entity.PruductCategorys)
.HasForeignKey(entity => entity.CategoryId)
.HasOne(entity => entity.Product)
.WithMany(entity => entity.ProductGalleries)
.HasForeignKey(entity => entity.ProductId)
.IsRequired(true);
}
@@ -3,9 +3,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace CMSMicroservice.Infrastructure.Persistence.Configurations;
//توکن Otp
public class ProductGallerysConfiguration : IEntityTypeConfiguration<ProductGallerys>
public class ProductGallerysConfiguration : IEntityTypeConfiguration<ProductGallery>
{
public void Configure(EntityTypeBuilder<ProductGallerys> builder)
public void Configure(EntityTypeBuilder<ProductGallery> builder)
{
builder.HasQueryFilter(p => !p.IsDeleted);
builder.Ignore(entity => entity.DomainEvents);
@@ -13,12 +13,12 @@ public class ProductGallerysConfiguration : IEntityTypeConfiguration<ProductGall
builder.Property(entity => entity.Id).UseIdentityColumn();
builder
.HasOne(entity => entity.ProductImage)
.WithMany(entity => entity.ProductGalleryss)
.WithMany(entity => entity.ProductGalleries)
.HasForeignKey(entity => entity.ProductImageId)
.IsRequired(true);
builder
.HasOne(entity => entity.Product)
.WithMany(entity => entity.ProductGalleryss)
.WithMany(entity => entity.ProductGalleries)
.HasForeignKey(entity => entity.ProductId)
.IsRequired(true);
@@ -2,10 +2,10 @@ using CMSMicroservice.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace CMSMicroservice.Infrastructure.Persistence.Configurations;
//توکن Otp
public class ProductImagesConfiguration : IEntityTypeConfiguration<ProductImages>
//تصاویر محصول
public class ProductImageConfiguration : IEntityTypeConfiguration<ProductImage>
{
public void Configure(EntityTypeBuilder<ProductImages> builder)
public void Configure(EntityTypeBuilder<ProductImage> builder)
{
builder.HasQueryFilter(p => !p.IsDeleted);
builder.Ignore(entity => entity.DomainEvents);
@@ -0,0 +1,21 @@
using CMSMicroservice.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace CMSMicroservice.Infrastructure.Persistence.Configurations;
public class ProductTagConfiguration : IEntityTypeConfiguration<ProductTag>
{
public void Configure(EntityTypeBuilder<ProductTag> builder)
{
builder.ToTable("ProductTags", "CMS");
builder.HasKey(e => e.Id);
builder.HasOne(d => d.Product)
.WithMany(p => p.ProductTags)
.HasForeignKey(d => d.ProductId);
builder.HasOne(d => d.Tag)
.WithMany(p => p.ProductTags)
.HasForeignKey(d => d.TagId);
}
}
@@ -0,0 +1,74 @@
using CMSMicroservice.Domain.Entities.Message;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace CMSMicroservice.Infrastructure.Persistence.Configurations;
public class PublicMessageConfiguration : IEntityTypeConfiguration<PublicMessage>
{
public void Configure(EntityTypeBuilder<PublicMessage> builder)
{
builder.ToTable("PublicMessages");
builder.HasKey(x => x.Id);
builder.Property(x => x.Title)
.IsRequired()
.HasMaxLength(200);
builder.Property(x => x.Content)
.IsRequired()
.HasMaxLength(2000);
builder.Property(x => x.Type)
.IsRequired();
builder.Property(x => x.Priority)
.IsRequired();
builder.Property(x => x.IsActive)
.IsRequired()
.HasDefaultValue(true);
builder.Property(x => x.StartsAt)
.IsRequired();
builder.Property(x => x.ExpiresAt)
.IsRequired();
builder.Property(x => x.CreatedByUserId)
.IsRequired();
builder.Property(x => x.ViewCount)
.IsRequired()
.HasDefaultValue(0);
builder.Property(x => x.LinkUrl)
.HasMaxLength(500);
builder.Property(x => x.LinkText)
.HasMaxLength(100);
// Indexes
builder.HasIndex(x => x.IsActive)
.HasDatabaseName("IX_PublicMessages_IsActive");
builder.HasIndex(x => x.Type)
.HasDatabaseName("IX_PublicMessages_Type");
builder.HasIndex(x => x.Priority)
.HasDatabaseName("IX_PublicMessages_Priority");
builder.HasIndex(x => x.StartsAt)
.HasDatabaseName("IX_PublicMessages_StartsAt");
builder.HasIndex(x => x.ExpiresAt)
.HasDatabaseName("IX_PublicMessages_ExpiresAt");
builder.HasIndex(x => x.CreatedByUserId)
.HasDatabaseName("IX_PublicMessages_CreatedByUserId");
builder.HasIndex(x => new { x.IsActive, x.ExpiresAt })
.HasDatabaseName("IX_PublicMessages_IsActive_ExpiresAt");
}
}
@@ -2,10 +2,10 @@ using CMSMicroservice.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace CMSMicroservice.Infrastructure.Persistence.Configurations;
//آدرس کاربر
public class TransactionsConfiguration : IEntityTypeConfiguration<Transactions>
//تراکنش
public class TransactionConfiguration : IEntityTypeConfiguration<Transaction>
{
public void Configure(EntityTypeBuilder<Transactions> builder)
public void Configure(EntityTypeBuilder<Transaction> builder)
{
builder.HasQueryFilter(p => !p.IsDeleted);
builder.Ignore(entity => entity.DomainEvents);
@@ -13,7 +13,7 @@ public class UserAddressConfiguration : IEntityTypeConfiguration<UserAddress>
builder.Property(entity => entity.Id).UseIdentityColumn();
builder
.HasOne(entity => entity.User)
.WithMany(entity => entity.UserAddresss)
.WithMany(entity => entity.UserAddresses)
.HasForeignKey(entity => entity.UserId)
.IsRequired(true);
builder.Property(entity => entity.Title).IsRequired(true);
@@ -0,0 +1,27 @@
using CMSMicroservice.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace CMSMicroservice.Infrastructure.Persistence.Configurations;
//تنظیمات سبد خرید کاربر
public class UserCartConfiguration : IEntityTypeConfiguration<UserCart>
{
public void Configure(EntityTypeBuilder<UserCart> builder)
{
builder.HasQueryFilter(p => !p.IsDeleted);
builder.Ignore(entity => entity.DomainEvents);
builder.HasKey(entity => entity.Id);
builder.Property(entity => entity.Id).UseIdentityColumn();
builder
.HasOne(entity => entity.Product)
.WithMany(entity => entity.UserCarts)
.HasForeignKey(entity => entity.ProductId)
.IsRequired(true);
builder
.HasOne(entity => entity.User)
.WithMany(entity => entity.UserCarts)
.HasForeignKey(entity => entity.UserId)
.IsRequired(true);
builder.Property(entity => entity.Count).IsRequired(true);
}
}
@@ -3,9 +3,9 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace CMSMicroservice.Infrastructure.Persistence.Configurations;
//آدرس کاربر
public class UserCartsConfiguration : IEntityTypeConfiguration<UserCarts>
public class UserCartsConfiguration : IEntityTypeConfiguration<UserCart>
{
public void Configure(EntityTypeBuilder<UserCarts> builder)
public void Configure(EntityTypeBuilder<UserCart> builder)
{
builder.HasQueryFilter(p => !p.IsDeleted);
builder.Ignore(entity => entity.DomainEvents);
@@ -13,12 +13,12 @@ public class UserCartsConfiguration : IEntityTypeConfiguration<UserCarts>
builder.Property(entity => entity.Id).UseIdentityColumn();
builder
.HasOne(entity => entity.Product)
.WithMany(entity => entity.UserCartss)
.WithMany(entity => entity.UserCarts)
.HasForeignKey(entity => entity.ProductId)
.IsRequired(true);
builder
.HasOne(entity => entity.User)
.WithMany(entity => entity.UserCartss)
.WithMany(entity => entity.UserCarts)
.HasForeignKey(entity => entity.UserId)
.IsRequired(true);
builder.Property(entity => entity.Count).IsRequired(true);
@@ -16,11 +16,6 @@ public class UserConfiguration : IEntityTypeConfiguration<User>
builder.Property(entity => entity.Mobile).IsRequired(true);
builder.Property(entity => entity.NationalCode).IsRequired(false);
builder.Property(entity => entity.AvatarPath).IsRequired(false);
builder
.HasOne(entity => entity.Parent)
.WithMany(entity => entity.Users)
.HasForeignKey(entity => entity.ParentId)
.IsRequired(false);
builder.Property(entity => entity.ReferralCode).IsRequired(true);
builder.Property(entity => entity.IsMobileVerified ).IsRequired(true);
builder.Property(entity => entity.MobileVerifiedAt).IsRequired(false);
@@ -0,0 +1,70 @@
using CMSMicroservice.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace CMSMicroservice.Infrastructure.Persistence.Configurations;
/// <summary>
/// خرید پکیج توسط کاربر
/// </summary>
public class UserPackagePurchaseConfiguration : IEntityTypeConfiguration<UserPackagePurchase>
{
public void Configure(EntityTypeBuilder<UserPackagePurchase> 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.PackageId).IsRequired();
builder.Property(entity => entity.PurchaseMethod).IsRequired();
builder.Property(entity => entity.PurchasedAt).IsRequired();
builder.Property(entity => entity.Amount).IsRequired();
builder.Property(entity => entity.OrderId).IsRequired(false);
builder.Property(entity => entity.TransactionId).IsRequired(false);
// رابطه با User
builder.HasOne(entity => entity.User)
.WithMany() // User can have multiple package purchases
.HasForeignKey(entity => entity.UserId)
.OnDelete(DeleteBehavior.Restrict);
// رابطه با Package
builder.HasOne(entity => entity.Package)
.WithMany()
.HasForeignKey(entity => entity.PackageId)
.OnDelete(DeleteBehavior.Restrict);
// رابطه با UserOrder (اختیاری)
builder.HasOne(entity => entity.Order)
.WithMany()
.HasForeignKey(entity => entity.OrderId)
.OnDelete(DeleteBehavior.Restrict)
.IsRequired(false);
// رابطه با Transaction (اختیاری)
builder.HasOne(entity => entity.Transaction)
.WithMany()
.HasForeignKey(entity => entity.TransactionId)
.OnDelete(DeleteBehavior.Restrict)
.IsRequired(false);
// Index برای UserId (برای کوئری سریع)
builder.HasIndex(e => e.UserId)
.HasDatabaseName("IX_UserPackagePurchase_UserId");
// Index برای PackageId
builder.HasIndex(e => e.PackageId)
.HasDatabaseName("IX_UserPackagePurchase_PackageId");
// Index برای PurchasedAt (برای فیلتر زمانی)
builder.HasIndex(e => e.PurchasedAt)
.HasDatabaseName("IX_UserPackagePurchase_PurchasedAt");
// Composite Index برای UserId + PurchasedAt (کوئری‌های متداول)
builder.HasIndex(e => new { e.UserId, e.PurchasedAt })
.HasDatabaseName("IX_UserPackagePurchase_UserId_PurchasedAt");
}
}