Exemple #1
0
        public async Task <CreateSessionResponse> Handle(CreateSessionCommand message)
        {
            var cinema = await _cinemaRepository.GetCinemaById(message.CinemaId);

            if (cinema == null)
            {
                throw new InvalidOperationException($"The cinema with id [{message.CinemaId}] can not be found");
            }

            var film = await _filmRepository.GetFilmById(message.FilmId);

            if (film == null)
            {
                throw new InvalidOperationException($"The film with id [{message.FilmId}] can not be found");
            }

            var screen = cinema.Screens.SingleOrDefault(s => s.Id == message.ScreenId);

            if (screen == null)
            {
                throw new InvalidOperationException($"The screen with id [{message.ScreenId}] can not be found in the cinema [{message.CinemaId}]");
            }

            var session = Session.Create(
                screen,
                film,
                message.Start);

            await _sessionRepository.AddAsync(session);

            await _unitOfWork.CommitAsync();

            return(new CreateSessionResponse(SessionViewModel.FromSession(session)));
        }
 public ServiceResponse <CinemaDto> GetCinemaById(int cinemaId)
 {
     _logger.LogInformation($"Вход в метод CinemaService.GetCinemaById c параметром {cinemaId}");
     return(Execute(() =>
     {
         var cinemaDto = new CinemaDto(_cinemaRepository.GetCinemaById(cinemaId));
         return ServiceResponse <CinemaDto> .Ok(cinemaDto);
     }));
 }
        public async Task <CreateScreenResponse> Handle(CreateScreenCommand message)
        {
            var cinema = await _cinemaRepository.GetCinemaById(message.CinemaId);

            var screen = cinema.CreateScreen(
                message.ScreenName,
                message.ScreenRows,
                message.ScreenSeatsPerRow);

            await _cinemaRepository.UnitOfWork.CommitAsync();

            return(new CreateScreenResponse(ScreenViewModel.FromScreen(screen)));
        }
Exemple #4
0
        public async Task <CreateScreenResponse> Handle(CreateScreenCommand message)
        {
            var cinema = await _cinemaRepository.GetCinemaById(message.CinemaId);

            if (cinema == null)
            {
                throw new InvalidOperationException($"The cinema with id [{message.CinemaId}] can not be found");
            }

            var screen = cinema.CreateScreen(
                message.ScreenName,
                message.ScreenRows,
                message.ScreenSeatsPerRow);

            await _unitOfWork.CommitAsync();

            return(new CreateScreenResponse(ScreenViewModel.FromScreen(screen)));
        }
        public async Task <CinemaModel> GetCinemaById(int id)
        {
            CinemaDalModel cinema = await _cinemaRepository.GetCinemaById(id);

            return((cinema == null) ? null : Mapper.Map <CinemaModel>(cinema));
        }