Example #1
0
        public static Reservation GetByUserIdAndSeanceId(int userId, int seanceId)
        {
            using var db = new DbCinema();
            var queryable = from reservation in db.Reservations
                            join user in db.Users on reservation.UserId equals user.Id
                            join seance in db.Seances on reservation.SeanceId equals seance.Id
                            where reservation.UserId == userId && reservation.SeanceId == seanceId
                            select Reservation.Build(reservation, user, seance);

            var singleReservation = queryable.ToList()[0];

            singleReservation.Seance = SeanceController.Get(singleReservation.SeanceId);
            singleReservation.User   = UserController.Get(singleReservation.UserId);
            return(singleReservation);
        }
Example #2
0
        public static List <Reservation> All()
        {
            using var db = new DbCinema();
            var query = from reservation in db.Reservations
                        join user in db.Users on reservation.UserId equals user.Id
                        join seance in db.Seances on reservation.SeanceId equals seance.Id
                        orderby reservation.Id descending
                        select Reservation.Build(reservation, user, seance);

            var reservations = query.ToList();

            foreach (var res in reservations)
            {
                res.Seance = SeanceController.Get(res.SeanceId);
                res.User   = UserController.Get(res.UserId);
            }
            return(reservations);
        }