This commit is contained in:
masoodafar-web
2025-11-25 01:58:45 +03:30
parent 02fc3f9122
commit 87842f0b9b
8 changed files with 4356 additions and 2191 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -34,6 +34,8 @@ public class
if (userWallet == null)
throw new Exception("کیف پول کاربر یافت نشد.");
if (userWallet.Balance<=0 || userWallet.Balance<request.TotalAmount)
throw new Exception("موجودی کیف پول کاربر برای انجام این تراکنش کافی نیست.");
var newTransaction = new Transactions()
{
@@ -71,24 +73,34 @@ public class
};
await _context.UserOrders.AddAsync(newOrder, cancellationToken);
await _context.SaveChangesAsync(cancellationToken);
await _context.FactorDetailss.AddRangeAsync(user.UserCartss.Select(s => new FactorDetails()
var factorDetailsList = user.UserCartss.Select(s => new FactorDetails()
{
ProductId = s.ProductId,
Count = s.Count,
UnitPrice = s.Product.Price,
OrderId = newOrder.Id
}), cancellationToken);
user.UserCartss.Clear();
await _context.SaveChangesAsync(cancellationToken);
return new SubmitShopBuyOrderResponseDto()
});
await _context.FactorDetailss.AddRangeAsync(factorDetailsList, cancellationToken);
var finalResult = new SubmitShopBuyOrderResponseDto()
{
Id = newOrder.Id,
PaymentMethod = newOrder.PaymentMethod,
PaymentStatus = newOrder.PaymentStatus,
TotalAmount = newOrder.Amount,
UserAddressText = user.UserAddresss.First(f => f.IsDefault).Address,
Created = newOrder.PaymentDate
Created = newOrder.PaymentDate,
FactorDetails = factorDetailsList.Select(s => new SubmitShopBuyOrderFactorDetail()
{
Count = s.Count,
UnitPrice = s.UnitPrice,
ProductId = s.ProductId,
ProductThumbnailPath = user.UserCartss.First(f => f.ProductId == s.ProductId).Product.ThumbnailPath,
ProductTitle = user.UserCartss.First(f => f.ProductId == s.ProductId).Product.Title,
UnitDiscountPrice = 0,
}).ToList()
};
user.UserCartss.Clear();
await _context.SaveChangesAsync(cancellationToken);
return finalResult;
}
}

View File

@@ -1,3 +1,5 @@
using CMSMicroservice.Domain.Enums;
namespace CMSMicroservice.Domain.Entities;
//آدرس کاربر
public class Transactions : BaseAuditableEntity

View File

@@ -1,3 +1,5 @@
using CMSMicroservice.Domain.Enums;
namespace CMSMicroservice.Domain.Entities;
//سفارش کاربر
public class UserOrder : BaseAuditableEntity

View File

