public async Task ConsumeAsync(CreateShipmentEvent context, CancellationToken cancellationToken) { if (context.ShipmentType == (int)ShipmentType.MNG || context.ShipmentType == (int)ShipmentType.Yurtici) { await _bus.PubSub.PublishAsync(new OrderCompletedEvent { OrderId = context.OrderId }); } else { await _bus.PubSub.PublishAsync(new OrderFailedEvent { OrderId = context.OrderId }); } var shipment = new Infrastructure.Entities.Shipment { OrderId = context.OrderId, ShipmentType = context.ShipmentType }; await _dbContext.AddAsync(shipment); await _dbContext.SaveChangesAsync(); }
public async Task <CreateShipmentResponseModel> Handle(CreateShipmentCommand request, CancellationToken cancellationToken) { var shipment = _mapping.Map <CreateShipmentRequestModel, Infrastructure.Entities.Shipment>(request.CreateShipmentRequest); var response = await _dbContext.AddAsync(shipment); await _dbContext.SaveChangesAsync(); return(_mapping.Map <Infrastructure.Entities.Shipment, CreateShipmentResponseModel>(response.Entity)); }
public async Task Consume(ConsumeContext <ICreateShipmentEventModel> context) { //Failed işlemi için örnek bir senaryo if (context.Message.ShipmentType == (int)ShipmentType.MNG || context.Message.ShipmentType == (int)ShipmentType.Yurtici) { await context.Publish <IOrderCompletedEventModel>(new { context.Message.OrderId }); } else { await context.Publish <IOrderFailedEventModel>(new { context.Message.OrderId }); //TODO: Add StockDecrease event publish } var shipment = new Infrastructure.Entities.Shipment { OrderId = context.Message.OrderId, ShipmentType = context.Message.ShipmentType }; await _dbContext.AddAsync(shipment); if (await _dbContext.SaveChangesAsync() <= 0) { await context.Publish <IOrderFailedEventModel>(new { context.Message.OrderId }); //TODO: Add StockDecrease event publish } }