Exemple #1
0
        public async Task HandleAsync(GenerateSchedule command)
        {
            var alreadyExists = await _repository.ExistsAsync(command.CinemaId, command.MovieId);

            if (alreadyExists)
            {
                throw new ScheduleAlreadyExistsException(command.CinemaId, command.MovieId);
            }

            var movie = await _client.GetAsync(command.MovieId);

            if (movie is null)
            {
                throw new MovieNotFoundException(command.MovieId);
            }

            var schedule = await _policy.GenerateScheduleAsync(command.Id, command.CinemaId, command.MovieId,
                                                               command.From, command.To, movie.AgeRestriction);

            await _repository.AddAsync(schedule);

            await _processor.ProcessAsync(schedule.DomainEvents);
        }