public IHttpActionResult GetAllReservationsByUserId()
 {
     return(Ok(new JsonApiOutput <IEnumerable <ReservationOutputModel> >(
                   ReservationsAdapter.QueryReservationsByUserId(User.Identity.GetUserId()).
                   Select <Reservation, ReservationOutputModel>(g => new ReservationOutputModel(g))
                   )));
 }
        public IHttpActionResult CancelReservation(int reservationId)
        {
            Reservation reservation = ReservationsAdapter.QueryReservation(reservationId);

            if (reservation == null)
            {
                return(BadRequest("This reservation does not exist!"));
            }

            ReservationsAdapter.CancelReservation(reservation);
            return(Ok());
        }
        public IHttpActionResult AddNewReservation(int projectionId)
        {
            IEnumerable <Reservation> reservations = ReservationsAdapter.
                                                     QueryReservationsByUserId(User.Identity.GetUserId()).
                                                     Where(r => r.ProjectionId == projectionId);

            if (reservations.Count() != 0)
            {
                return(BadRequest("Projection already reserved"));
            }

            Reservation reservation = ReservationsAdapter.AddNewReservation(User.Identity.GetUserId(), projectionId);

            return(Ok(new JsonApiOutput <ReservationOutputModel>(
                          new ReservationOutputModel(reservation)
                          )));
        }
        public IHttpActionResult CompleteReservation(int reservationId, int quantity)
        {
            Reservation reservation = ReservationsAdapter.QueryReservation(reservationId);

            if (reservation == null)
            {
                return(BadRequest("This reservation does not exist!"));
            }

            int freeSeats = reservation.Projection.FreeSeats;

            if (quantity > freeSeats)
            {
                return(BadRequest("Number of seats exceeded!"));
            }

            ReservationsAdapter.CompleteReservation(reservation, quantity);
            return(Ok());
        }
 public IHttpActionResult GetFreeSeats(int projectionId)
 {
     return(Ok(new JsonApiOutput <FreeSeatsOutputModel>(
                   new FreeSeatsOutputModel(ReservationsAdapter.QueryProjection(projectionId))
                   )));
 }