示例#1
0
 public static void AddRoom(Room room)
 {
     using (var context = new CinemaContext())
     {
         List <DAL.Seat> seats = new List <DAL.Seat>();
         for (int i = 0; i < room.Capacity; i++)
         {
             DAL.Seat seat = new DAL.Seat();
             seat.SeatNumber = i % 6 + 1;
             seat.RowNumber  = (i / 6) + 1;
             seats.Add(seat);
             context.Seats.Add(seat);
         }
         room.Seats = seats;
         context.CinemaRooms
         .Add(room);
         context.SaveChanges();
     }
 }
示例#2
0
        public static List <Seat> ListFreeSeatsForMovieEvent(int movieEventId)
        {
            using (CinemaContext ctx = new CinemaContext())
            {
                var allSeatsForMovieEvent = ctx.MovieEvents
                                            .Where(m => m.MovieEventId == movieEventId)
                                            .Select(m => m.Room.Seats).FirstOrDefault().OrderBy(o => o.RowNumber).ThenBy(o => o.SeatNumber);



                var reservedSeatIdsForMovieEvent = from r in ctx.Reservations
                                                   where r.MovieEventId == movieEventId
                                                   select r.SeatId;

                var reservedSeatsForMovieEvent = from s in ctx.Seats
                                                 where reservedSeatIdsForMovieEvent.Contains(s.SeatId)
                                                 select s;

                return((allSeatsForMovieEvent.Except(reservedSeatsForMovieEvent)).OrderBy(o => o.RowNumber).ThenBy(o => o.SeatNumber).ToList());
            }
        }
示例#3
0
 public static MovieEvent GetMovieEventById(int movieEventId)
 {
     using (CinemaContext ctx = new CinemaContext()) {
         return(ctx.MovieEvents.Include(me => me.Movie).Include(me => me.Room).SingleOrDefault(m => m.MovieEventId == movieEventId));
     }
 }