Beispiel #1
0
        public IActionResult Create([FromForm] Reservation reservation)
        {
            reservation = _reservationService.IncludeRoom(reservation);
            if (!ModelState.IsValid)
            {
                if (reservation.Room == null)
                {
                    _messageService.AddMessage(new Message("The room was not found."));
                    return(RedirectToAction("Index", "Room"));
                }

                return(View(reservation));
            }

            if (!_reservationService.HasValidRange(reservation))
            {
                _messageService.AddMessage(new Message("Invalid time range."));
                return(RedirectToAction("Index", "Room")); //user is trying to break the app, does not really matter where I redirect him...
            }

            try
            {
                _reservationService.Add(reservation);
                _messageService.AddMessage(new Message("A reservation has been made!", MessageType.Success));
                return(RedirectToAction("Index", "Room"));
            }
            catch
            {
                _messageService.AddMessage(new Message("A reservation with that time range has already been taken."));
                return(RedirectToAction("Prepare", "Reservation", new { id = reservation.RoomId }));
            }
        }
Beispiel #2
0
        public async Task <ActionResult> Post([FromBody] AddReservationDto reservation)
        {
            var takenSeats = await _showingsService.GetTakenSeats(reservation.ShowingId);

            if (reservation.Seat <= 0)
            {
                return(BadRequest(new ErrorMessage($"Seat number must be greater than 0")));
            }
            if (takenSeats.Select(s => s.Number).Contains(reservation.Seat))
            {
                return(BadRequest(new ErrorMessage($"Seat {reservation.Seat} is already taken!")));
            }
            await _reservationsService.Add(reservation);

            var seats = await _showingsService.GetTakenSeats(reservation.ShowingId);

            await _hubContext.Clients.All.SendAsync("OnSeatsChanged", seats);

            return(Ok());
        }
Beispiel #3
0
 // POST: api/Reservations
 // Reservation item must be specified in request body
 public ValidationResult Post([FromBody] NewReservationItem item)
 {
     return(_service.Add(item));
 }
Beispiel #4
0
 public ValidationResult Post([FromBody] ReservationDetail item)
 {
     return(_service.Add(item));
 }