Browse Source

Make aggregate roots multi-tenant.

pull/116/head
gdlcf88 5 years ago
parent
commit
0d6d343c2d
  1. 6
      modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain.Shared/EasyAbp/EShop/Orders/Orders/CompleteOrderEto.cs
  2. 11
      modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain.Shared/EasyAbp/EShop/Orders/Orders/OrderCanceledEto.cs
  3. 11
      modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain.Shared/EasyAbp/EShop/Orders/Orders/OrderCompletedEto.cs
  4. 13
      modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain.Shared/EasyAbp/EShop/Orders/Orders/OrderPaidEto.cs
  5. 12
      modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain.Shared/EasyAbp/EShop/Orders/Orders/OrderRefundedEto.cs
  6. 14
      modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderManager.cs
  7. 9
      modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/PaymentCompletedEventHandler.cs
  8. 6
      modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/RefundCompletedEventHandler.cs
  9. 11
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/Payments/EShopPaymentCanceledEto.cs
  10. 11
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/Payments/EShopPaymentCompletedEto.cs
  11. 12
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/Payments/PaymentSynchronizer.cs
  12. 3
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/Refunds/Refund.cs
  13. 6
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductInventories/ProductInventoryAppService.cs
  14. 22
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain.Shared/EasyAbp/EShop/Products/ProductInventories/ProductInventoryChangedEto.cs
  15. 5
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain.Shared/EasyAbp/EShop/Products/Products/ProductEto.cs
  16. 2
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain.Shared/EasyAbp/EShop/Products/Products/ProductSkuEto.cs
  17. 7
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/ProductDetailHistories/ProductDetailHistory.cs
  18. 6
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/ProductDetailHistories/ProductDetailHistoryRecorder.cs
  19. 7
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/ProductDetails/ProductDetail.cs
  20. 7
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/ProductHistories/ProductHistory.cs
  21. 8
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/ProductHistories/ProductHistoryRecorder.cs
  22. 7
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/ProductInventories/ProductInventory.cs
  23. 31
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/DefaultProductInventoryProvider.cs
  24. 7
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/Product.cs
  25. 7
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/ProductView.cs
  26. 2
      modules/EasyAbp.EShop.Products/test/EasyAbp.EShop.Products.TestBase/ProductsTestDataBuilder.cs
  27. 2
      modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/StoreOwners/StoreOwner.cs
  28. 2
      plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Domain/EasyAbp/EShop/Plugins/Baskets/BasketItems/BasketItem.cs
  29. 5
      plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Domain/EasyAbp/EShop/Plugins/Baskets/BasketItems/ProductUpdateRecorder.cs
  30. 6
      plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Domain/EasyAbp/EShop/Plugins/Baskets/ProductUpdates/ProductUpdate.cs
  31. 5102
      samples/EShopSample/aspnet-core/src/EShopSample.EntityFrameworkCore.DbMigrations/Migrations/20210118120852_MadeAggregateRootsMultiTenant.Designer.cs
  32. 84
      samples/EShopSample/aspnet-core/src/EShopSample.EntityFrameworkCore.DbMigrations/Migrations/20210118120852_MadeAggregateRootsMultiTenant.cs
  33. 31
      samples/EShopSample/aspnet-core/src/EShopSample.EntityFrameworkCore.DbMigrations/Migrations/EShopSampleMigrationsDbContextModelSnapshot.cs

6
modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain.Shared/EasyAbp/EShop/Orders/Orders/CompleteOrderEto.cs

@ -9,5 +9,11 @@ namespace EasyAbp.EShop.Orders.Orders
public Guid? TenantId { get; set; }
public Guid OrderId { get; set; }
public CompleteOrderEto(Guid? tenantId, Guid orderId)
{
TenantId = tenantId;
OrderId = orderId;
}
}
}

11
modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain.Shared/EasyAbp/EShop/Orders/Orders/OrderCanceledEto.cs

@ -1,10 +1,19 @@
using System;
using Volo.Abp.MultiTenancy;
namespace EasyAbp.EShop.Orders.Orders
{
[Serializable]
public class OrderCanceledEto
public class OrderCanceledEto : IMultiTenant
{
public Guid? TenantId { get; set; }
public OrderEto Order { get; set; }
public OrderCanceledEto(OrderEto order)
{
TenantId = order.TenantId;
Order = order;
}
}
}

