Пример #1
0
        public async Task <FullHallBlModel> GetHall(int id)
        {
            HallDalDtoModel hallDalDto = await _hallsRepository.GetHall(id);

            if (hallDalDto == null)
            {
                return(null);
            }

            Task <IEnumerable <PlaceDalDtoModel> >      t1 = _cinemaRepository.GetPlaces(hallDalDto.Id);
            Task <IEnumerable <HallSchemeDalDtoModel> > t2 = _cinemaRepository.GetHallScheme(hallDalDto.Id);

            IEnumerable <PlaceDalDtoModel> places = await t1;

            PlaceBlModel[] placesBlArray = places.Select
                                           (
                x => new PlaceBlModel
                (
                    x.Id,
                    x.HallId,
                    new PlaceTypeBlModel(x.TypeId, x.Type),
                    x.RowNumber,
                    x.PlaceNumber,
                    x.Price,
                    x.PriceId,
                    x.PlaceStatus
                )
                                           ).ToArray();

            IEnumerable <HallSchemeDalDtoModel> hallSchemeResponse = await t2;

            HallSchemeBlModel[] hallSchemeBlModels =
                hallSchemeResponse.Select(Mapper.Map <HallSchemeBlModel>).ToArray();

            return(new FullHallBlModel(
                       hallDalDto.Id,
                       hallDalDto.CinemaId,
                       hallDalDto.HallName,
                       hallDalDto.CinemaName,
                       placesBlArray,
                       hallSchemeBlModels
                       ));
        }
        public async Task <IEnumerable <FullHallBlModel> > GetHalls(int cinemaId)
        {
            CinemaDalModel cinema = await _cinemaRepository.GetCinemaById(cinemaId);

            if (cinema == null)
            {
                return(null);
            }

            IEnumerable <HallDalDtoModel> halls = await _cinemaRepository.GetHalls(cinemaId);

            List <FullHallBlModel> results = new List <FullHallBlModel>();

            if (halls != null)
            {
                foreach (HallDalDtoModel hall in halls)
                {
                    Task <IEnumerable <PlaceDalDtoModel> >      t1 = _cinemaRepository.GetPlaces(hall.Id);
                    Task <IEnumerable <HallSchemeDalDtoModel> > t2 = _cinemaRepository.GetHallScheme(hall.Id);

                    IEnumerable <PlaceDalDtoModel> places = await t1;
                    PlaceBlModel[] placesBlArray          = places.Select(
                        x => new PlaceBlModel
                        (
                            x.Id,
                            x.HallId,
                            new PlaceTypeBlModel(x.TypeId, x.Type),
                            x.RowNumber,
                            x.PlaceNumber,
                            x.Price,
                            x.PriceId,
                            x.PlaceStatus
                        )
                        ).ToArray();

                    IEnumerable <HallSchemeDalDtoModel> hallSchemeResponse = await t2;

                    HallSchemeBlModel[] hallSchemeBlModels =
                        hallSchemeResponse.Select(Mapper.Map <HallSchemeBlModel>).ToArray();

                    results.Add(new FullHallBlModel(
                                    hall.Id,
                                    hall.CinemaId,
                                    hall.HallName,
                                    hall.CinemaName,
                                    placesBlArray,
                                    hallSchemeBlModels
                                    ));
                }
            }

            return(results);
        }