public int Create(Movie movie)
        {
            ValidateTitleExistence(movie.Title);

            _movieTheaterDbRepository.Add(movie);
            var changes = _movieTheaterDbRepository.Commit();

            return(changes);
        }
        public int Create(MovieRoom movieRoom)
        {
            ValidateNameExistence(movieRoom.Name);

            _movieTheaterDbRepository.Add(movieRoom);
            var changes = _movieTheaterDbRepository.Commit();

            return(changes);
        }
Ejemplo n.º 3
0
        public int Create(MovieSession movieSession)
        {
            _movieSessionValidator.ValidateAndThrow(movieSession);
            var movie = _movieTheaterDbRepository.Query <Movie>().FirstOrDefault(e => e.Id == movieSession.MovieId);

            movieSession.PresentationEnd = movieSession.PresentationStart.AddMinutes(movie.Duration);

            var roomReserved = _movieTheaterDbRepository.Query <MovieSession>()
                               .Any(ms => ms.RoomId == movieSession.RoomId &&
                                    ((ms.PresentationStart <= movieSession.PresentationStart && movieSession.PresentationStart <= ms.PresentationEnd) ||
                                     (ms.PresentationStart <= movieSession.PresentationEnd && movieSession.PresentationEnd <= ms.PresentationEnd)));

            if (roomReserved)
            {
                var message = "You can't create a new session in this room, cause it has already been reserved.";
                throw new ValidationException(message);
            }


            _movieTheaterDbRepository.Add(movieSession);
            var changes = _movieTheaterDbRepository.Commit();

            return(changes);
        }