Browse Source

Aded OrderPlacedEto and

pull/53/head
Galip Tolga Erdem 5 years ago
parent
commit
43b415b1a7
  1. 13
      services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Buyers/BuyerEto.cs
  2. 7
      services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderItemEto.cs
  3. 16
      services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderPlacedEto.cs
  4. 52
      services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs

13
services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Buyers/BuyerEto.cs

@ -0,0 +1,13 @@
using System;
using Volo.Abp.Domain.Entities.Events.Distributed;
namespace EShopOnAbp.OrderingService.Buyers;
public class BuyerEto : EtoBase
{
public Guid BuyerId { get; set; }
public string BuyerEmail { get; set; }
public string PaymentType { get; set; }
public int PaymentTypeId { get; set; }
}

7
services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderItemEto.cs

@ -1,15 +1,16 @@
using System;
using Volo.Abp.Domain.Entities.Events.Distributed;
namespace EShopOnAbp.OrderingService.Orders
{
public class OrderItemEto
public class OrderItemEto : EtoBase
{
public Guid ProductId { get; set; }
public string ProductCode { get; set; }
public string ProductName { get; set; }
public string PictureUrl { get; set; }
public decimal UnitPrice { get; set; }
public decimal Discount { get; set; }
public int Units { get; set; }
}
}
}

16
services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Orders/OrderPlacedEto.cs

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using EShopOnAbp.OrderingService.Buyers;
using Volo.Abp.Domain.Entities.Events.Distributed;
using Volo.Abp.EventBus;
namespace EShopOnAbp.OrderingService.Orders;
[EventName("EShopOnAbp.Order.Placed")]
public class OrderPlacedEto : EtoBase
{
public Guid OrderId { get; set; }
public BuyerEto Buyer { get; set; }
public DateTime OrderDate { get; set; }
public List<OrderItemEto> Items { get; set; } = new();
}

52
services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using EShopOnAbp.OrderingService.Buyers;
using Volo.Abp.Domain.Services;
using Volo.Abp.EventBus.Distributed;
namespace EShopOnAbp.OrderingService.Orders;
@ -10,11 +11,16 @@ public class OrderManager : DomainService
{
private readonly IOrderRepository _orderRepository;
private readonly IBuyerRepository _buyerRepository;
private readonly IDistributedEventBus _distributedEventBus;
public OrderManager(IOrderRepository orderRepository, IBuyerRepository buyerRepository)
public OrderManager(
IOrderRepository orderRepository,
IBuyerRepository buyerRepository,
IDistributedEventBus distributedEventBus)
{
_orderRepository = orderRepository;
_buyerRepository = buyerRepository;
_distributedEventBus = distributedEventBus;
}
public async Task<Order> CreateOrderAsync(
@ -62,6 +68,48 @@ public class OrderManager : DomainService
);
}
return await _orderRepository.InsertAsync(order);
var placedOrder = await _orderRepository.InsertAsync(order, true);
// Publish Order placed event
await _distributedEventBus.PublishAsync(new OrderPlacedEto
{
OrderId = placedOrder.Id,
OrderDate = placedOrder.OrderDate,
Buyer = GetBuyerEto(buyer),
Items = GetProductItemEtoList(order.OrderItems)
});
return placedOrder;
}
private BuyerEto GetBuyerEto(Buyer buyer)
{
return new BuyerEto()
{
BuyerEmail = buyer.Email,
BuyerId = buyer.Id,
PaymentType = buyer.PaymentType.Name,
PaymentTypeId = buyer.PaymentType.Id
};
}
private List<OrderItemEto> GetProductItemEtoList(List<OrderItem> orderItems)
{
List<OrderItemEto> etoList = new List<OrderItemEto>();
foreach (var oItem in orderItems)
{
etoList.Add(new OrderItemEto()
{
Discount = oItem.Discount,
PictureUrl = oItem.PictureUrl,
ProductCode = oItem.ProductCode,
ProductId = oItem.ProductId,
ProductName = oItem.ProductName,
UnitPrice = oItem.UnitPrice,
Units = oItem.Units
});
}
return etoList;
}
}
Loading…
Cancel
Save