コード例 #1
0
        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);
        }
コード例 #2
0
        public async Task <CinemaModel> AddOrUpdateCinema(CinemaModel cinema)
        {
            CinemaDalModel cinemaRequest = Mapper.Map <CinemaDalModel>(cinema);

            int cinemaResponseId = await _cinemaRepository.AddOrUpdateCinema(cinemaRequest);

            return(new CinemaModel
                   (
                       (cinemaResponseId != 0) ? cinemaResponseId : cinema.Id,
                       cinema.Name,
                       cinema.City,
                       cinema.HallsNumber
                   ));
        }
コード例 #3
0
        public async Task <CinemaModel> GetCinemaById(int id)
        {
            CinemaDalModel cinema = await _cinemaRepository.GetCinemaById(id);

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