public async Task Handle(CheckoutReservation message, IMessageHandlerContext context) { Console.WriteLine($"Going to check-out reservation '{message.ReservationId}'.", Color.Green); using (var db = ReservationsContext.Create()) { var reservation = await db.Reservations .Where(r => r.Id == message.ReservationId) .Include(r => r.ReservedTickets) .SingleOrDefaultAsync(); /* * In case reservations expires the demo ignores that. * A description of reservations expiration can be found * in the ReservationsPolicy class. * A reservation could be checked out after the Reservation * expiration timeout is expired. In such scenario there won't * be any reservation to checkout and the incoming message is * simply "lost", or leads to a failure. */ await context.Publish(new ReservationCheckedout() { ReservationId = message.ReservationId, Tickets = reservation.ReservedTickets .Select(rt => rt.TicketId) .ToArray() }); db.Reservations.Remove(reservation); await db.SaveChangesAsync(); Console.WriteLine($"ReservationCheckedout event published and reservation removed from db.", Color.Green); } }
public async Task Handle(MarkTicketAsReserved message, IMessageHandlerContext context) { Console.WriteLine($"Going to mark ticket '{message.TicketId}' as reserved.", Color.Green); using (var db = ReservationsContext.Create()) { var reservation = await db.Reservations .Where(r => r.Id == message.ReservationId) .Include(r => r.ReservedTickets) .SingleOrDefaultAsync(); if (reservation == null) { reservation = new Reservation() { Id = message.ReservationId }; db.Reservations.Add(reservation); } reservation.ReservedTickets.Add(new ReservedTicket() { ReservationId = message.ReservationId, TicketId = message.TicketId }); await db.SaveChangesAsync(); Console.WriteLine($"Ticket '{message.TicketId}' reserved to reservation '{message.ReservationId}'.", Color.Green); } }
public TrainRepository( ReservationsContext dbContext, IGetVoyageUseCase voyageUseCase) { _dbContext = dbContext; _voyageUseCase = voyageUseCase; }
public async Task Handle(IReservationCheckedout message, IMessageHandlerContext context) { /* * Creation of an order is not a Reservations responsibility. * It's probably much more a Sales responsibility, in which case * having this handler here is a clear boundaries violation. * The only reason to keep it here is that an Order does nothing * in this demo. Its creation completes the payment process and * nothing else. It made little sense to increase even more the * complexity of the demo, creating a Sales endpoint just for the * purpose of hosting this message handler. If Sales had more * responsibilities in the demo it would have deserved its own * endpoint. */ Console.WriteLine($"Ready to create order for reservation '{message.ReservationId}'.", Color.Green); using (var db = ReservationsContext.Create()) { var order = new Order { Id = Guid.NewGuid(), ReservationId = message.ReservationId }; order.OrderedTickets = message.Tickets .GroupBy(t => t) .Select(g => new OrderedTicket() { OrderId = order.Id, TicketId = g.Key, Quantity = g.Count(), }).ToList(); /* * Demo utilizes LearningTransport and SQL, with no * Outbox configured to simplify the F5 experience. * This, however, means that the Publish operation * and the below database transaction are not atomic. * * There isn't really a chance for the LearningTransport * to fail, but in production Outbox should be used when * using transports with no support for transactions. */ await context.Publish(new Messages.OrderCreated() { OrderId = order.Id, ReservationId = message.ReservationId }); db.Orders.Add(order); await db.SaveChangesAsync(); Console.WriteLine($"Order '{order.Id}' created, IOrderCreated event published.", Color.Green); } }
public ReservationsController(ReservationsContext reservationsContext, ICommunicationService communicationService) { _reservationsContext = reservationsContext; _communicationService = communicationService; }
public CarsController(ReservationsContext context) { _context = context; }
public ContactsService(ReservationsContext context) { _context = context; }
public ReservationRepository(ReservationsContext context, IMapper mapper) { _context = context; _mapper = mapper; }
public CreateReservationCommandHandler(ReservationsContext dbContext, ILogger <CreateReservationCommandHandler> logger) { _logger = logger; _dbContext = dbContext; }
public GuestsService(ReservationsContext reservationsContext) { _reservationsContext = reservationsContext; }
public ReservationsRepository(ReservationsContext dbContext) { _dbContext = dbContext; }
private static ReservationsContext GetContext() => ReservationsContext.CreateDbInRuntimeMemory(DBName);
public CustomerQueries(ReservationsContext context) { _context = context; }
public ReservationQueries(ReservationsContext context) { _context = context; }