public IHttpActionResult BuyTicket(int id, int row, int col) { var projection = (Projection)projectionResosiory.GetProjectionById(id); if (projection == null) { return(BadRequest("Projection with given id doesn't exist")); } if (projection.StartDate < DateTime.Now) { return(BadRequest("Cannot buy ticket for finished or started projection")); } reservationRepository.CancelReservations(id); if (projection.Reservations.Any(x => x.Row == row && x.Column == col && x.IsCancelled == false)) { return(BadRequest("Sorry! These seats are already reserved.")); } if (projection.Tickets.Any(x => x.Row == row && x.Col == col)) { return(BadRequest("Sorry! These seats are already bought.")); } Ticket ticket = new Ticket(projection.StartDate, projection.Movie.Name, projection.Room.Cinema.Name, projection.Room.Number, row, col, projection.Id); var returnTicket = this.ticketRepository.Insert(ticket); return(Ok(returnTicket)); }