public IActionResult Put(int id, [FromBody] ShowtimeRequest showtimeRequest)
        {
            if (showtimeRepository.GetShowtimeById(id) == null)
            {
                return(NotFound());
            }

            if (showtimeRequest == null)
            {
                return(StatusCode(400, ModelState));
            }

            var statusCode = ValidateShowtime(showtimeRequest);

            if (!ModelState.IsValid)
            {
                return(StatusCode(statusCode.StatusCode));
            }

            var showtime = showtimeRepository.UpdateShowtime(id, showtimeRequest);

            if (showtime == null)
            {
                var error = new Error()
                {
                    message = "Showtime went oopsie when updating"
                };
                return(StatusCode(400, error));
            }
            return(Ok(new ShowtimeDTO(showtime)));
        }
Beispiel #2
0
        public IActionResult Get(int id)
        {
            var showtime = showtimeRepository.GetShowtimeById(id);

            if (showtime == null)
            {
                return(NotFound());
            }
            var showtimeDTO = new ShowtimeDTO(showtime);
            var tickets     = ticketRepository.GetAllTicketsByShowtimeId(id);

            List <string> seats = new List <string>();

            foreach (var ticket in tickets)
            {
                seats.Add(ticket.Seat);
            }
            return(Ok(new { showtime = showtimeDTO, seats = seats }));
        }