@@ -19,7 +19,7 @@ public class UserOrderConfiguration : IEntityTypeConfiguration<UserOrder>
.IsRequired(false);
builder
.HasOne(entity => entity.Transaction)
.WithMany(entity => entity.TransactionUserOrders)
.WithMany(entity => entity.UserOrders)
.HasForeignKey(entity => entity.TransactionId)
.IsRequired(false);
builder.Property(entity => entity.PaymentStatus).IsRequired(true);
@@ -32,7 +32,7 @@ public class UserOrderConfiguration : IEntityTypeConfiguration<UserOrder>
builder
.HasOne(entity => entity.UserAddress)
.WithMany(entity => entity.UserOrders)
.HasForeignKey(entity => entity.UserAddressId)
.HasForeignKey(entity => entity.UserAddressId).OnDelete(DeleteBehavior.NoAction)
.IsRequired(true);
builder.Property(entity => entity.PaymentMethod).IsRequired(false);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,340 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace CMSMicroservice.Infrastructure.Persistence.Migrations
{
/// <inheritdoc />
public partial class u10 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Transactionss_UserOrders_OrderId",
schema: "CMS",
table: "Transactionss");
migrationBuilder.DropForeignKey(
name: "FK_UserOrders_Packages_PackageId",
schema: "CMS",
table: "UserOrders");
migrationBuilder.DropForeignKey(
name: "FK_UserOrders_UserAddresss_UserAddressId",
schema: "CMS",
table: "UserOrders");
migrationBuilder.DropIndex(
name: "IX_Transactionss_OrderId",
schema: "CMS",
table: "Transactionss");
migrationBuilder.DropColumn(
name: "Authority",
schema: "CMS",
table: "Transactionss");
migrationBuilder.DropColumn(
name: "CallbackUrl",
schema: "CMS",
table: "Transactionss");
migrationBuilder.DropColumn(
name: "CardHash",
schema: "CMS",
table: "Transactionss");
migrationBuilder.DropColumn(
name: "CardPan",
schema: "CMS",
table: "Transactionss");
migrationBuilder.DropColumn(
name: "Currency",
schema: "CMS",
table: "Transactionss");
migrationBuilder.DropColumn(
name: "Email",
schema: "CMS",
table: "Transactionss");
migrationBuilder.DropColumn(
name: "Fee",
schema: "CMS",
table: "Transactionss");
migrationBuilder.DropColumn(
name: "FeeType",
schema: "CMS",
table: "Transactionss");
migrationBuilder.DropColumn(
name: "MerchantId",
schema: "CMS",
table: "Transactionss");
migrationBuilder.DropColumn(
name: "Mobile",
schema: "CMS",
table: "Transactionss");
migrationBuilder.DropColumn(
name: "OrderId",
schema: "CMS",
table: "Transactionss");
migrationBuilder.DropColumn(
name: "RequestStatusCode",
schema: "CMS",
table: "Transactionss");
migrationBuilder.DropColumn(
name: "RequestStatusMessage",
schema: "CMS",
table: "Transactionss");
migrationBuilder.DropColumn(
name: "VerificationStatusCode",
schema: "CMS",
table: "Transactionss");
migrationBuilder.DropColumn(
name: "VerificationStatusMessage",
schema: "CMS",
table: "Transactionss");
migrationBuilder.RenameColumn(
name: "Price",
schema: "CMS",
table: "UserOrders",
newName: "Amount");
migrationBuilder.AlterColumn<long>(
name: "PackageId",
schema: "CMS",
table: "UserOrders",
type: "bigint",
nullable: true,
oldClrType: typeof(long),
oldType: "bigint");
migrationBuilder.CreateIndex(
name: "IX_UserOrders_TransactionId",
schema: "CMS",
table: "UserOrders",
column: "TransactionId");
migrationBuilder.AddForeignKey(
name: "FK_UserOrders_Packages_PackageId",
schema: "CMS",
table: "UserOrders",
column: "PackageId",
principalSchema: "CMS",
principalTable: "Packages",
principalColumn: "Id");
migrationBuilder.AddForeignKey(
name: "FK_UserOrders_Transactionss_TransactionId",
schema: "CMS",
table: "UserOrders",
column: "TransactionId",
principalSchema: "CMS",
principalTable: "Transactionss",
principalColumn: "Id");
migrationBuilder.AddForeignKey(
name: "FK_UserOrders_UserAddresss_UserAddressId",
schema: "CMS",
table: "UserOrders",
column: "UserAddressId",
principalSchema: "CMS",
principalTable: "UserAddresss",
principalColumn: "Id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_UserOrders_Packages_PackageId",
schema: "CMS",
table: "UserOrders");
migrationBuilder.DropForeignKey(
name: "FK_UserOrders_Transactionss_TransactionId",
schema: "CMS",
table: "UserOrders");
migrationBuilder.DropForeignKey(
name: "FK_UserOrders_UserAddresss_UserAddressId",
schema: "CMS",
table: "UserOrders");
migrationBuilder.DropIndex(
name: "IX_UserOrders_TransactionId",
schema: "CMS",
table: "UserOrders");
migrationBuilder.RenameColumn(
name: "Amount",
schema: "CMS",
table: "UserOrders",
newName: "Price");
migrationBuilder.AlterColumn<long>(
name: "PackageId",
schema: "CMS",
table: "UserOrders",
type: "bigint",
nullable: false,
defaultValue: 0L,
oldClrType: typeof(long),
oldType: "bigint",
oldNullable: true);
migrationBuilder.AddColumn<string>(
name: "Authority",
schema: "CMS",
table: "Transactionss",
type: "nvarchar(max)",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "CallbackUrl",
schema: "CMS",
table: "Transactionss",
type: "nvarchar(max)",
nullable: false,
defaultValue: "");
migrationBuilder.AddColumn<string>(
name: "CardHash",
schema: "CMS",
table: "Transactionss",
type: "nvarchar(max)",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "CardPan",
schema: "CMS",
table: "Transactionss",
type: "nvarchar(max)",
nullable: true);
migrationBuilder.AddColumn<int>(
name: "Currency",
schema: "CMS",
table: "Transactionss",
type: "int",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "Email",
schema: "CMS",
table: "Transactionss",
type: "nvarchar(max)",
nullable: true);
migrationBuilder.AddColumn<long>(
name: "Fee",
schema: "CMS",
table: "Transactionss",
type: "bigint",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "FeeType",
schema: "CMS",
table: "Transactionss",
type: "nvarchar(max)",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "MerchantId",
schema: "CMS",
table: "Transactionss",
type: "nvarchar(max)",
nullable: false,
defaultValue: "");
migrationBuilder.AddColumn<string>(
name: "Mobile",
schema: "CMS",
table: "Transactionss",
type: "nvarchar(max)",
nullable: true);
migrationBuilder.AddColumn<long>(
name: "OrderId",
schema: "CMS",
table: "Transactionss",
type: "bigint",
nullable: true);
migrationBuilder.AddColumn<int>(
name: "RequestStatusCode",
schema: "CMS",
table: "Transactionss",
type: "int",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "RequestStatusMessage",
schema: "CMS",
table: "Transactionss",
type: "nvarchar(max)",
nullable: true);
migrationBuilder.AddColumn<int>(
name: "VerificationStatusCode",
schema: "CMS",
table: "Transactionss",
type: "int",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "VerificationStatusMessage",
schema: "CMS",
table: "Transactionss",
type: "nvarchar(max)",
nullable: true);
migrationBuilder.CreateIndex(
name: "IX_Transactionss_OrderId",
schema: "CMS",
table: "Transactionss",
column: "OrderId");
migrationBuilder.AddForeignKey(
name: "FK_Transactionss_UserOrders_OrderId",
schema: "CMS",
table: "Transactionss",
column: "OrderId",
principalSchema: "CMS",
principalTable: "UserOrders",
principalColumn: "Id");
migrationBuilder.AddForeignKey(
name: "FK_UserOrders_Packages_PackageId",
schema: "CMS",
table: "UserOrders",
column: "PackageId",
principalSchema: "CMS",
principalTable: "Packages",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_UserOrders_UserAddresss_UserAddressId",
schema: "CMS",
table: "UserOrders",
column: "UserAddressId",
principalSchema: "CMS",
principalTable: "UserAddresss",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}
}
}

