public async Task <NewReservedTicketSummary> NewAsync(IReservationIdentifier reservationIdentifier) { var reservation = await reservationRepo.GetByIdAsync(reservationIdentifier.ReservationId); ITicket newReservedTicket = await ticketRepo.InsertAsync( new Ticket( reservation.ProjectionId, reservation.Row, reservation.Column)); await reservationRepo.RemoveReservationAsync(reservationIdentifier.ReservationId); //preparing data for ticketOutputReceipt var currProjection = await projectionRepo.GetProjectionByIdAsync(newReservedTicket.ProjectionId); var currMovie = await movieRepo.GetByIdAsync(currProjection.MovieId); var currRoom = await roomRepo.GetByIdAsync(currProjection.RoomId); var currCinema = await cinemaRepo.GetByIdAsync(currRoom.CinemaId); TicketOutputReceipt ticketOutputReceipt = new TicketOutputReceipt( newReservedTicket.Id, currProjection.StartDate, currMovie.Name, currCinema.Name, currRoom.Number, newReservedTicket.Row, newReservedTicket.Column); return(new NewReservedTicketSummary(true, ticketOutputReceipt)); }
public async Task <NewReservedTicketSummary> NewAsync(IReservationIdentifier reservationIdentifier) { var reservation = await reservationRepo.GetByIdAsync(reservationIdentifier.ReservationId); if (reservation == null) { var constraintMessage = "The reservation does not exist."; return(new NewReservedTicketSummary(false, constraintMessage)); } else { return(await newReservedTicket.NewAsync(reservationIdentifier)); } }
public async Task <NewReservedTicketSummary> NewAsync(IReservationIdentifier reservationIdentifier) { var reservation = await reservationRepo.GetByIdAsync(reservationIdentifier.ReservationId); var currProjection = await projectionRepo.GetProjectionByIdAsync(reservation.ProjectionId); var endingTimeToTakeReservedTicket = currProjection.StartDate - TimeSpan.FromSeconds(10); if (endingTimeToTakeReservedTicket <= DateTime.Now) { var constraintMessage = "It is too late to buy tickets with reservation for this projection! You can try to buy ticket without reservation."; return(new NewReservedTicketSummary(false, constraintMessage)); } else { return(await newReservedTicket.NewAsync(reservationIdentifier)); } }