示例#1
0
        public async Task <SeanceRoomData> GetSeanceRoomData(int id)
        {
            var seance = await _dbContext.Seances
                         .Include(x => x.Reservations).ThenInclude(x => x.ReservedSeats)
                         .Include(x => x.Room).ThenInclude(x => x.Seats)
                         .FirstOrDefaultAsync(x => x.Id == id);

            var seanceRoomData = new SeanceRoomData();

            seanceRoomData.RoomId      = seance.RoomId;
            seanceRoomData.SeanceId    = seance.Id;
            seanceRoomData.SeatsInRoom = _mapper.Map <ICollection <Seat>, ICollection <SeatDto> >(seance.Room.Seats.ToList());
            foreach (var seat in seanceRoomData.SeatsInRoom)
            {
                if (seance.Reservations.Any(r => r.ReservedSeats.Any(rs => rs.SeatId == seat.Id)))
                {
                    seanceRoomData.ReservedSeats.Add(seat);
                }
            }
            return(seanceRoomData);
        }
示例#2
0
        public async Task <IActionResult> GetSeanceRoomData(int id)
        {
            SeanceRoomData seanceRoomData = await _seanceService.GetSeanceRoomData(id);

            return(Json(seanceRoomData));
        }