Browse Source

Change SaveEntitiesAsync to SaveChangesAsync

pull/223/head
Christian Arenas 7 years ago
parent
commit
3556a5d126
9 changed files with 26 additions and 18 deletions
  1. +0
    -5
      src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs
  2. +2
    -2
      src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentFailedIntegrationEventHandler.cs
  3. +2
    -2
      src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs
  4. +2
    -2
      src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs
  5. +1
    -1
      src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs
  6. +11
    -5
      src/Services/Ordering/Ordering.API/Startup.cs
  7. +2
    -0
      src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/IOrderRepository.cs
  8. +1
    -1
      src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs
  9. +5
    -0
      src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs

+ 0
- 5
src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs View File

@ -41,11 +41,6 @@
orderStockList); orderStockList);
await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(decrementOrderStockCommandMsg); await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(decrementOrderStockCommandMsg);
await _orderingIntegrationEventService.PublishThroughEventBusAsync(decrementOrderStockCommandMsg); await _orderingIntegrationEventService.PublishThroughEventBusAsync(decrementOrderStockCommandMsg);
//is it necessary get a DecrementOrderStockSuccessIntegrationEvent/DecrementOrderStockFailedIntegrationEvent before to call ShipOrderCommandMsg???
var shipOrderCommandMsg = new ShipOrderCommandMsg(orderStatusChangedToPaidDomainEvent.OrderId);
await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(shipOrderCommandMsg);
await _orderingIntegrationEventService.PublishThroughEventBusAsync(shipOrderCommandMsg);
} }
} }
} }

+ 2
- 2
src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentFailedIntegrationEventHandler.cs View File

@ -17,11 +17,11 @@
public async Task Handle(OrderPaymentFailedIntegrationEvent @event) public async Task Handle(OrderPaymentFailedIntegrationEvent @event)
{ {
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
var orderToUpdate = await _orderRepository.GetWithDependenciesAsync(@event.OrderId);
orderToUpdate.SetCancelledStatus(); orderToUpdate.SetCancelledStatus();
await _orderRepository.UnitOfWork.SaveEntitiesAsync();
await _orderRepository.UnitOfWork.SaveChangesAsync();
} }
} }
} }

+ 2
- 2
src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs View File

@ -17,11 +17,11 @@
public async Task Handle(OrderPaymentSuccededIntegrationEvent @event) public async Task Handle(OrderPaymentSuccededIntegrationEvent @event)
{ {
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
var orderToUpdate = await _orderRepository.GetWithDependenciesAsync(@event.OrderId);
orderToUpdate.SetPaidStatus(); orderToUpdate.SetPaidStatus();
await _orderRepository.UnitOfWork.SaveEntitiesAsync();
await _orderRepository.UnitOfWork.SaveChangesAsync();
} }
} }
} }

+ 2
- 2
src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs View File

@ -17,11 +17,11 @@
public async Task Handle(OrderStockConfirmedIntegrationEvent @event) public async Task Handle(OrderStockConfirmedIntegrationEvent @event)
{ {
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
var orderToUpdate = await _orderRepository.GetWithDependenciesAsync(@event.OrderId);
orderToUpdate.SetStockConfirmedStatus(); orderToUpdate.SetStockConfirmedStatus();
await _orderRepository.UnitOfWork.SaveEntitiesAsync();
await _orderRepository.UnitOfWork.SaveChangesAsync();
} }
} }
} }

+ 1
- 1
src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs View File

