public Task Consume(ConsumeContext <CreateConcertCommand> context) { CreateConcertCommand command = context.Message; Logger.LogInformation($"Processing command Create concert: Maximum number of tickets:{command.MaximumNumberOfTickets}, Place: {command.Place}, Title: {command.Title} - started. "); try { Concert concert = ConcertFactory.Create(command.Place, command.MaximumNumberOfTickets, command.Date, command.Title, ConcertRepository.GetNextId()); ConcertRepository.Add(concert); foreach (var @event in concert.Changes) { var publisher = EventHandlerFactory.CreatePublisher(@event); publisher.Publish(@event, context); } Logger.LogInformation($"Processing command Create concert: Maximum number of tickets:{command.MaximumNumberOfTickets}, Place: {command.Place}, Title: {command.Title} - finished successfully. "); } catch (IntialTicketsCapacityNotSet ticketsCapacityNotSetException) { Logger.LogError($"{ticketsCapacityNotSetException.Message}. Can not execute command Create concert: Maximum number of tickets:{command.MaximumNumberOfTickets}, Place: {command.Place}, Title: {command.Title}.Command rejected. "); } return(Task.CompletedTask); }
public Concert OfId(string id) { var concertEntity = _db.Concerts.FirstOrDefault(x => x.Id == Guid.Parse(id)); var rehydratedConcert = new ConcertFactory().CreateFrom(concertEntity.RehydrateConcertSnapshot()); return(rehydratedConcert); }
public override CommandExecutionResult Execute() { try { Concert concert = new ConcertFactory().Create( GeoTitle, EngTitle, Description, ConcertDate ); _concertRepository.Store(concert); return(new CommandExecutionResult(CommandExecutionStatus.Success, concert.Id)); } catch (Exception ex) { //log exception return(new CommandExecutionResult(ex.Message)); } }