From cfb293c135f9014051139895b6e7b6854f9ba8e5 Mon Sep 17 00:00:00 2001 From: "Amir.H Khademi" Date: Mon, 30 Sep 2024 22:09:39 +0330 Subject: [PATCH] fix calculate issue --- .version | 2 +- Netina.Api/Netina.Api.csproj | 4 ++-- .../WebFramework/Configurations/ServiceExtensions.cs | 2 +- .../CalculateProductDiscountCommandHandler.cs | 8 +++++++- Netina.Domain/Entities/Orders/Order.Aggregate.cs | 11 +++++++++-- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/.version b/.version index 74062c9..0de1add 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -1.5.17.23 \ No newline at end of file +1.5.17.26 \ No newline at end of file diff --git a/Netina.Api/Netina.Api.csproj b/Netina.Api/Netina.Api.csproj index 8eb30c9..f24c487 100644 --- a/Netina.Api/Netina.Api.csproj +++ b/Netina.Api/Netina.Api.csproj @@ -6,8 +6,8 @@ enable true Linux - 1.5.17.23 - 1.5.17.23 + 1.5.17.26 + 1.5.17.26 diff --git a/Netina.Api/WebFramework/Configurations/ServiceExtensions.cs b/Netina.Api/WebFramework/Configurations/ServiceExtensions.cs index eb04e9d..977c174 100644 --- a/Netina.Api/WebFramework/Configurations/ServiceExtensions.cs +++ b/Netina.Api/WebFramework/Configurations/ServiceExtensions.cs @@ -72,7 +72,7 @@ public static class ServiceExtensions serviceCollection.AddDbContextFactory(options => { options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking); - options.UseNpgsql(Configuration.GetConnectionString("PostgresServer"), b => b.MigrationsAssembly("Netina.Repository")) + options.UseNpgsql(Configuration.GetConnectionString("Postgres"), b => b.MigrationsAssembly("Netina.Repository")) .UseProjectAssembly(typeof(ApplicationUser).Assembly); //options.EnableServiceProviderCaching(true); diff --git a/Netina.Core/EntityServices/DiscountHandlers/CalculateProductDiscountCommandHandler.cs b/Netina.Core/EntityServices/DiscountHandlers/CalculateProductDiscountCommandHandler.cs index 1e51659..2620ad0 100644 --- a/Netina.Core/EntityServices/DiscountHandlers/CalculateProductDiscountCommandHandler.cs +++ b/Netina.Core/EntityServices/DiscountHandlers/CalculateProductDiscountCommandHandler.cs @@ -70,7 +70,7 @@ public class CalculateProductDiscountCommandHandler(IRepositoryWrapper repositor if (request.DiscountPercent == 0) { - request.CostWithDiscount = 0; + request.CostWithDiscount = request.Cost; request.HasDiscount = false; } @@ -131,6 +131,12 @@ public class CalculateProductDiscountCommandHandler(IRepositoryWrapper repositor request.CostWithDiscount = discountPrice; request.DiscountPercent = request.Cost == 0 ? 0 : 100 - 100 * request.CostWithDiscount / request.Cost; } + if (request.DiscountPercent == 0) + { + request.CostWithDiscount = request.Cost; + request.HasDiscount = false; + } + return request; } diff --git a/Netina.Domain/Entities/Orders/Order.Aggregate.cs b/Netina.Domain/Entities/Orders/Order.Aggregate.cs index 1d4355c..8a52de9 100644 --- a/Netina.Domain/Entities/Orders/Order.Aggregate.cs +++ b/Netina.Domain/Entities/Orders/Order.Aggregate.cs @@ -30,7 +30,7 @@ public partial class Order } else { - orderProduct.SetCount(count); + orderProduct.SetCount(count,cost,costWithDiscount,packingCost); } } public void RemoveFromOrderBag(Guid productId, int count) @@ -175,7 +175,14 @@ public partial class OrderProduct public void SetCount(int count) { Count = count; - var productCost = ProductFeeWithDiscount * Count; + } + public void SetCount(int count,double productFee,double costWithDiscount,double packingFee) + { + Count = count; + ProductFee = productFee; + PackingFee = packingFee; + ProductFeeWithDiscount = costWithDiscount; + ProductCost = ProductFeeWithDiscount * Count; } }