Implement Inventory Management Service with CRUD operations for warehouses and inventory items, stock operations, and bulk processing capabilities.
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 1m48s
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 1m48s
This commit is contained in:
+89
@@ -0,0 +1,89 @@
|
||||
using CMSMicroservice.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace CMSMicroservice.Infrastructure.Persistence.Configurations;
|
||||
|
||||
/// <summary>
|
||||
/// تنظیمات Entity Framework برای انبار
|
||||
/// </summary>
|
||||
public class WarehouseConfiguration : IEntityTypeConfiguration<Warehouse>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Warehouse> builder)
|
||||
{
|
||||
// ========== تنظیمات پایه ==========
|
||||
builder.HasQueryFilter(w => !w.IsDeleted);
|
||||
builder.Ignore(entity => entity.DomainEvents);
|
||||
builder.HasKey(entity => entity.Id);
|
||||
builder.Property(entity => entity.Id).UseIdentityColumn();
|
||||
|
||||
// ========== فیلدهای اصلی ==========
|
||||
|
||||
// نام انبار (اجباری)
|
||||
builder.Property(e => e.Name)
|
||||
.IsRequired()
|
||||
.HasMaxLength(200);
|
||||
|
||||
// کد انبار (اجباری و یکتا)
|
||||
builder.Property(e => e.Code)
|
||||
.IsRequired()
|
||||
.HasMaxLength(50);
|
||||
|
||||
// آدرس انبار (اختیاری)
|
||||
builder.Property(e => e.Address)
|
||||
.IsRequired(false)
|
||||
.HasMaxLength(1000);
|
||||
|
||||
// ========== تنظیمات ==========
|
||||
|
||||
// انبار پیشفرض
|
||||
builder.Property(e => e.IsDefault)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(false);
|
||||
|
||||
// وضعیت فعال/غیرفعال
|
||||
builder.Property(e => e.IsActive)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(true);
|
||||
|
||||
// ========== Index ها ==========
|
||||
|
||||
// Index یکتا روی کد انبار
|
||||
builder.HasIndex(e => e.Code)
|
||||
.IsUnique()
|
||||
.HasDatabaseName("IX_Warehouses_Code_Unique");
|
||||
|
||||
// Index روی IsDefault برای پیدا کردن سریع انبار پیشفرض
|
||||
builder.HasIndex(e => e.IsDefault)
|
||||
.HasDatabaseName("IX_Warehouses_IsDefault")
|
||||
.HasFilter("[IsDefault] = 1");
|
||||
|
||||
// Index روی IsActive برای فیلتر انبارهای فعال
|
||||
builder.HasIndex(e => e.IsActive)
|
||||
.HasDatabaseName("IX_Warehouses_IsActive");
|
||||
|
||||
// ========== روابط ==========
|
||||
|
||||
// رابطه یک-به-چند با InventoryItems
|
||||
builder.HasMany(w => w.InventoryItems)
|
||||
.WithOne(i => i.Warehouse)
|
||||
.HasForeignKey(i => i.WarehouseId)
|
||||
.OnDelete(DeleteBehavior.Restrict); // جلوگیری از حذف انبار در صورت وجود موجودی
|
||||
|
||||
// ========== دادههای اولیه ==========
|
||||
|
||||
// انبار پیشفرض
|
||||
builder.HasData(new Warehouse
|
||||
{
|
||||
Id = 1,
|
||||
Name = "انبار اصلی",
|
||||
Code = "WH-001",
|
||||
Address = "تهران - انبار مرکزی فروشگاه",
|
||||
IsDefault = true,
|
||||
IsActive = true,
|
||||
Created = new DateTime(2026, 1, 1, 0, 0, 0, DateTimeKind.Utc),
|
||||
CreatedBy = "System",
|
||||
IsDeleted = false
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user