@ -19,7 +19,7 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
public async Task Handle(OrderStockNotConfirmedIntegrationEvent @event) public async Task Handle(OrderStockNotConfirmedIntegrationEvent @event)
{ {
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
var orderToUpdate = await _orderRepository.GetWithDependenciesAsync(@event.OrderId);
var orderStockNotConfirmedItems = @event.OrderStockItems var orderStockNotConfirmedItems = @event.OrderStockItems
.FindAll(c => !c.Confirmed) .FindAll(c => !c.Confirmed)


+ 11
- 5
src/Services/Ordering/Ordering.API/Startup.cs View File

@ -32,6 +32,7 @@
using System; using System;
using System.Data.Common; using System.Data.Common;
using System.Reflection; using System.Reflection;
using global::Ordering.API.Application.IntegrationEvents.EventHandling;
public class Startup public class Startup
{ {
@ -129,8 +130,14 @@
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>(); services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
services.AddTransient<IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>>(); services.AddTransient<IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>>();
services.AddTransient<IIntegrationEventHandler<ConfirmGracePeriodCommandMsg>, OrderProcessSaga>(); services.AddTransient<IIntegrationEventHandler<ConfirmGracePeriodCommandMsg>, OrderProcessSaga>();
services.AddTransient<IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>>();
services.AddTransient<IIntegrationEventHandler<OrderStockNotConfirmedIntegrationEvent>>();
services.AddTransient<IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>,
OrderStockConfirmedIntegrationEventHandler>();
services.AddTransient<IIntegrationEventHandler<OrderStockNotConfirmedIntegrationEvent>,
OrderStockNotConfirmedIntegrationEventHandler>();
services.AddTransient<IIntegrationEventHandler<OrderPaymentFailedIntegrationEvent>,
OrderPaymentFailedIntegrationEventHandler>();
services.AddTransient<IIntegrationEventHandler<OrderPaymentSuccededIntegrationEvent>,
OrderPaymentSuccededIntegrationEventHandler>();
services.AddOptions(); services.AddOptions();
//configure autofac //configure autofac
@ -176,12 +183,11 @@
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>(); var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
eventBus.Subscribe<UserCheckoutAcceptedIntegrationEvent, IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>>(); eventBus.Subscribe<UserCheckoutAcceptedIntegrationEvent, IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>>();
eventBus.Subscribe<ConfirmGracePeriodCommandMsg, IIntegrationEventHandler<ConfirmGracePeriodCommandMsg>>(); eventBus.Subscribe<ConfirmGracePeriodCommandMsg, IIntegrationEventHandler<ConfirmGracePeriodCommandMsg>>();
eventBus.Subscribe<OrderStockConfirmedIntegrationEvent, IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>>(); eventBus.Subscribe<OrderStockConfirmedIntegrationEvent, IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>>();
eventBus.Subscribe<OrderStockNotConfirmedIntegrationEvent, IIntegrationEventHandler<OrderStockNotConfirmedIntegrationEvent>>(); eventBus.Subscribe<OrderStockNotConfirmedIntegrationEvent, IIntegrationEventHandler<OrderStockNotConfirmedIntegrationEvent>>();
eventBus.Subscribe<OrderPaymentFailedIntegrationEvent, IIntegrationEventHandler<OrderPaymentFailedIntegrationEvent>>();
eventBus.Subscribe<OrderPaymentSuccededIntegrationEvent, IIntegrationEventHandler<OrderPaymentSuccededIntegrationEvent>>();
} }
protected virtual void ConfigureAuth(IApplicationBuilder app) protected virtual void ConfigureAuth(IApplicationBuilder app)


+ 2
- 0
src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/IOrderRepository.cs View File

@ -13,5 +13,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
void Update(Order order); void Update(Order order);
Task<Order> GetAsync(int orderId); Task<Order> GetAsync(int orderId);
Task<Order> GetWithDependenciesAsync(int orderId);
} }
} }

+ 1
- 1
src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs View File

@ -30,7 +30,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
// but only through the method OrderAggrergateRoot.AddOrderItem() which includes behaviour. // but only through the method OrderAggrergateRoot.AddOrderItem() which includes behaviour.
private readonly List<OrderItem> _orderItems; private readonly List<OrderItem> _orderItems;
public IReadOnlyList<OrderItem> OrderItems => _orderItems;
public IReadOnlyCollection<OrderItem> OrderItems => _orderItems;
// Using List<>.AsReadOnly() // Using List<>.AsReadOnly()
// This will create a read only wrapper around the private list so is protected against "external updates". // This will create a read only wrapper around the private list so is protected against "external updates".
// It's much cheaper than .ToList() because it will not have to copy all items in a new collection. (Just one heap alloc for the wrapper instance) // It's much cheaper than .ToList() because it will not have to copy all items in a new collection. (Just one heap alloc for the wrapper instance)


+ 5
- 0
src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs View File

@ -32,6 +32,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositor
} }
public async Task<Order> GetAsync(int orderId) public async Task<Order> GetAsync(int orderId)
{
return await _context.Orders.FindAsync(orderId);
}
public async Task<Order> GetWithDependenciesAsync(int orderId)
{ {
return await _context.Orders return await _context.Orders
.Include(c => c.OrderStatus) .Include(c => c.OrderStatus)


Loading…
Cancel
Save