Example #1
0
        public static Schedule Create(EntityId id, CinemaId cinemaId, MovieId movieId)
        {
            var schedule = new Schedule(id, cinemaId, movieId);

            schedule.AddDomainEvent(new ScheduleAdded(schedule));
            schedule.Version = 1;
            return(schedule);
        }
Example #2
0
 public Schedule(EntityId id, CinemaId cinemaId, MovieId movieId, IEnumerable <Show> shows = null, int?version = null)
     : base(id)
 {
     CinemaId = cinemaId ?? throw new EmptyScheduleCinemaException(id);
     MovieId  = movieId ?? throw new EmptyScheduleMovieException(id);
     _shows   = shows is null ? new HashSet <Show>() : shows.ToHashSet();
     Version  = version ?? 1;
 }
Example #3
0
        public static ScheduleSchema Create(EntityId id, CinemaId cinemaId, ScheduleSchemaTimes times)
        {
            var schema = new ScheduleSchema(id, cinemaId);

            schema.ChangeTimes(times);
            schema.ClearEvents();
            schema.AddDomainEvent(new ScheduleSchemaAdded(schema));
            schema.Version = 1;
            return(schema);
        }
Example #4
0
        public async Task <Reservation> CreateAsync(EntityId id, CinemaId cinemaId, MovieId movieId, HallId hallId, CustomerId customerId,
                                                    DateTime dateTime, bool isPaymentUponArrival, IEnumerable <Seat> seats, Reservee reservee)
        {
            var areSeatsValid = await _validator.ValidateAsync(cinemaId, movieId, hallId, seats);

            if (!areSeatsValid)
            {
                throw new SeatsAlreadyReservedException(id);
            }

            if (!customerId.IsEmpty())
            {
                reservee = await _provider.GetAsync(customerId);
            }

            var status      = isPaymentUponArrival ? ReservationStatus.PaymentUponArrival : ReservationStatus.Pending;
            var reservation = Reservation.Create(id, cinemaId, movieId, hallId, dateTime, status, reservee, seats);

            return(reservation);
        }
Example #5
0
        public async Task <Schedule> GenerateScheduleAsync(EntityId id, CinemaId cinemaId, MovieId movieId,
                                                           DateTime from, DateTime to, int ageRestriction)
        {
            var schema = await _scheduleSchemasRepository.GetAsync(cinemaId);

            if (schema is null)
            {
                throw new ScheduleSchemaNotFoundException(cinemaId);
            }

            var times = schema.Times
                        .Where(h => h.ageRestriction <= ageRestriction)
                        .Select(h => h.times)
                        .FirstOrDefault();

            if (times is null)
            {
                throw new MissingScheduleTimesException(cinemaId, ageRestriction);
            }

            var schedules = await _schedulesRepository.GetAsync();

            var schedule = Schedule.Create(id, cinemaId, movieId);

            var shows = schedules.SelectMany(s => s.Shows);

            var dates = Enumerable.Range(0, 1 + to.Subtract(from).Days)
                        .Select(offset => from.AddDays(offset))
                        .ToList();

            var halls = await _hallsRepository.GetAsync(cinemaId);

            var generatedShows = dates.SelectMany(d =>
                                                  GenerateShowsForDay(d, movieId, shows.ToList(), times.ToList(), halls.ToList()));

            schedule.AddShows(generatedShows);
            return(schedule);
        }
Example #6
0
 public Hall(EntityId id, CinemaId cinemaId)
 {
     Id       = id;
     CinemaId = cinemaId;
 }
 public CinemaAdded(CinemaId id, string name)
 {
     Id   = id;
     Name = name;
 }
Example #8
0
        public async Task <IEnumerable <Hall> > GetAsync(CinemaId cinemaId)
        {
            var documents = await _repository.FindAsync(h => h.CinemaId == cinemaId);

            return(documents?.Select(d => d.AsEntity()));
        }
 public ScheduleSchemaNotFoundException(CinemaId cinemaId)
     : base($"Schedule schema for cinema {cinemaId} was not found")
 {
 }
Example #10
0
 public MissingScheduleTimesException(CinemaId cinemaId, int ageRestriction)
     : base($"Schedule schema for cinema {cinemaId} does not define hours for age {ageRestriction}")
 {
 }
Example #11
0
 public ScheduleAlreadyExistsException(CinemaId cinemaId, MovieId movieId)
     : base($"Schedule for cinema {cinemaId} and movie {movieId} already exists")
 {
 }
Example #12
0
 public ScheduleSchema(EntityId id, CinemaId cinemaId, ScheduleSchemaTimes times, int?version = null)
     : this(id, cinemaId)
 {
     Times   = times;
     Version = version ?? 1;
 }
Example #13
0
 private ScheduleSchema(EntityId id, CinemaId cinemaId) : base(id)
     => CinemaId = cinemaId ?? throw new EmptyScheduleSchemaCinemaException(id);
 public CinemaAdded(CinemaId id, string name)
 {
     Id = id;
     Name = name;
 }
Example #15
0
 public ScheduleSchemaAlreadyExistsException(CinemaId cinemaId)
     : base($"Schedule schema for cinema with id {cinemaId} already exists")
 {
 }