View File

@@ -580,41 +580,16 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
b.Property<long>("Amount")
.HasColumnType("bigint");
b.Property<string>("Authority")
.HasColumnType("nvarchar(max)");
b.Property<string>("CallbackUrl")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("CardHash")
.HasColumnType("nvarchar(max)");
b.Property<string>("CardPan")
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("Created")
.HasColumnType("datetime2");
b.Property<string>("CreatedBy")
.HasColumnType("nvarchar(max)");
b.Property<int?>("Currency")
.HasColumnType("int");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Email")
.HasColumnType("nvarchar(max)");
b.Property<long?>("Fee")
.HasColumnType("bigint");
b.Property<string>("FeeType")
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
@@ -624,16 +599,6 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
b.Property<string>("LastModifiedBy")
.HasColumnType("nvarchar(max)");
b.Property<string>("MerchantId")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Mobile")
.HasColumnType("nvarchar(max)");
b.Property<long?>("OrderId")
.HasColumnType("bigint");
b.Property<DateTime?>("PaymentDate")
.HasColumnType("datetime2");
@@ -643,25 +608,11 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
b.Property<string>("RefId")
.HasColumnType("nvarchar(max)");
b.Property<int?>("RequestStatusCode")
.HasColumnType("int");
b.Property<string>("RequestStatusMessage")
.HasColumnType("nvarchar(max)");
b.Property<int>("Type")
.HasColumnType("int");
b.Property<int?>("VerificationStatusCode")
.HasColumnType("int");
b.Property<string>("VerificationStatusMessage")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("OrderId");
b.ToTable("Transactionss", "CMS");
});
@@ -891,6 +842,9 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
b.Property<long>("Amount")
.HasColumnType("bigint");
b.Property<DateTime>("Created")
.HasColumnType("datetime2");
@@ -906,7 +860,7 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
b.Property<string>("LastModifiedBy")
.HasColumnType("nvarchar(max)");
b.Property<long>("PackageId")
b.Property<long?>("PackageId")
.HasColumnType("bigint");
b.Property<DateTime?>("PaymentDate")
@@ -918,9 +872,6 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
b.Property<int>("PaymentStatus")
.HasColumnType("int");
b.Property<long>("Price")
.HasColumnType("bigint");
b.Property<long?>("TransactionId")
.HasColumnType("bigint");
@@ -934,6 +885,8 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
b.HasIndex("PackageId");
b.HasIndex("TransactionId");
b.HasIndex("UserAddressId");
b.HasIndex("UserId");
@@ -1145,15 +1098,6 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
b.Navigation("Tag");
});
modelBuilder.Entity("CMSMicroservice.Domain.Entities.Transactions", b =>
{
b.HasOne("CMSMicroservice.Domain.Entities.UserOrder", "Order")
.WithMany("Transactionss")
.HasForeignKey("OrderId");
b.Navigation("Order");
});
modelBuilder.Entity("CMSMicroservice.Domain.Entities.User", b =>
{
b.HasOne("CMSMicroservice.Domain.Entities.User", "Parent")
@@ -1216,14 +1160,16 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
{
b.HasOne("CMSMicroservice.Domain.Entities.Package", "Package")
.WithMany("UserOrders")
.HasForeignKey("PackageId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.HasForeignKey("PackageId");
b.HasOne("CMSMicroservice.Domain.Entities.Transactions", "Transaction")
.WithMany("UserOrders")
.HasForeignKey("TransactionId");
b.HasOne("CMSMicroservice.Domain.Entities.UserAddress", "UserAddress")
.WithMany("UserOrders")
.HasForeignKey("UserAddressId")
.OnDelete(DeleteBehavior.Restrict)
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
b.HasOne("CMSMicroservice.Domain.Entities.User", "User")
@@ -1234,6 +1180,8 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
b.Navigation("Package");
b.Navigation("Transaction");
b.Navigation("User");
b.Navigation("UserAddress");
@@ -1325,6 +1273,11 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
b.Navigation("PruductTags");
});
modelBuilder.Entity("CMSMicroservice.Domain.Entities.Transactions", b =>
{
b.Navigation("UserOrders");
});
modelBuilder.Entity("CMSMicroservice.Domain.Entities.User", b =>
{
b.Navigation("UserAddresss");
@@ -1350,8 +1303,6 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
modelBuilder.Entity("CMSMicroservice.Domain.Entities.UserOrder", b =>
{
b.Navigation("FactorDetailss");
b.Navigation("Transactionss");
});
modelBuilder.Entity("CMSMicroservice.Domain.Entities.UserWallet", b =>