Browse Source

OrderNo generation and logging update

pull/56/head
Galip Tolga Erdem 5 years ago
parent
commit
b0e08015c0
  1. 2
      services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs
  2. 17
      services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs

2
services/ordering/src/EShopOnAbp.OrderingService.Application/Orders/OrderAppService.cs

@ -42,8 +42,8 @@ public class OrderAppService : ApplicationService, IOrderAppService
public async Task<OrderDto> GetByOrderNoAsync(int orderNo)
{
Logger.LogInformation($"========== {orderNo} ============== ");
var order = await _orderRepository.GetByOrderNoAsync(orderNo);
Logger.LogInformation($" Order recieved with order no:{orderNo}");
return CreateOrderDtoMapping(order);
}

17
services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs

@ -23,12 +23,13 @@ public class Order : AggregateRoot<Guid>
{
}
internal Order(Guid id, Buyer buyer, Address address, PaymentType paymentType, Guid? paymentRequestId = null) : base(id)
internal Order(Guid id, Buyer buyer, Address address, PaymentType paymentType,
Guid? paymentRequestId = null) : base(id)
{
_orderStatusId = OrderStatus.Placed.Id;
_paymentTypeId = paymentType.Id;
OrderDate = DateTime.UtcNow;
OrderNo = id.GetHashCode();
OrderNo = GenerateOrderNo(id);
Buyer = buyer;
Address = address;
PaymentRequestId = paymentRequestId;
@ -36,6 +37,18 @@ public class Order : AggregateRoot<Guid>
OrderItems = new List<OrderItem>();
}
private int GenerateOrderNo(Guid id)
{
// Simple order no generation. Should be improved for uniqueness.
var code = Id.GetHashCode();
if (code < 0) // Should be negative
{
code *= -1;
}
return code;
}
internal Order SetOrderAccepted(Guid paymentRequestId, string paymentRequestStatus)
{
PaymentRequestId = paymentRequestId;

Loading…
Cancel
Save