11
modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain.Shared/EasyAbp/EShop/Orders/Orders/OrderCompletedEto.cs

@ -1,10 +1,19 @@
using System;
using Volo.Abp.MultiTenancy;
namespace EasyAbp.EShop.Orders.Orders
{
[Serializable]
public class OrderCompletedEto
public class OrderCompletedEto : IMultiTenant
{
public Guid? TenantId { get; set; }
public OrderEto Order { get; set; }
public OrderCompletedEto(OrderEto order)
{
TenantId = order.TenantId;
Order = order;
}
}
}

13
modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain.Shared/EasyAbp/EShop/Orders/Orders/OrderPaidEto.cs

@ -1,14 +1,25 @@
using System;
using Volo.Abp.MultiTenancy;
namespace EasyAbp.EShop.Orders.Orders
{
[Serializable]
public class OrderPaidEto
public class OrderPaidEto : IMultiTenant
{
public Guid? TenantId { get; set; }
public OrderEto Order { get; set; }
public Guid PaymentId { get; set; }
public Guid PaymentItemId { get; set; }
public OrderPaidEto(OrderEto order, Guid paymentId, Guid paymentItemId)
{
TenantId = order.TenantId;
Order = order;
PaymentId = paymentId;
PaymentItemId = paymentItemId;
}
}
}

12
modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain.Shared/EasyAbp/EShop/Orders/Orders/OrderRefundedEto.cs

@ -1,13 +1,23 @@
using System;
using EasyAbp.EShop.Payments.Refunds;
using Volo.Abp.MultiTenancy;
namespace EasyAbp.EShop.Orders.Orders
{
[Serializable]
public class OrderRefundedEto
public class OrderRefundedEto : IMultiTenant
{
public Guid? TenantId { get; set; }
public OrderEto Order { get; set; }
public EShopRefundEto Refund { get; set; }
public OrderRefundedEto(OrderEto order, EShopRefundEto refund)
{
TenantId = order.TenantId;
Order = order;
Refund = refund;
}
}
}

14
modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderManager.cs

@ -49,10 +49,9 @@ namespace EasyAbp.EShop.Orders.Orders
order.SetCompletionTime(_clock.Now);
order.SetOrderStatus(OrderStatus.Completed);
uow.OnCompleted(async () => await _distributedEventBus.PublishAsync(new OrderCompletedEto
{
Order = _objectMapper.Map<Order, OrderEto>(order)
}));
uow.OnCompleted(async () =>
await _distributedEventBus.PublishAsync(
new OrderCompletedEto(_objectMapper.Map<Order, OrderEto>(order))));
await _orderRepository.UpdateAsync(order, true);
@ -78,10 +77,9 @@ namespace EasyAbp.EShop.Orders.Orders
order.SetCanceled(_clock.Now, cancellationReason);
order.SetOrderStatus(OrderStatus.Canceled);
uow.OnCompleted(async () => await _distributedEventBus.PublishAsync(new OrderCanceledEto
{
Order = _objectMapper.Map<Order, OrderEto>(order)
}));
uow.OnCompleted(async () =>
await _distributedEventBus.PublishAsync(
new OrderCanceledEto(_objectMapper.Map<Order, OrderEto>(order))));
await _orderRepository.UpdateAsync(order, true);

9
modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/PaymentCompletedEventHandler.cs

@ -75,12 +75,9 @@ namespace EasyAbp.EShop.Orders.Orders
await _orderRepository.UpdateAsync(order, true);
uow.OnCompleted(async () => await _distributedEventBus.PublishAsync(new OrderPaidEto
{
Order = _objectMapper.Map<Order, OrderEto>(order),
PaymentId = payment.Id,
PaymentItemId = item.Id
}));
uow.OnCompleted(async () =>
await _distributedEventBus.PublishAsync(new OrderPaidEto(_objectMapper.Map<Order, OrderEto>(order),
payment.Id, item.Id)));
}
await uow.CompleteAsync();

6
modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/RefundCompletedEventHandler.cs

@ -49,11 +49,7 @@ namespace EasyAbp.EShop.Orders.Orders
await _orderRepository.UpdateAsync(order, true);
uow.OnCompleted(async () => await _distributedEventBus.PublishAsync(
new OrderRefundedEto
{
Order = _objectMapper.Map<Order, OrderEto>(order),
Refund = eventData.Refund
})
new OrderRefundedEto(_objectMapper.Map<Order, OrderEto>(order), eventData.Refund))
);
await uow.CompleteAsync();

