|
@@ -5,16 +5,19 @@ using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
+using XF.Domain.Dependency;
|
|
|
using XF.Domain.Repository.Events;
|
|
|
|
|
|
namespace Hotline.Orders.DatabaseEventHandler;
|
|
|
-public class OrderSnapshotEventHandler : IUpdateDatabaseEvent<OrderSnapshot>
|
|
|
+public class OrderSnapshotEventHandler : IUpdateDatabaseEvent<OrderSnapshot>, IScopeDependency
|
|
|
{
|
|
|
private readonly IIndustryLogRepository _industryLogRepository;
|
|
|
+ private readonly IOrderSnapshotRepository _orderSnapshotRepository;
|
|
|
|
|
|
- public OrderSnapshotEventHandler(IIndustryLogRepository industryLogRepository)
|
|
|
+ public OrderSnapshotEventHandler(IIndustryLogRepository industryLogRepository, IOrderSnapshotRepository orderSnapshotRepository)
|
|
|
{
|
|
|
_industryLogRepository = industryLogRepository;
|
|
|
+ _orderSnapshotRepository = orderSnapshotRepository;
|
|
|
}
|
|
|
|
|
|
public void OnInserted(OrderSnapshot entity)
|
|
@@ -25,17 +28,21 @@ public class OrderSnapshotEventHandler : IUpdateDatabaseEvent<OrderSnapshot>
|
|
|
{
|
|
|
}
|
|
|
|
|
|
- public void OnUpdating(object oldValue, string propertyName, OrderSnapshot entity)
|
|
|
+ public void OnUpdating(object propertyValue, string propertyName, OrderSnapshot entity)
|
|
|
{
|
|
|
- if (oldValue == null) return;
|
|
|
+ if (propertyValue == null) return;
|
|
|
if (propertyName != "IndustryName") return;
|
|
|
- if (oldValue is String industryName)
|
|
|
+ if (propertyValue is String industryName)
|
|
|
{
|
|
|
- if (industryName == entity.IndustryName) return;
|
|
|
+ var industry = _orderSnapshotRepository.Queryable()
|
|
|
+ .Where(m => m.Id == entity.Id)
|
|
|
+ .Select(m => m.IndustryName)
|
|
|
+ .First();
|
|
|
+ if (industryName == industry) return;
|
|
|
var entityLog = new IndustryLog
|
|
|
{
|
|
|
- IndustryName = oldValue.ToString(),
|
|
|
- OldIndustryName = industryName,
|
|
|
+ IndustryName = propertyValue.ToString(),
|
|
|
+ OldIndustryName = industry,
|
|
|
CreationTime = DateTime.Now,
|
|
|
OrderId = entity.Id,
|
|
|
};
|