Esempio n. 1
0
        public async Task UpsertHallsAsync(CinemaHallsModel hallsModel)
        {
            foreach (HallModel hall in hallsModel.Halls)
            {
                int result;
                try
                {
                    result = await _hallRepository.UpsertHallAsync(
                        new HallEntity(
                            hall.Id,
                            hall.Name,
                            hallsModel.CinemaId
                            )
                        );
                }
                catch (UniqueIndexException e)
                {
                    throw new ConflictException(e);
                }

                List <SeatModel> hallSeats = hallsModel
                                             .Seats
                                             .FindAll(seat => seat.HallId == hall.Id);

                if (hall.Id == result)
                {
                    await _hallRepository.DeleteHallPlanAsync(result);
                }

                TypeAdapterConfig <SeatModel, SeatEntity>
                .NewConfig()
                .Map(dest => dest.HallId, sourse => result);

                await _hallRepository.AddHallPlanAsync(
                    hallSeats
                    .Adapt <List <SeatEntity> >()
                    );
            }
        }