11
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/Payments/EShopPaymentCanceledEto.cs

@ -1,10 +1,19 @@
using System;
using Volo.Abp.MultiTenancy;
namespace EasyAbp.EShop.Payments.Payments
{
[Serializable]
public class EShopPaymentCanceledEto
public class EShopPaymentCanceledEto : IMultiTenant
{
public Guid? TenantId { get; set; }
public EShopPaymentEto Payment { get; set; }
public EShopPaymentCanceledEto(EShopPaymentEto payment)
{
TenantId = payment.TenantId;
Payment = payment;
}
}
}

11
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/Payments/EShopPaymentCompletedEto.cs

@ -1,10 +1,19 @@
using System;
using Volo.Abp.MultiTenancy;
namespace EasyAbp.EShop.Payments.Payments
{
[Serializable]
public class EShopPaymentCompletedEto
public class EShopPaymentCompletedEto : IMultiTenant
{
public Guid? TenantId { get; set; }
public EShopPaymentEto Payment { get; set; }
public EShopPaymentCompletedEto(EShopPaymentEto payment)
{
TenantId = payment.TenantId;
Payment = payment;
}
}
}

12
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/Payments/PaymentSynchronizer.cs

@ -84,10 +84,8 @@ namespace EasyAbp.EShop.Payments.Payments
{
uow.OnCompleted(async () =>
{
await _distributedEventBus.PublishAsync(new EShopPaymentCanceledEto
{
Payment = _objectMapper.Map<Payment, EShopPaymentEto>(payment)
});
await _distributedEventBus.PublishAsync(
new EShopPaymentCanceledEto(_objectMapper.Map<Payment, EShopPaymentEto>(payment)));
});
}
@ -95,10 +93,8 @@ namespace EasyAbp.EShop.Payments.Payments
{
uow.OnCompleted(async () =>
{
await _distributedEventBus.PublishAsync(new EShopPaymentCompletedEto
{
Payment = _objectMapper.Map<Payment, EShopPaymentEto>(payment)
});
await _distributedEventBus.PublishAsync(
new EShopPaymentCompletedEto(_objectMapper.Map<Payment, EShopPaymentEto>(payment)));
});
}

3
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/Refunds/Refund.cs

