public async Task <SpectacleSessionReservation> AddReservationAsync(SpectacleSessionReservation reservation) { var session = await _unitOfWork.SessionRepository.DbSet.Include(q => q.Reservations).FirstOrDefaultAsync(q => q.Id == reservation.SpectacleSessionId); session.Reservations.Add(reservation); await _unitOfWork.SessionRepository.UpdateAsync(session); return(reservation); }
public async Task <IActionResult> Reserve(Guid sessionId) { var userId = User.Claims.First(c => c.Type == "UserId").Value; var session = await _spectacleService.GetSessionAsync(sessionId); if (session == null) { return(NotFound()); } var reservation = new SpectacleSessionReservation() { SpectacleSessionId = session.Id, ApplicationUserId = Guid.Parse(userId), ReservationDateTime = DateTime.Now }; reservation = await _spectacleService.AddReservationAsync(reservation); var reservationDto = _mapper.Map <SpectacleSessionReservation, SpectacleSessionReservationDto>(reservation); return(Ok(reservationDto)); }