refactor: rename UserWalletChangeLog→UserWalletHistory, add History interceptor & migration
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 9m11s
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 9m11s
- Rename UserWalletChangeLog to UserWalletHistory across 54+ files (entities, configs, DTOs, commands, queries, protos, services) - Rename 34 files and 11 directories accordingly - Rename proto file userwalletchangelog.proto → userwallethistory.proto - Add IHasHistory<T> generic interface for history auto-tracking - Implement IHasHistory<PackageHistory> on Package entity - Add HistoryTrackingSaveChangesInterceptor (reflection-based, auto-fills Old* values from OriginalValues) - Wire interceptor in DI and ApplicationDbContext - Add EF migration Q27_HistoryTables_And_RenameWalletHistory: * RenameTable UserWalletChangeLogs → UserWalletHistories (preserves data) * Rename PK, FK constraints and indexes via sp_rename * CreateTable ClubMembershipCycleHistories + PackageHistories
This commit is contained in:
@@ -31,6 +31,7 @@ public static class ConfigureServices
|
||||
services.Configure<SmsSettings>(configuration.GetSection(SmsSettings.SectionName));
|
||||
|
||||
services.AddScoped<AuditableEntitySaveChangesInterceptor>();
|
||||
services.AddScoped<HistoryTrackingSaveChangesInterceptor>();
|
||||
services.AddScoped<ApplicationDbContextInitialiser>();
|
||||
services.AddScoped<IGenerateJwtToken, GenerateJwtTokenService>();
|
||||
services.AddScoped<IHashService, HashService>();
|
||||
|
||||
@@ -18,6 +18,7 @@ public class ApplicationDbContext : DbContext, IApplicationDbContext
|
||||
{
|
||||
private readonly IMediator? _mediator;
|
||||
private readonly AuditableEntitySaveChangesInterceptor? _auditableEntitySaveChangesInterceptor;
|
||||
private readonly HistoryTrackingSaveChangesInterceptor? _historyTrackingInterceptor;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor برای design-time (migrations)
|
||||
@@ -33,11 +34,13 @@ public class ApplicationDbContext : DbContext, IApplicationDbContext
|
||||
public ApplicationDbContext(
|
||||
DbContextOptions<ApplicationDbContext> options,
|
||||
IMediator mediator,
|
||||
AuditableEntitySaveChangesInterceptor auditableEntitySaveChangesInterceptor)
|
||||
AuditableEntitySaveChangesInterceptor auditableEntitySaveChangesInterceptor,
|
||||
HistoryTrackingSaveChangesInterceptor historyTrackingInterceptor)
|
||||
: base(options)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_auditableEntitySaveChangesInterceptor = auditableEntitySaveChangesInterceptor;
|
||||
_historyTrackingInterceptor = historyTrackingInterceptor;
|
||||
}
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
@@ -57,6 +60,11 @@ public class ApplicationDbContext : DbContext, IApplicationDbContext
|
||||
optionsBuilder.AddInterceptors(_auditableEntitySaveChangesInterceptor);
|
||||
}
|
||||
|
||||
if (_historyTrackingInterceptor != null)
|
||||
{
|
||||
optionsBuilder.AddInterceptors(_historyTrackingInterceptor);
|
||||
}
|
||||
|
||||
// Suppress PendingModelChangesWarning in EF Core 9
|
||||
optionsBuilder.ConfigureWarnings(w => w.Ignore(RelationalEventId.PendingModelChangesWarning));
|
||||
}
|
||||
@@ -89,7 +97,7 @@ public class ApplicationDbContext : DbContext, IApplicationDbContext
|
||||
public DbSet<OrderVAT> OrderVATs => Set<OrderVAT>();
|
||||
public DbSet<UserPackagePurchase> UserPackagePurchases => Set<UserPackagePurchase>();
|
||||
public DbSet<UserWallet> UserWallets => Set<UserWallet>();
|
||||
public DbSet<UserWalletChangeLog> UserWalletChangeLogs => Set<UserWalletChangeLog>();
|
||||
public DbSet<UserWalletHistory> UserWalletHistories => Set<UserWalletHistory>();
|
||||
public DbSet<DayaLoanContract> DayaLoanContracts => Set<DayaLoanContract>();
|
||||
|
||||
// Payment
|
||||
|
||||
+3
-3
@@ -3,9 +3,9 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
namespace CMSMicroservice.Infrastructure.Persistence.Configurations;
|
||||
//آدرس کاربر
|
||||
public class UserWalletChangeLogConfiguration : IEntityTypeConfiguration<UserWalletChangeLog>
|
||||
public class UserWalletHistoryConfiguration : IEntityTypeConfiguration<UserWalletHistory>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<UserWalletChangeLog> builder)
|
||||
public void Configure(EntityTypeBuilder<UserWalletHistory> builder)
|
||||
{
|
||||
builder.HasQueryFilter(p => !p.IsDeleted);
|
||||
builder.Ignore(entity => entity.DomainEvents);
|
||||
@@ -13,7 +13,7 @@ public class UserWalletChangeLogConfiguration : IEntityTypeConfiguration<UserWal
|
||||
builder.Property(entity => entity.Id).UseIdentityColumn();
|
||||
builder
|
||||
.HasOne(entity => entity.Wallet)
|
||||
.WithMany(entity => entity.UserWalletChangeLogs)
|
||||
.WithMany(entity => entity.UserWalletHistories)
|
||||
.HasForeignKey(entity => entity.WalletId)
|
||||
.IsRequired(true);
|
||||
builder.Property(entity => entity.CurrentBalance).IsRequired(true);
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CMSMicroservice.Application.Common.Interfaces;
|
||||
using CMSMicroservice.Domain.Common;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CMSMicroservice.Infrastructure.Persistence.Interceptors;
|
||||
|
||||
/// <summary>
|
||||
/// Interceptor ثبت خودکار تاریخچه تغییرات (Q27).
|
||||
/// هر entity که IHasHistory<T> رو implement کرده باشه،
|
||||
/// هنگام Modified یا Added شدن یک رکورد history ثبت میشه.
|
||||
/// </summary>
|
||||
public class HistoryTrackingSaveChangesInterceptor : SaveChangesInterceptor
|
||||
{
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly ILogger<HistoryTrackingSaveChangesInterceptor> _logger;
|
||||
|
||||
public HistoryTrackingSaveChangesInterceptor(
|
||||
ICurrentUserService currentUserService,
|
||||
ILogger<HistoryTrackingSaveChangesInterceptor> logger)
|
||||
{
|
||||
_currentUserService = currentUserService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public override InterceptionResult<int> SavingChanges(
|
||||
DbContextEventData eventData,
|
||||
InterceptionResult<int> result)
|
||||
{
|
||||
TrackHistoryChanges(eventData.Context);
|
||||
return base.SavingChanges(eventData, result);
|
||||
}
|
||||
|
||||
public override ValueTask<InterceptionResult<int>> SavingChangesAsync(
|
||||
DbContextEventData eventData,
|
||||
InterceptionResult<int> result,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
TrackHistoryChanges(eventData.Context);
|
||||
return base.SavingChangesAsync(eventData, result, cancellationToken);
|
||||
}
|
||||
|
||||
private void TrackHistoryChanges(DbContext? context)
|
||||
{
|
||||
if (context == null) return;
|
||||
|
||||
var performedBy = _currentUserService.GetPerformedBy();
|
||||
var historyEntries = new List<object>();
|
||||
|
||||
foreach (var entry in context.ChangeTracker.Entries())
|
||||
{
|
||||
// فقط Modified و Added — Deleted رو ignore میکنیم (soft delete)
|
||||
if (entry.State != EntityState.Modified && entry.State != EntityState.Added)
|
||||
continue;
|
||||
|
||||
var entityType = entry.Entity.GetType();
|
||||
|
||||
// بررسی اینکه entity آیا IHasHistory<T> رو implement کرده
|
||||
var historyInterface = entityType.GetInterfaces()
|
||||
.FirstOrDefault(i => i.IsGenericType
|
||||
&& i.GetGenericTypeDefinition() == typeof(IHasHistory<>));
|
||||
|
||||
if (historyInterface == null)
|
||||
continue;
|
||||
|
||||
// تعیین نوع عملیات
|
||||
var action = entry.State == EntityState.Added ? "Created" : "Updated";
|
||||
|
||||
try
|
||||
{
|
||||
// فراخوانی CreateHistorySnapshot از طریق reflection
|
||||
var method = historyInterface.GetMethod("CreateHistorySnapshot");
|
||||
if (method == null) continue;
|
||||
|
||||
var historyEntity = method.Invoke(entry.Entity, new object?[] { action, performedBy });
|
||||
if (historyEntity == null) continue;
|
||||
|
||||
// برای Modified: مقادیر Original رو ست کنیم
|
||||
if (entry.State == EntityState.Modified)
|
||||
{
|
||||
SetOriginalValues(entry, historyEntity);
|
||||
}
|
||||
|
||||
historyEntries.Add(historyEntity);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex,
|
||||
"Failed to create history snapshot for {EntityType} (Id={Id})",
|
||||
entityType.Name,
|
||||
entry.Property("Id").CurrentValue);
|
||||
}
|
||||
}
|
||||
|
||||
// اضافه کردن history entities به context
|
||||
foreach (var historyEntry in historyEntries)
|
||||
{
|
||||
context.Add(historyEntry);
|
||||
}
|
||||
|
||||
if (historyEntries.Count > 0)
|
||||
{
|
||||
_logger.LogDebug("HistoryTrackingInterceptor: {Count} history records queued", historyEntries.Count);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ست کردن مقادیر Original (قبل از تغییر) روی history entity.
|
||||
/// از روی نام property: "OldX" ← OriginalValue("X"), "NewX" ← CurrentValue("X")
|
||||
/// </summary>
|
||||
private static void SetOriginalValues(
|
||||
Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry entry,
|
||||
object historyEntity)
|
||||
{
|
||||
var historyType = historyEntity.GetType();
|
||||
var historyProps = historyType.GetProperties();
|
||||
|
||||
foreach (var historyProp in historyProps)
|
||||
{
|
||||
// الگو: OldPrice ← entry.OriginalValues["Price"]
|
||||
if (!historyProp.Name.StartsWith("Old") || !historyProp.CanWrite)
|
||||
continue;
|
||||
|
||||
var sourcePropertyName = historyProp.Name[3..]; // "OldPrice" → "Price"
|
||||
|
||||
try
|
||||
{
|
||||
var entryProperty = entry.Properties
|
||||
.FirstOrDefault(p => p.Metadata.Name == sourcePropertyName);
|
||||
|
||||
if (entryProperty != null)
|
||||
{
|
||||
var originalValue = entryProperty.OriginalValue;
|
||||
// تبدیل نوع اگه nullable باشه
|
||||
if (originalValue != null || Nullable.GetUnderlyingType(historyProp.PropertyType) != null)
|
||||
{
|
||||
historyProp.SetValue(historyEntity, originalValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// اگه property match نداشت، skip — ممکنه OldIsActive با bool? باشه
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+5203
File diff suppressed because it is too large
Load Diff
+190
@@ -0,0 +1,190 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace CMSMicroservice.Infrastructure.Persistence.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class Q27_HistoryTables_And_RenameWalletHistory : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.RenameTable(
|
||||
name: "UserWalletChangeLogs",
|
||||
schema: "CMS",
|
||||
newName: "UserWalletHistories",
|
||||
newSchema: "CMS");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_UserWalletChangeLogs_PackageId",
|
||||
schema: "CMS",
|
||||
table: "UserWalletHistories",
|
||||
newName: "IX_UserWalletHistories_PackageId");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_UserWalletChangeLogs_WalletId",
|
||||
schema: "CMS",
|
||||
table: "UserWalletHistories",
|
||||
newName: "IX_UserWalletHistories_WalletId");
|
||||
|
||||
migrationBuilder.Sql(
|
||||
"EXEC sp_rename N'CMS.PK_UserWalletChangeLogs', N'PK_UserWalletHistories', N'OBJECT'");
|
||||
|
||||
migrationBuilder.Sql(
|
||||
"EXEC sp_rename N'CMS.FK_UserWalletChangeLogs_Packages_PackageId', N'FK_UserWalletHistories_Packages_PackageId', N'OBJECT'");
|
||||
|
||||
migrationBuilder.Sql(
|
||||
"EXEC sp_rename N'CMS.FK_UserWalletChangeLogs_UserWallets_WalletId', N'FK_UserWalletHistories_UserWallets_WalletId', N'OBJECT'");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ClubMembershipCycleHistories",
|
||||
schema: "CMS",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ClubMembershipCycleId = table.Column<long>(type: "bigint", nullable: false),
|
||||
UserId = table.Column<long>(type: "bigint", nullable: false),
|
||||
CycleNumber = table.Column<int>(type: "int", nullable: false),
|
||||
OldIsCurrentCycle = table.Column<bool>(type: "bit", nullable: false),
|
||||
NewIsCurrentCycle = table.Column<bool>(type: "bit", nullable: false),
|
||||
OldMagicStartedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
NewMagicStartedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
OldMagicCompletedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
NewMagicCompletedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
Action = table.Column<int>(type: "int", nullable: false),
|
||||
PerformedBy = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true),
|
||||
Reason = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
|
||||
Created = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
CreatedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
LastModified = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
LastModifiedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
IsDeleted = table.Column<bool>(type: "bit", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ClubMembershipCycleHistories", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_ClubMembershipCycleHistories_ClubMembershipCycles_ClubMembershipCycleId",
|
||||
column: x => x.ClubMembershipCycleId,
|
||||
principalSchema: "CMS",
|
||||
principalTable: "ClubMembershipCycles",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "PackageHistories",
|
||||
schema: "CMS",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
PackageId = table.Column<long>(type: "bigint", nullable: false),
|
||||
OldPrice = table.Column<long>(type: "bigint", nullable: true),
|
||||
NewPrice = table.Column<long>(type: "bigint", nullable: true),
|
||||
OldActivationFee = table.Column<long>(type: "bigint", nullable: true),
|
||||
NewActivationFee = table.Column<long>(type: "bigint", nullable: true),
|
||||
OldMagicMultiplier = table.Column<decimal>(type: "decimal(18,4)", precision: 18, scale: 4, nullable: true),
|
||||
NewMagicMultiplier = table.Column<decimal>(type: "decimal(18,4)", precision: 18, scale: 4, nullable: true),
|
||||
OldMagicMaxDeposit = table.Column<long>(type: "bigint", nullable: true),
|
||||
NewMagicMaxDeposit = table.Column<long>(type: "bigint", nullable: true),
|
||||
OldMaxBalancesPerLeg = table.Column<int>(type: "int", nullable: true),
|
||||
NewMaxBalancesPerLeg = table.Column<int>(type: "int", nullable: true),
|
||||
OldIsActive = table.Column<bool>(type: "bit", nullable: true),
|
||||
NewIsActive = table.Column<bool>(type: "bit", nullable: true),
|
||||
Action = table.Column<int>(type: "int", nullable: false),
|
||||
PerformedBy = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true),
|
||||
Reason = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
|
||||
Created = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
CreatedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
LastModified = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
LastModifiedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
IsDeleted = table.Column<bool>(type: "bit", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_PackageHistories", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_PackageHistories_Packages_PackageId",
|
||||
column: x => x.PackageId,
|
||||
principalSchema: "CMS",
|
||||
principalTable: "Packages",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ClubMembershipCycleHistory_Action",
|
||||
schema: "CMS",
|
||||
table: "ClubMembershipCycleHistories",
|
||||
column: "Action");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ClubMembershipCycleHistory_CycleId",
|
||||
schema: "CMS",
|
||||
table: "ClubMembershipCycleHistories",
|
||||
column: "ClubMembershipCycleId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ClubMembershipCycleHistory_UserId_Created",
|
||||
schema: "CMS",
|
||||
table: "ClubMembershipCycleHistories",
|
||||
columns: new[] { "UserId", "Created" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PackageHistory_Action",
|
||||
schema: "CMS",
|
||||
table: "PackageHistories",
|
||||
column: "Action");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PackageHistory_PackageId_Created",
|
||||
schema: "CMS",
|
||||
table: "PackageHistories",
|
||||
columns: new[] { "PackageId", "Created" });
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "ClubMembershipCycleHistories",
|
||||
schema: "CMS");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "PackageHistories",
|
||||
schema: "CMS");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "UserWalletHistories",
|
||||
schema: "CMS",
|
||||
newName: "UserWalletChangeLogs",
|
||||
newSchema: "CMS");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_UserWalletHistories_PackageId",
|
||||
schema: "CMS",
|
||||
table: "UserWalletChangeLogs",
|
||||
newName: "IX_UserWalletChangeLogs_PackageId");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_UserWalletHistories_WalletId",
|
||||
schema: "CMS",
|
||||
table: "UserWalletChangeLogs",
|
||||
newName: "IX_UserWalletChangeLogs_WalletId");
|
||||
|
||||
migrationBuilder.Sql(
|
||||
"EXEC sp_rename N'CMS.PK_UserWalletHistories', N'PK_UserWalletChangeLogs', N'OBJECT'");
|
||||
|
||||
migrationBuilder.Sql(
|
||||
"EXEC sp_rename N'CMS.FK_UserWalletHistories_Packages_PackageId', N'FK_UserWalletChangeLogs_Packages_PackageId', N'OBJECT'");
|
||||
|
||||
migrationBuilder.Sql(
|
||||
"EXEC sp_rename N'CMS.FK_UserWalletHistories_UserWallets_WalletId', N'FK_UserWalletChangeLogs_UserWallets_WalletId', N'OBJECT'");
|
||||
}
|
||||
}
|
||||
}
|
||||
+195
-5
@@ -1935,6 +1935,81 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
|
||||
b.ToTable("States", "GMS");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CMSMicroservice.Domain.Entities.History.ClubMembershipCycleHistory", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<int>("Action")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<long>("ClubMembershipCycleId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<DateTime>("Created")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("CreatedBy")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("CycleNumber")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<DateTime?>("LastModified")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("LastModifiedBy")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<bool>("NewIsCurrentCycle")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<DateTime?>("NewMagicCompletedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime?>("NewMagicStartedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<bool>("OldIsCurrentCycle")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<DateTime?>("OldMagicCompletedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime?>("OldMagicStartedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("PerformedBy")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("nvarchar(100)");
|
||||
|
||||
b.Property<string>("Reason")
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("nvarchar(500)");
|
||||
|
||||
b.Property<long>("UserId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Action")
|
||||
.HasDatabaseName("IX_ClubMembershipCycleHistory_Action");
|
||||
|
||||
b.HasIndex("ClubMembershipCycleId")
|
||||
.HasDatabaseName("IX_ClubMembershipCycleHistory_CycleId");
|
||||
|
||||
b.HasIndex("UserId", "Created")
|
||||
.HasDatabaseName("IX_ClubMembershipCycleHistory_UserId_Created");
|
||||
|
||||
b.ToTable("ClubMembershipCycleHistories", "CMS");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CMSMicroservice.Domain.Entities.History.ClubMembershipHistory", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
@@ -2133,6 +2208,92 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
|
||||
b.ToTable("NetworkMembershipHistories", "CMS");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CMSMicroservice.Domain.Entities.History.PackageHistory", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<int>("Action")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("Created")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("CreatedBy")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<DateTime?>("LastModified")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("LastModifiedBy")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<long?>("NewActivationFee")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<bool?>("NewIsActive")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<long?>("NewMagicMaxDeposit")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<decimal?>("NewMagicMultiplier")
|
||||
.HasPrecision(18, 4)
|
||||
.HasColumnType("decimal(18,4)");
|
||||
|
||||
b.Property<int?>("NewMaxBalancesPerLeg")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<long?>("NewPrice")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<long?>("OldActivationFee")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<bool?>("OldIsActive")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<long?>("OldMagicMaxDeposit")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<decimal?>("OldMagicMultiplier")
|
||||
.HasPrecision(18, 4)
|
||||
.HasColumnType("decimal(18,4)");
|
||||
|
||||
b.Property<int?>("OldMaxBalancesPerLeg")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<long?>("OldPrice")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<long>("PackageId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("PerformedBy")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("nvarchar(100)");
|
||||
|
||||
b.Property<string>("Reason")
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("nvarchar(500)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Action")
|
||||
.HasDatabaseName("IX_PackageHistory_Action");
|
||||
|
||||
b.HasIndex("PackageId", "Created")
|
||||
.HasDatabaseName("IX_PackageHistory_PackageId_Created");
|
||||
|
||||
b.ToTable("PackageHistories", "CMS");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CMSMicroservice.Domain.Entities.InventoryItem", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
@@ -3826,7 +3987,7 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
|
||||
b.ToTable("UserWallets", "CMS");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CMSMicroservice.Domain.Entities.UserWalletChangeLog", b =>
|
||||
modelBuilder.Entity("CMSMicroservice.Domain.Entities.UserWalletHistory", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
@@ -3885,7 +4046,7 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
|
||||
|
||||
b.HasIndex("WalletId");
|
||||
|
||||
b.ToTable("UserWalletChangeLogs", "CMS");
|
||||
b.ToTable("UserWalletHistories", "CMS");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CMSMicroservice.Domain.Entities.Warehouse", b =>
|
||||
@@ -4430,6 +4591,17 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
|
||||
b.Navigation("Country");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CMSMicroservice.Domain.Entities.History.ClubMembershipCycleHistory", b =>
|
||||
{
|
||||
b.HasOne("CMSMicroservice.Domain.Entities.Club.ClubMembershipCycle", "ClubMembershipCycle")
|
||||
.WithMany("CycleHistories")
|
||||
.HasForeignKey("ClubMembershipCycleId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("ClubMembershipCycle");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CMSMicroservice.Domain.Entities.History.ClubMembershipHistory", b =>
|
||||
{
|
||||
b.HasOne("CMSMicroservice.Domain.Entities.Club.ClubMembership", "ClubMembership")
|
||||
@@ -4460,6 +4632,17 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
|
||||
b.Navigation("WeekDefinition");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CMSMicroservice.Domain.Entities.History.PackageHistory", b =>
|
||||
{
|
||||
b.HasOne("CMSMicroservice.Domain.Entities.Package", "Package")
|
||||
.WithMany("PackageHistories")
|
||||
.HasForeignKey("PackageId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Package");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CMSMicroservice.Domain.Entities.InventoryItem", b =>
|
||||
{
|
||||
b.HasOne("CMSMicroservice.Domain.Entities.DiscountShop.DiscountProduct", "DiscountProduct")
|
||||
@@ -4781,7 +4964,7 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CMSMicroservice.Domain.Entities.UserWalletChangeLog", b =>
|
||||
modelBuilder.Entity("CMSMicroservice.Domain.Entities.UserWalletHistory", b =>
|
||||
{
|
||||
b.HasOne("CMSMicroservice.Domain.Entities.Package", "Package")
|
||||
.WithMany()
|
||||
@@ -4789,7 +4972,7 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
b.HasOne("CMSMicroservice.Domain.Entities.UserWallet", "Wallet")
|
||||
.WithMany("UserWalletChangeLogs")
|
||||
.WithMany("UserWalletHistories")
|
||||
.HasForeignKey("WalletId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
@@ -4834,6 +5017,11 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
|
||||
b.Navigation("UserClubFeatures");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CMSMicroservice.Domain.Entities.Club.ClubMembershipCycle", b =>
|
||||
{
|
||||
b.Navigation("CycleHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CMSMicroservice.Domain.Entities.Commission.UserCommissionPayout", b =>
|
||||
{
|
||||
b.Navigation("CommissionPayoutHistories");
|
||||
@@ -4901,6 +5089,8 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
|
||||
{
|
||||
b.Navigation("PackageFeatures");
|
||||
|
||||
b.Navigation("PackageHistories");
|
||||
|
||||
b.Navigation("Purchases");
|
||||
|
||||
b.Navigation("UserOrders");
|
||||
@@ -4984,7 +5174,7 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
|
||||
|
||||
modelBuilder.Entity("CMSMicroservice.Domain.Entities.UserWallet", b =>
|
||||
{
|
||||
b.Navigation("UserWalletChangeLogs");
|
||||
b.Navigation("UserWalletHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CMSMicroservice.Domain.Entities.Warehouse", b =>
|
||||
|
||||
+5
-5
@@ -471,7 +471,7 @@ public class OrmCommissionCalculationStrategy : ICommissionCalculationStrategy
|
||||
.ToDictionaryAsync(w => w.UserId, cancellationToken);
|
||||
|
||||
var newWallets = new List<UserWallet>();
|
||||
var walletLogs = new List<UserWalletChangeLog>();
|
||||
var walletLogs = new List<UserWalletHistory>();
|
||||
|
||||
foreach (var payout in payouts)
|
||||
{
|
||||
@@ -510,7 +510,7 @@ public class OrmCommissionCalculationStrategy : ICommissionCalculationStrategy
|
||||
var wallet = existingWallets[payout.UserId];
|
||||
wallet.NetworkBalance += payout.TotalAmount;
|
||||
|
||||
var walletLog = new UserWalletChangeLog
|
||||
var walletLog = new UserWalletHistory
|
||||
{
|
||||
WalletId = wallet.Id,
|
||||
CurrentBalance = wallet.Balance,
|
||||
@@ -526,7 +526,7 @@ public class OrmCommissionCalculationStrategy : ICommissionCalculationStrategy
|
||||
walletLogs.Add(walletLog);
|
||||
}
|
||||
|
||||
await _context.UserWalletChangeLogs.AddRangeAsync(walletLogs, cancellationToken);
|
||||
await _context.UserWalletHistories.AddRangeAsync(walletLogs, cancellationToken);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
|
||||
@@ -534,7 +534,7 @@ public class OrmCommissionCalculationStrategy : ICommissionCalculationStrategy
|
||||
List<long> oldPayoutIds,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var oldWalletLogs = await _context.UserWalletChangeLogs
|
||||
var oldWalletLogs = await _context.UserWalletHistories
|
||||
.Where(l => l.RefrenceId.HasValue && oldPayoutIds.Contains(l.RefrenceId.Value))
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
@@ -557,7 +557,7 @@ public class OrmCommissionCalculationStrategy : ICommissionCalculationStrategy
|
||||
}
|
||||
}
|
||||
|
||||
_context.UserWalletChangeLogs.RemoveRange(oldWalletLogs);
|
||||
_context.UserWalletHistories.RemoveRange(oldWalletLogs);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user