From cd48ae156f4bbce90a53bb2e53063824c1e2177d Mon Sep 17 00:00:00 2001 From: gdlcf88 Date: Sun, 12 Jun 2022 03:48:18 +0800 Subject: [PATCH] Fix InventoryActor --- .../Plugins/Inventories/DaprActors/InventoryActor.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/Inventories/DaprActors/src/EasyAbp.EShop.Plugins.Inventories.DaprActors/EasyAbp/EShop/Plugins/Inventories/DaprActors/InventoryActor.cs b/plugins/Inventories/DaprActors/src/EasyAbp.EShop.Plugins.Inventories.DaprActors/EasyAbp/EShop/Plugins/Inventories/DaprActors/InventoryActor.cs index eb8e7345..28457019 100644 --- a/plugins/Inventories/DaprActors/src/EasyAbp.EShop.Plugins.Inventories.DaprActors/EasyAbp/EShop/Plugins/Inventories/DaprActors/InventoryActor.cs +++ b/plugins/Inventories/DaprActors/src/EasyAbp.EShop.Plugins.Inventories.DaprActors/EasyAbp/EShop/Plugins/Inventories/DaprActors/InventoryActor.cs @@ -7,7 +7,7 @@ namespace EasyAbp.EShop.Plugins.Inventories.DaprActors; public class InventoryActor : Actor, IInventoryActor { public static string InventoryStateName { get; set; } = "i"; - + public InventoryActor(ActorHost host) : base(host) { } @@ -27,6 +27,8 @@ public class InventoryActor : Actor, IInventoryActor var state = await GetInventoryStateAsync(); InternalIncreaseInventory(state, quantity, decreaseSold); + + await SetInventoryStateAsync(state); } public async Task ReduceInventoryAsync(int quantity, bool increaseSold) @@ -34,6 +36,13 @@ public class InventoryActor : Actor, IInventoryActor var state = await GetInventoryStateAsync(); InternalReduceInventory(state, quantity, increaseSold); + + await SetInventoryStateAsync(state); + } + + protected virtual async Task SetInventoryStateAsync(InventoryStateModel state) + { + await StateManager.SetStateAsync(InventoryStateName, state); } protected virtual void InternalIncreaseInventory(InventoryStateModel stateModel, int quantity, bool decreaseSold)