@ -3,10 +3,11 @@ using System.Collections.Generic;
using EasyAbp.PaymentService.Refunds;
using JetBrains.Annotations;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy;
namespace EasyAbp.EShop.Payments.Refunds
{
public class Refund : FullAuditedAggregateRoot<Guid>, IRefund
public class Refund : FullAuditedAggregateRoot<Guid>, IRefund, IMultiTenant
{
#region Base properties

6
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductInventories/ProductInventoryAppService.cs

@ -32,7 +32,8 @@ namespace EasyAbp.EShop.Products.ProductInventories
if (productInventory == null)
{
productInventory = new ProductInventory(GuidGenerator.Create(), productId, productSkuId, 0, 0);
productInventory = new ProductInventory(GuidGenerator.Create(), CurrentTenant.Id, productId,
productSkuId, 0, 0);
await _repository.InsertAsync(productInventory, true);
}
@ -52,7 +53,8 @@ namespace EasyAbp.EShop.Products.ProductInventories
if (productInventory == null)
{
productInventory =
new ProductInventory(GuidGenerator.Create(), input.ProductId, input.ProductSkuId, 0, 0);
new ProductInventory(GuidGenerator.Create(), CurrentTenant.Id, input.ProductId, input.ProductSkuId,
0, 0);
await _repository.InsertAsync(productInventory, true);
}

22
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain.Shared/EasyAbp/EShop/Products/ProductInventories/ProductInventoryChangedEto.cs

@ -4,8 +4,10 @@ using Volo.Abp.MultiTenancy;
namespace EasyAbp.EShop.Products.ProductInventories
{
[Serializable]
public class ProductInventoryChangedEto
public class ProductInventoryChangedEto : IMultiTenant
{
public Guid? TenantId { get; set; }
public Guid StoreId { get; set; }
public Guid ProductId { get; set; }
@ -17,5 +19,23 @@ namespace EasyAbp.EShop.Products.ProductInventories
public int NewInventory { get; set; }
public long Sold { get; set; }
public ProductInventoryChangedEto(
Guid? tenantId,
Guid storeId,
Guid productId,
Guid productSkuId,
int originalInventory,
int newInventory,
long sold)
{
TenantId = tenantId;
StoreId = storeId;
ProductId = productId;
ProductSkuId = productSkuId;
OriginalInventory = originalInventory;
NewInventory = newInventory;
Sold = sold;
}
}
}

5
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain.Shared/EasyAbp/EShop/Products/Products/ProductEto.cs

@ -1,12 +1,15 @@
using System;
using System.Collections.Generic;
using Volo.Abp.Data;
using Volo.Abp.MultiTenancy;
namespace EasyAbp.EShop.Products.Products
{
[Serializable]
public class ProductEto : IProduct
public class ProductEto : IProduct, IMultiTenant
{
public Guid? TenantId { get; set; }
public Guid Id { get; set; }
public Guid StoreId { get; set; }

2
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain.Shared/EasyAbp/EShop/Products/Products/ProductSkuEto.cs

@ -4,7 +4,7 @@ using Volo.Abp.Data;
namespace EasyAbp.EShop.Products.Products
{
[Serializable]
public class ProductSkuEto : IProductSku
public class ProductSkuEto : IProductSku
{
public Guid Id { get; set; }

7
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/ProductDetailHistories/ProductDetailHistory.cs

@ -1,11 +1,14 @@
using System;
using JetBrains.Annotations;
using Volo.Abp.Domain.Entities;
using Volo.Abp.MultiTenancy;
namespace EasyAbp.EShop.Products.ProductDetailHistories
{
public class ProductDetailHistory : AggregateRoot<Guid>
public class ProductDetailHistory : AggregateRoot<Guid>, IMultiTenant
{
public virtual Guid? TenantId { get; protected set; }
public virtual Guid ProductDetailId { get; protected set; }
public virtual DateTime ModificationTime { get; protected set; }
@ -17,10 +20,12 @@ namespace EasyAbp.EShop.Products.ProductDetailHistories
public ProductDetailHistory(
Guid id,
Guid? tenantId,
Guid productDetailId,
DateTime modificationTime,
[NotNull] string serializedEntityData) : base(id)
{
TenantId = tenantId;
ProductDetailId = productDetailId;
ModificationTime = modificationTime;
SerializedEntityData = serializedEntityData;

6
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/ProductDetailHistories/ProductDetailHistoryRecorder.cs

@ -4,6 +4,7 @@ using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities.Events;
using Volo.Abp.Guids;
using Volo.Abp.Json;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Uow;
namespace EasyAbp.EShop.Products.ProductDetailHistories
@ -11,15 +12,18 @@ namespace EasyAbp.EShop.Products.ProductDetailHistories
public class ProductDetailHistoryRecorder : IProductDetailHistoryRecorder, ITransientDependency
{
private readonly IGuidGenerator _guidGenerator;
private readonly ICurrentTenant _currentTenant;
private readonly IJsonSerializer _jsonSerializer;
private readonly IProductDetailHistoryRepository _productDetailHistoryRepository;
public ProductDetailHistoryRecorder(
IGuidGenerator guidGenerator,
ICurrentTenant currentTenant,
IJsonSerializer jsonSerializer,
IProductDetailHistoryRepository productDetailHistoryRepository)
{
_guidGenerator = guidGenerator;
_currentTenant = currentTenant;
_jsonSerializer = jsonSerializer;
_productDetailHistoryRepository = productDetailHistoryRepository;
}
@ -32,7 +36,7 @@ namespace EasyAbp.EShop.Products.ProductDetailHistories
var serializeEntityData = _jsonSerializer.Serialize(eventData.Entity);
await _productDetailHistoryRepository.InsertAsync(new ProductDetailHistory(_guidGenerator.Create(),
eventData.Entity.Id, modificationTime, serializeEntityData));
_currentTenant.Id, eventData.Entity.Id, modificationTime, serializeEntityData));
}
}
}

7
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/ProductDetails/ProductDetail.cs

@ -1,11 +1,14 @@
using System;
using JetBrains.Annotations;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy;
namespace EasyAbp.EShop.Products.ProductDetails
{
public class ProductDetail : FullAuditedAggregateRoot<Guid>
public class ProductDetail : FullAuditedAggregateRoot<Guid>, IMultiTenant
{
public virtual Guid? TenantId { get; protected set; }
public virtual Guid? StoreId { get; protected set; }
[CanBeNull]
@ -15,9 +18,11 @@ namespace EasyAbp.EShop.Products.ProductDetails
public ProductDetail(
Guid id,
Guid? tenantId,
Guid? storeId,
[CanBeNull] string description) : base(id)
{
TenantId = tenantId;
StoreId = storeId;
Description = description;
}

7
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/ProductHistories/ProductHistory.cs

@ -1,11 +1,14 @@
using System;
using JetBrains.Annotations;
using Volo.Abp.Domain.Entities;
using Volo.Abp.MultiTenancy;
namespace EasyAbp.EShop.Products.ProductHistories
{
public class ProductHistory : AggregateRoot<Guid>
public class ProductHistory : AggregateRoot<Guid>, IMultiTenant
{
public virtual Guid? TenantId { get; protected set; }
public virtual Guid ProductId { get; protected set; }
public virtual DateTime ModificationTime { get; protected set; }
@ -17,10 +20,12 @@ namespace EasyAbp.EShop.Products.ProductHistories
public ProductHistory(
Guid id,
Guid? tenantId,
Guid productId,
DateTime modificationTime,
[NotNull] string serializedEntityData) : base(id)
{
TenantId = tenantId;
ProductId = productId;
ModificationTime = modificationTime;
SerializedEntityData = serializedEntityData;

8
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/ProductHistories/ProductHistoryRecorder.cs

@ -5,6 +5,7 @@ using Volo.Abp.Domain.Entities.Events;
using Volo.Abp.EventBus;
using Volo.Abp.Guids;
using Volo.Abp.Json;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Uow;
namespace EasyAbp.EShop.Products.ProductHistories
@ -15,15 +16,18 @@ namespace EasyAbp.EShop.Products.ProductHistories
ITransientDependency
{
private readonly IGuidGenerator _guidGenerator;
private readonly ICurrentTenant _currentTenant;
private readonly IJsonSerializer _jsonSerializer;
private readonly IProductHistoryRepository _productHistoryRepository;
public ProductHistoryRecorder(
IGuidGenerator guidGenerator,
ICurrentTenant currentTenant,
IJsonSerializer jsonSerializer,
IProductHistoryRepository productHistoryRepository)
{
_guidGenerator = guidGenerator;
_currentTenant = currentTenant;
_jsonSerializer = jsonSerializer;
_productHistoryRepository = productHistoryRepository;
}
@ -35,8 +39,8 @@ namespace EasyAbp.EShop.Products.ProductHistories
var serializedEntityData = _jsonSerializer.Serialize(eventData.Entity);
await _productHistoryRepository.InsertAsync(new ProductHistory(_guidGenerator.Create(), eventData.Entity.Id,
modificationTime, serializedEntityData));
await _productHistoryRepository.InsertAsync(new ProductHistory(_guidGenerator.Create(), _currentTenant.Id,
eventData.Entity.Id, modificationTime, serializedEntityData));
}
}
}

7
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/ProductInventories/ProductInventory.cs

@ -1,10 +1,13 @@
using System;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy;
namespace EasyAbp.EShop.Products.ProductInventories
{
public class ProductInventory : FullAuditedAggregateRoot<Guid>
public class ProductInventory : FullAuditedAggregateRoot<Guid>, IMultiTenant
{
public virtual Guid? TenantId { get; protected set; }
public virtual Guid ProductId { get; protected set; }
public virtual Guid ProductSkuId { get; protected set; }
@ -19,11 +22,13 @@ namespace EasyAbp.EShop.Products.ProductInventories
public ProductInventory(
Guid id,
Guid? tenantId,
Guid productId,
Guid productSkuId,
int inventory,
long sold) : base(id)
{
TenantId = tenantId;
ProductId = productId;
ProductSkuId = productSkuId;
Inventory = inventory;

31
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/DefaultProductInventoryProvider.cs

@ -76,8 +76,9 @@ namespace EasyAbp.EShop.Products.Products
await _productInventoryRepository.UpdateAsync(productInventory, true);
PublishInventoryChangedEventOnUowCompleted(uow, product.StoreId, productInventory.ProductId,
productInventory.ProductSkuId, originalInventory, productInventory.Inventory, productInventory.Sold);
PublishInventoryChangedEventOnUowCompleted(uow, product.TenantId, product.StoreId,
productInventory.ProductId, productInventory.ProductSkuId, originalInventory,
productInventory.Inventory, productInventory.Sold);
await uow.CompleteAsync();
@ -102,26 +103,26 @@ namespace EasyAbp.EShop.Products.Products
await _productInventoryRepository.UpdateAsync(productInventory, true);
PublishInventoryChangedEventOnUowCompleted(uow, product.StoreId, productInventory.ProductId,
productInventory.ProductSkuId, originalInventory, productInventory.Inventory, productInventory.Sold);
PublishInventoryChangedEventOnUowCompleted(uow, product.TenantId, product.StoreId,
productInventory.ProductId, productInventory.ProductSkuId, originalInventory,
productInventory.Inventory, productInventory.Sold);
await uow.CompleteAsync();
return true;
}
protected virtual void PublishInventoryChangedEventOnUowCompleted(IUnitOfWork uow, Guid storeId, Guid productId,
Guid productSkuId, int originalInventory, int newInventory, long sold)
protected virtual void PublishInventoryChangedEventOnUowCompleted(IUnitOfWork uow, Guid? tenantId, Guid storeId,
Guid productId, Guid productSkuId, int originalInventory, int newInventory, long sold)
{
uow.OnCompleted(async () => await _distributedEventBus.PublishAsync(new ProductInventoryChangedEto
{
StoreId = storeId,
ProductId = productId,
ProductSkuId = productSkuId,
OriginalInventory = originalInventory,
NewInventory = newInventory,
Sold = sold
}));
uow.OnCompleted(async () => await _distributedEventBus.PublishAsync(new ProductInventoryChangedEto(
tenantId,
storeId,
productId,
productSkuId,
originalInventory,
newInventory,
sold)));
}
}
}

7
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/Product.cs

@ -2,11 +2,14 @@ using JetBrains.Annotations;
using System;
using System.Collections.Generic;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy;
namespace EasyAbp.EShop.Products.Products
{
public class Product : FullAuditedAggregateRoot<Guid>, IProduct
public class Product : FullAuditedAggregateRoot<Guid>, IProduct, IMultiTenant
{
public virtual Guid? TenantId { get; protected set; }
public virtual Guid StoreId { get; protected set; }
[NotNull]
@ -43,6 +46,7 @@ namespace EasyAbp.EShop.Products.Products
public Product(
Guid id,
Guid? tenantId,
Guid storeId,
[NotNull] string productGroupName,
Guid productDetailId,
@ -56,6 +60,7 @@ namespace EasyAbp.EShop.Products.Products
int displayOrder
) : base(id)
{
TenantId = tenantId;
StoreId = storeId;
ProductGroupName = productGroupName;
ProductDetailId = productDetailId;

7
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Domain/EasyAbp/EShop/Products/Products/ProductView.cs

@ -1,10 +1,13 @@
using System;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy;
namespace EasyAbp.EShop.Products.Products
{
public class ProductView : CreationAuditedAggregateRoot<Guid>, IProduct
public class ProductView : CreationAuditedAggregateRoot<Guid>, IProduct, IMultiTenant
{
public virtual Guid? TenantId { get; protected set; }
#region Properties of IProduct
public virtual Guid StoreId { get; protected set; }
@ -45,6 +48,7 @@ namespace EasyAbp.EShop.Products.Products
public ProductView(
Guid id,
Guid? tenantId,
Guid storeId,
string productGroupName,
Guid productDetailId,
@ -62,6 +66,7 @@ namespace EasyAbp.EShop.Products.Products
long sold
) : base(id)
{
TenantId = tenantId;
StoreId = storeId;
ProductGroupName = productGroupName;
ProductDetailId = productDetailId;

2
modules/EasyAbp.EShop.Products/test/EasyAbp.EShop.Products.TestBase/ProductsTestDataBuilder.cs

@ -21,7 +21,7 @@ namespace EasyAbp.EShop.Products
public async Task BuildAsync()
{
await _productDetailRepository.InsertAsync(new ProductDetail(ProductsTestData.ProductDetails1Id,
await _productDetailRepository.InsertAsync(new ProductDetail(ProductsTestData.ProductDetails1Id, null,
ProductsTestData.Store1Id, "Product details for store 1"));
}
}

2
modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/StoreOwners/StoreOwner.cs

@ -5,7 +5,7 @@ using Volo.Abp.MultiTenancy;
namespace EasyAbp.EShop.Stores.StoreOwners
{
public class StoreOwner : AuditedAggregateRoot<Guid>, IMultiTenant, IMultiStore
public class StoreOwner : AuditedAggregateRoot<Guid>, IMultiStore, IMultiTenant
{
public virtual Guid? TenantId { get; protected set; }

2
plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Domain/EasyAbp/EShop/Plugins/Baskets/BasketItems/BasketItem.cs

@ -5,7 +5,7 @@ using Volo.Abp.MultiTenancy;
namespace EasyAbp.EShop.Plugins.Baskets.BasketItems
{
public class BasketItem : AuditedAggregateRoot<Guid>, IMultiTenant, IProductData
public class BasketItem : AuditedAggregateRoot<Guid>, IProductData, IMultiTenant
{
public virtual Guid? TenantId { get; protected set; }

5
plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Domain/EasyAbp/EShop/Plugins/Baskets/BasketItems/ProductUpdateRecorder.cs

@ -15,13 +15,16 @@ namespace EasyAbp.EShop.Plugins.Baskets.BasketItems
public class ProductUpdateRecorder : IProductUpdateRecorder, ITransientDependency
{
private readonly IGuidGenerator _guidGenerator;
private readonly ICurrentTenant _currentTenant;
private readonly IProductUpdateRepository _productUpdateRepository;
public ProductUpdateRecorder(
IGuidGenerator guidGenerator,
ICurrentTenant currentTenant,
IProductUpdateRepository productUpdateRepository)
{
_guidGenerator = guidGenerator;
_currentTenant = currentTenant;
_productUpdateRepository = productUpdateRepository;
}
@ -46,7 +49,7 @@ namespace EasyAbp.EShop.Plugins.Baskets.BasketItems
if (entity == null)
{
entity = new ProductUpdate(_guidGenerator.Create(), skuId);
entity = new ProductUpdate(_guidGenerator.Create(), _currentTenant.Id, skuId);
await _productUpdateRepository.InsertAsync(entity);
}

6
plugins/Baskets/src/EasyAbp.EShop.Plugins.Baskets.Domain/EasyAbp/EShop/Plugins/Baskets/ProductUpdates/ProductUpdate.cs

@ -4,8 +4,10 @@ using Volo.Abp.MultiTenancy;
namespace EasyAbp.EShop.Plugins.Baskets.ProductUpdates
{
public class ProductUpdate : FullAuditedAggregateRoot<Guid>
public class ProductUpdate : FullAuditedAggregateRoot<Guid>, IMultiTenant
{
public virtual Guid? TenantId { get; protected set; }
public virtual Guid ProductSkuId { get; protected set; }
protected ProductUpdate()
@ -14,8 +16,10 @@ namespace EasyAbp.EShop.Plugins.Baskets.ProductUpdates
public ProductUpdate(
Guid id,
Guid? tenantId,
Guid productSkuId) : base(id)
{
TenantId = tenantId;
ProductSkuId = productSkuId;
}
}

5102
samples/EShopSample/aspnet-core/src/EShopSample.EntityFrameworkCore.DbMigrations/Migrations/20210118120852_MadeAggregateRootsMultiTenant.Designer.cs

File diff suppressed because it is too large

84
samples/EShopSample/aspnet-core/src/EShopSample.EntityFrameworkCore.DbMigrations/Migrations/20210118120852_MadeAggregateRootsMultiTenant.cs

@ -0,0 +1,84 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace EShopSample.Migrations
{
public partial class MadeAggregateRootsMultiTenant : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "TenantId",
table: "EasyAbpEShopProductsProductViews",
type: "uniqueidentifier",
nullable: true);
migrationBuilder.AddColumn<Guid>(
name: "TenantId",
table: "EasyAbpEShopProductsProducts",
type: "uniqueidentifier",
nullable: true);
migrationBuilder.AddColumn<Guid>(
name: "TenantId",
table: "EasyAbpEShopProductsProductInventories",
type: "uniqueidentifier",
nullable: true);
migrationBuilder.AddColumn<Guid>(
name: "TenantId",
table: "EasyAbpEShopProductsProductHistories",
type: "uniqueidentifier",
nullable: true);
migrationBuilder.AddColumn<Guid>(
name: "TenantId",
table: "EasyAbpEShopProductsProductDetails",
type: "uniqueidentifier",
nullable: true);
migrationBuilder.AddColumn<Guid>(
name: "TenantId",
table: "EasyAbpEShopProductsProductDetailHistories",
type: "uniqueidentifier",
nullable: true);
migrationBuilder.AddColumn<Guid>(
name: "TenantId",
table: "EasyAbpEShopPluginsBasketsProductUpdates",
type: "uniqueidentifier",
nullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "TenantId",
table: "EasyAbpEShopProductsProductViews");
migrationBuilder.DropColumn(
name: "TenantId",
table: "EasyAbpEShopProductsProducts");
migrationBuilder.DropColumn(
name: "TenantId",
table: "EasyAbpEShopProductsProductInventories");
migrationBuilder.DropColumn(
name: "TenantId",
table: "EasyAbpEShopProductsProductHistories");
migrationBuilder.DropColumn(
name: "TenantId",
table: "EasyAbpEShopProductsProductDetails");
migrationBuilder.DropColumn(
name: "TenantId",
table: "EasyAbpEShopProductsProductDetailHistories");
migrationBuilder.DropColumn(
name: "TenantId",
table: "EasyAbpEShopPluginsBasketsProductUpdates");
}
}
}

31
samples/EShopSample/aspnet-core/src/EShopSample.EntityFrameworkCore.DbMigrations/Migrations/EShopSampleMigrationsDbContextModelSnapshot.cs

@ -505,7 +505,8 @@ namespace EShopSample.Migrations
.HasColumnType("nvarchar(max)");
b.Property<Guid?>("TenantId")
.HasColumnType("uniqueidentifier");
.HasColumnType("uniqueidentifier")
.HasColumnName("TenantId");
b.HasKey("Id");
@ -748,6 +749,10 @@ namespace EShopSample.Migrations
b.Property<Guid>("ProductSkuId")
.HasColumnType("uniqueidentifier");
b.Property<Guid?>("TenantId")
.HasColumnType("uniqueidentifier")
.HasColumnName("TenantId");
b.HasKey("Id");
b.HasIndex("ProductSkuId");
@ -1140,6 +1145,10 @@ namespace EShopSample.Migrations
b.Property<string>("SerializedEntityData")
.HasColumnType("nvarchar(max)");
b.Property<Guid?>("TenantId")
.HasColumnType("uniqueidentifier")
.HasColumnName("TenantId");
b.HasKey("Id");
b.HasIndex("ModificationTime");
@ -1201,6 +1210,10 @@ namespace EShopSample.Migrations
b.Property<Guid?>("StoreId")
.HasColumnType("uniqueidentifier");
b.Property<Guid?>("TenantId")
.HasColumnType("uniqueidentifier")
.HasColumnName("TenantId");
b.HasKey("Id");
b.ToTable("EasyAbpEShopProductsProductDetails");
@ -1231,6 +1244,10 @@ namespace EShopSample.Migrations
b.Property<string>("SerializedEntityData")
.HasColumnType("nvarchar(max)");
b.Property<Guid?>("TenantId")
.HasColumnType("uniqueidentifier")
.HasColumnName("TenantId");
b.HasKey("Id");
b.HasIndex("ModificationTime");
@ -1298,6 +1315,10 @@ namespace EShopSample.Migrations
b.Property<long>("Sold")
.HasColumnType("bigint");
b.Property<Guid?>("TenantId")
.HasColumnType("uniqueidentifier")
.HasColumnName("TenantId");
b.HasKey("Id");
b.HasIndex("ProductSkuId");
@ -1381,6 +1402,10 @@ namespace EShopSample.Migrations
b.Property<Guid>("StoreId")
.HasColumnType("uniqueidentifier");
b.Property<Guid?>("TenantId")
.HasColumnType("uniqueidentifier")
.HasColumnName("TenantId");
b.Property<string>("UniqueName")
.HasColumnType("nvarchar(450)");
@ -1652,6 +1677,10 @@ namespace EShopSample.Migrations
b.Property<Guid>("StoreId")
.HasColumnType("uniqueidentifier");
b.Property<Guid?>("TenantId")
.HasColumnType("uniqueidentifier")
.HasColumnName("TenantId");
b.Property<string>("UniqueName")
.HasColumnType("nvarchar(450)");

Loading…
Cancel
Save