Exemple #1
0
        public async Task <ActionResult> OrderReservation([Bind("MovieRoomID,SeatID,UserID")]
                                                          [FromBody] Reservation reservation, [FromForm] IFormCollection formCollection)
        {
            if (reservation == null)
            {
                return(BadRequest("Unsufficient data provided"));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState)); //400
            }

            try
            {
                Seat theSeat = new Seat();
                var  seat    = await seatRepo.GetByExpressionAsync(s => s.SeatID == reservation.SeatID);

                theSeat = seat.First();

                var movieroom = await movieRoomRepo.GetMovieRoom(reservation.MovieRoomID);

                reservation.Price = movieroom.Movie.Price;

                if (theSeat.Special == true)
                {
                    reservation.Price = reservation.Price + 4.5;
                }


                if (movieRoomRepo.ReservationExist(reservation))
                {
                    return(NotFound());
                }

                await movieRoomRepo.PostReservation(reservation);
            }
            catch (Exception exc)
            {
                logger.LogError($"Threw exception when adding the reservation {reservation.MovieRoom.Movie.Name} room {reservation.MovieRoom.RoomID}: {exc}");
                throw new Exception($"Creating  the reservation {reservation.MovieRoom.Movie.Name} room {reservation.MovieRoom.RoomID} did not succeed.");
            }

            ReservationDTO reservationDTO = mapper.Map <ReservationDTO>(reservation);

            return(Created($"api/{reservation.UserID}", reservationDTO));
        }