public async Task <ActionResult> PlaceReservation(NewReservationRequest newReservationRequest)
        {
            var user = await _userManager.FindByNameAsync(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            var reservedMovies = new List <Movie>();

            newReservationRequest.ReservedMovieIds.ForEach(rid =>
            {
                var movieWithId = _context.Movies.Find(rid);
                if (movieWithId != null)
                {
                    reservedMovies.Add(movieWithId);
                }
            });

            if (reservedMovies.Count == 0)
            {
                return(BadRequest());
            }

            var reservation = new Reservation
            {
                ApplicationUser     = user,
                ReservationDateTime = newReservationRequest.ReservationDateTime.GetValueOrDefault(),
                Movies = reservedMovies
            };

            _context.Reservations.Add(reservation);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetMovieWithComments", new { id = reservation.Id }, "New reservation successfully added"));
        }
        public async Task <IActionResult> UpdateReservation(int id, NewReservationRequest updateReservationRequest)
        {
            var user = await _userManager.FindByNameAsync(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            var reservedMovies = new List <Movie>();

            updateReservationRequest.ReservedMovieIds.ForEach(rid =>
            {
                var movieWithId = _context.Movies.Find(rid);
                if (movieWithId != null)
                {
                    reservedMovies.Add(movieWithId);
                }
            });

            if (reservedMovies.Count == 0)
            {
                return(BadRequest());
            }

            //var reservation = _mapper.Map<Reservation>(reservedMovies);
            var reservation = new Reservation
            {
                Id = id,
                ApplicationUser     = user,
                ReservationDateTime = updateReservationRequest.ReservationDateTime.GetValueOrDefault(),
                Movies = reservedMovies
            };

            if (reservation == null)
            {
                return(BadRequest());
            }

            _context.Entry(reservation).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ReservationExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }