Ejemplo n.º 1
0
        public async Task <IActionResult> SellTickets([FromBody] ReservationDto newReserve)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var seats = _context.Seats.Where(o => newReserve.SelectedSeats.Contains(o.Id));
                    foreach (var seat in seats)
                    {
                        seat.State        = State.Sold;
                        seat.NameReserved = newReserve.Name;
                        seat.PhoneNum     = newReserve.PhoneNum;
                    }

                    _context.UpdateRange(seats);
                    await _context.SaveChangesAsync();
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception e)
            {
                BadRequest();
            }
            return(Ok());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Reserve(ReservationViewModel reservationViewModel)
        {
            if (ModelState.IsValid)
            {
                var ids           = reservationViewModel.SeatIds.Split(",");
                var selectedSeats = from m in _context.Seats where ids.Contains(m.Id.ToString()) select m;
                foreach (var current in selectedSeats)
                {
                    if (current.State != State.Free)
                    {
                        return(NotFound());
                    }

                    current.State        = State.Reserved;
                    current.NameReserved = reservationViewModel.Name;
                    current.PhoneNum     = reservationViewModel.PhoneNumber;
                }
                _context.UpdateRange(selectedSeats);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(HomeController.Index)));
            }
            var selectedShow = await _context.Shows
                               .FirstOrDefaultAsync(m => m.Id == reservationViewModel.ShowId);

            if (selectedShow == null)
            {
                return(NotFound());
            }

            var thisShowRoom = await _context.Rooms
                               .FirstOrDefaultAsync(m => m.Id == selectedShow.RoomRefId);

            if (thisShowRoom == null)
            {
                return(NotFound());
            }

            var thisShowSeats = from m in _context.Seats where m.ShowRefId == reservationViewModel.ShowId
                                select m;

            reservationViewModel.Room  = thisShowRoom;
            reservationViewModel.Seats = await thisShowSeats.ToListAsync();

            reservationViewModel.SeatIds = "";
            return(View(reservationViewModel));
        }